From 9d4abecc7effba585f87f928a795aa328ea16e68 Mon Sep 17 00:00:00 2001 From: Santiago Herrera Date: Mon, 21 Aug 2017 10:57:09 -0500 Subject: [PATCH 1/2] Select line number --- open_include.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/open_include.py b/open_include.py index f62f08b..0aff4bc 100644 --- a/open_include.py +++ b/open_include.py @@ -419,6 +419,13 @@ def try_open(self, window, maybe_path): debug_info('Trying to open: ' + maybe_path) + row_regex = re.compile(r':(\d+)$') + row_search_result = row_regex.search(maybe_path) + row = None + if row_search_result is not None: + maybe_path = row_regex.sub('', maybe_path) + row = int(row_search_result.group(1)) + path_normalized = normalize(maybe_path) if path_normalized in cache['checked']: return False @@ -448,7 +455,7 @@ def try_open(self, window, maybe_path): desktop.open(maybe_path) else: # Open within ST - self.open(window, maybe_path) + self.open(window, maybe_path, row = row) elif maybe_path and ( os_is_dir(maybe_path) or os_is_dir('\\' + maybe_path) ) and not cache['folder'] and cache['folder_save']: # Walkaround for UNC path @@ -521,12 +528,18 @@ def read_url_on_done(self, content, content_type): elif content_type == 'text/xml' or content_type == 'application/xml': view.settings().set('syntax', 'Packages/XML/XML.tmLanguage') - def open(self, window, path): + def open(self, window, path, row = None): if get_setting('in_secondary_colum', False): window.run_command('set_layout', {"cols": [0.0, 0.5, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]}) window.focus_group(1) window.open_file(path) + if row is not None: + view = window.active_view() + view.sel().clear() + view.sel().add(sublime.Region(view.text_point(row - 1, 0))) + view.show(view.text_point(row - 1, 0)) + class OpenIncludeFindInFileGoto(): def run(self, view): line_no = self.get_line_no(view) From 581363f5609f50e6bc7d3594b72299a3adbe3c8e Mon Sep 17 00:00:00 2001 From: Santiago Herrera Date: Thu, 24 Aug 2017 00:14:59 -0500 Subject: [PATCH 2/2] adding start row and end row --- open_include.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/open_include.py b/open_include.py index 0aff4bc..1c57067 100644 --- a/open_include.py +++ b/open_include.py @@ -419,12 +419,15 @@ def try_open(self, window, maybe_path): debug_info('Trying to open: ' + maybe_path) - row_regex = re.compile(r':(\d+)$') + row_regex = re.compile(r':(\d+)(?:-(\d+))?$') row_search_result = row_regex.search(maybe_path) - row = None + rows = None if row_search_result is not None: maybe_path = row_regex.sub('', maybe_path) - row = int(row_search_result.group(1)) + row_start = row_end = int(row_search_result.group(1)) + if row_search_result.group(2) is not None: + row_end = int(row_search_result.group(2)) + rows = [row_start, row_end] path_normalized = normalize(maybe_path) if path_normalized in cache['checked']: @@ -455,7 +458,7 @@ def try_open(self, window, maybe_path): desktop.open(maybe_path) else: # Open within ST - self.open(window, maybe_path, row = row) + self.open(window, maybe_path, rows = rows) elif maybe_path and ( os_is_dir(maybe_path) or os_is_dir('\\' + maybe_path) ) and not cache['folder'] and cache['folder_save']: # Walkaround for UNC path @@ -528,17 +531,23 @@ def read_url_on_done(self, content, content_type): elif content_type == 'text/xml' or content_type == 'application/xml': view.settings().set('syntax', 'Packages/XML/XML.tmLanguage') - def open(self, window, path, row = None): + def open(self, window, path, rows = None): if get_setting('in_secondary_colum', False): window.run_command('set_layout', {"cols": [0.0, 0.5, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]}) window.focus_group(1) window.open_file(path) - if row is not None: + if rows is not None: + start_row, end_row = min(rows), max(rows) + view = window.active_view() - view.sel().clear() - view.sel().add(sublime.Region(view.text_point(row - 1, 0))) - view.show(view.text_point(row - 1, 0)) + start_point = view.text_point(start_row - 1, 0) + end_point = view.text_point(end_row, 0) - 1 + + selection = view.sel() + selection.clear() + selection.add(sublime.Region(start_point, end_point)) + view.show(view.text_point(start_row - 1, 0)) class OpenIncludeFindInFileGoto(): def run(self, view):