From 5c13045532a2cfa55001785e35207bf123824b27 Mon Sep 17 00:00:00 2001 From: LordBrom Date: Tue, 10 Oct 2017 09:06:55 -0700 Subject: [PATCH 1/3] Adding "Select Duplicate" Command Adding the "Select Duplicates" to the commands list. --- Default.sublime-commands | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Default.sublime-commands b/Default.sublime-commands index 76dd588..89000ca 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -2,5 +2,9 @@ { "caption": "Highlight Duplicates: Toggle highlighting", "command": "toggle_highlight_duplicates" + }, + { + "caption": "Select Duplicates", + "command": "toggle_select_duplicates" } -] \ No newline at end of file +] From 076dc201e286d5d5e0f28007dcd18ce244ab3dc0 Mon Sep 17 00:00:00 2001 From: LordBrom Date: Tue, 10 Oct 2017 09:07:45 -0700 Subject: [PATCH 2/3] Adding "Select Duplicate" Command Adding code to select all the duplicate lines, instead of just outlining them. --- hightlight_duplicates.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hightlight_duplicates.py b/hightlight_duplicates.py index 8351275..32ab211 100644 --- a/hightlight_duplicates.py +++ b/hightlight_duplicates.py @@ -67,6 +67,15 @@ def show_lines(regions, view): sublime.DRAW_OUTLINED) +def add_lines(regions, view): + '''Merges all duplicated regions in one set and highlights them.''' + all_regions = [] + for r in regions: + for i in r: + print(i) + view.sel().add(i) + + def highlight_duplicates(view): '''Main function that glues everything for hightlighting.''' # get all lines @@ -77,6 +86,17 @@ def highlight_duplicates(view): show_lines(duplicates.values(), view) + +def select_duplicates(view): + '''Main function that glues everything for hightlighting.''' + # get all lines + lines = view.lines(sublime.Region(0, view.size())) + # count and filter out non duplicated lines + duplicates = filter_counts(count_lines(lines, view)) + # select duplicated lines + add_lines(duplicates.values(), view) + + def downlight_duplicates(window): '''Removes any region highlighted by this plugin accross all views.''' for view in window.views(): @@ -122,3 +142,8 @@ def run(self): highlight_duplicates(self.window.active_view()) else: downlight_duplicates(self.window) + + +class ToggleSelectDuplicatesCommand(sublime_plugin.WindowCommand): + def run(self): + select_duplicates(self.window.active_view()) From 482b1745e62ab0d28c9f91d9f0f3269bb599c9c1 Mon Sep 17 00:00:00 2001 From: LordBrom Date: Tue, 10 Oct 2017 09:21:48 -0700 Subject: [PATCH 3/3] Adding Ignore White Space Setting Added a setting for whether or not each line gets trimmed of white space, before checking for duplicates. --- highlight_duplicates.sublime-settings | 5 ++++- hightlight_duplicates.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/highlight_duplicates.sublime-settings b/highlight_duplicates.sublime-settings index 70a1a96..45d0eea 100644 --- a/highlight_duplicates.sublime-settings +++ b/highlight_duplicates.sublime-settings @@ -3,5 +3,8 @@ "highlight_duplicates_color" : "invalid", // By default plugin is enabled or disabled (true|false) - "highlight_duplicates_enabled" : true + "highlight_duplicates_enabled" : true, + + // If true, whitespace gets trimmed off each line before checking for matching lines + "ignore_white_space" : true } \ No newline at end of file diff --git a/hightlight_duplicates.py b/hightlight_duplicates.py index 32ab211..41cd130 100644 --- a/hightlight_duplicates.py +++ b/hightlight_duplicates.py @@ -31,7 +31,10 @@ def count_lines(lines, view): ''' counts = defaultdict(list) for line in lines: - string = view.substr(line).strip() + if bool(settings.get('ignore_white_space', DEFAULT_IS_ENABLED)): + string = view.substr(line).strip() + else: + string = view.substr(line) if is_candidate(string): counts[string].append(line) return counts