From 730e15a1478798878285840efe4940aa85f9d2c7 Mon Sep 17 00:00:00 2001 From: mg979 Date: Fri, 29 Sep 2017 04:53:44 +0200 Subject: [PATCH 1/4] more options for multi_find_all --- Default (Linux).sublime-keymap | 10 +++++++++- Default (OSX).sublime-keymap | 10 +++++++++- Default (Windows).sublime-keymap | 10 +++++++++- MultiEditUtils.py | 29 ++++++++++++++++++++++++++--- README.md | 13 ++++++++++++- 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index aaefb40..f32403c 100755 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -10,7 +10,15 @@ {"key": "setting.is_widget", "operator": "equal", "operand": false} ] }, - { "keys": ["ctrl+alt+f"], "command": "multi_find_all" }, + + // multi find all - the first is the same behaviour as old [alt+f3], and it's the same as [alt+f3, ctrl+w], incuded for consistency + { "keys": ["alt+f3", "alt+f3"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + { "keys": ["alt+f3", "c"], "command": "multi_find_all", "args": {"case": true}}, + { "keys": ["alt+f3", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, + { "keys": ["alt+f3", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, + { "keys": ["alt+f3", "ctrl+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + { "keys": ["alt+f3", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, + { "keys": ["ctrl+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} }, { "keys": ["escape"], "command": "selection_fields", "args": {"mode": "pop"}, diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index 00515da..0e3dbb5 100755 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -10,7 +10,15 @@ {"key": "setting.is_widget", "operator": "equal", "operand": false} ] }, - { "keys": ["super+alt+j"], "command": "multi_find_all" }, + + // multi find all - the first is the same behaviour as old [alt+f3], and it's the same as [alt+f3, ctrl+w], incuded for consistency + { "keys": ["ctrl+super+g", "ctrl+super+g"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + { "keys": ["ctrl+super+g", "c"], "command": "multi_find_all", "args": {"case": true}}, + { "keys": ["ctrl+super+g", "super+c"], "command": "multi_find_all", "args": {"case": false}}, + { "keys": ["ctrl+super+g", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, + { "keys": ["ctrl+super+g", "super+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + { "keys": ["ctrl+super+g", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, + { "keys": ["super+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} }, { "keys": ["escape"], "command": "selection_fields", "args": {"mode": "pop"}, diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index aaefb40..f32403c 100755 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -10,7 +10,15 @@ {"key": "setting.is_widget", "operator": "equal", "operand": false} ] }, - { "keys": ["ctrl+alt+f"], "command": "multi_find_all" }, + + // multi find all - the first is the same behaviour as old [alt+f3], and it's the same as [alt+f3, ctrl+w], incuded for consistency + { "keys": ["alt+f3", "alt+f3"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + { "keys": ["alt+f3", "c"], "command": "multi_find_all", "args": {"case": true}}, + { "keys": ["alt+f3", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, + { "keys": ["alt+f3", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, + { "keys": ["alt+f3", "ctrl+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + { "keys": ["alt+f3", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, + { "keys": ["ctrl+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} }, { "keys": ["escape"], "command": "selection_fields", "args": {"mode": "pop"}, diff --git a/MultiEditUtils.py b/MultiEditUtils.py index dd04e86..dee348b 100755 --- a/MultiEditUtils.py +++ b/MultiEditUtils.py @@ -4,15 +4,38 @@ class MultiFindAllCommand(sublime_plugin.TextCommand): - def run(self, edit): + def run(self, edit, case=True, word=False, ignore_comments=False): view = self.view newRegions = [] + selected_words = [view.substr(view.word(sel)).lower() for sel in view.sel()] for region in view.sel(): substr = view.substr(region) - for region in view.find_all(substr, sublime.LITERAL): - newRegions.append(region) + + if case: + for region in view.find_all(substr, sublime.LITERAL): + newRegions.append(region) + else: + for region in view.find_all(substr, sublime.LITERAL | sublime.IGNORECASE): + newRegions.append(region) + + if word: + deleted = [] + for region in newRegions: + if view.substr(view.word(region)).lower() not in selected_words: + deleted.append(region) + newRegions = [region for region in newRegions if region not in deleted] + + if ignore_comments: + deleted = [] + for region in newRegions: + scope = view.scope_name(region.begin()) + comment = re.search(r'\bcomment\b', scope) + if comment: + print(comment.group(0)) + deleted.append(region) + newRegions = (region for region in newRegions if region not in deleted) for region in newRegions: view.sel().add(region) diff --git a/README.md b/README.md index 26116fc..b1b021a 100755 --- a/README.md +++ b/README.md @@ -67,8 +67,19 @@ When splitting your selection or performing other actions on your selection, it ### Quick Find All for multiple selections -Similar to the built-in "Quick Find All" functionality, MultiEditUtils provides a functionality which selects all occurrences of all active selections. The default keybinding of the ```multi_find_all``` command is **ctrl+alt+f** (on Mac it's **cmd+alt+j**). +Similar to the built-in "Quick Find All" functionality, MultiEditUtils provides a functionality which selects all occurrences of all active selections. These are the default keybindings for Windows/Linux (for OSX replace `alt+f3` with `ctrl+super+g`, and additional `ctrl` modifier with `super`). +``` +alt+f3, alt+f3 case: false word: true +alt+f3, c case: true +alt+f3, ctrl+c case: false +alt+f3, w case: true word: true +alt+f3, ctrl+w case: false word: true +alt+f3, q case: true word: true ignore_comments: true + +Note that the first keybinding works just the same as old `find_all_under` +(and replaces it), but it supports multiple selections. +``` ![](http://philippotto.github.io/Sublime-MultiEditUtils/screens/08%20multi%20find%20all.gif) From fa373268bb4707169534c9321d2e139c7359ef11 Mon Sep 17 00:00:00 2001 From: mg979 Date: Fri, 29 Sep 2017 05:15:36 +0200 Subject: [PATCH 2/4] removed a debug message, restored two keybindings --- Default (Linux).sublime-keymap | 6 ++++-- Default (OSX).sublime-keymap | 10 ++++++---- Default (Windows).sublime-keymap | 6 ++++-- MultiEditUtils.py | 1 - README.md | 9 ++++----- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index f32403c..8ac32c0 100755 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -11,8 +11,10 @@ ] }, - // multi find all - the first is the same behaviour as old [alt+f3], and it's the same as [alt+f3, ctrl+w], incuded for consistency - { "keys": ["alt+f3", "alt+f3"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + // multi find all - the first is the same behaviour as old [alt+f3] + { "keys": ["alt+f3", "alt+f3"], "command": "find_all_under"}, + + { "keys": ["ctrl+alt+f"], "command": "multi_find_all" }, { "keys": ["alt+f3", "c"], "command": "multi_find_all", "args": {"case": true}}, { "keys": ["alt+f3", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, { "keys": ["alt+f3", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index 0e3dbb5..9325397 100755 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -11,12 +11,14 @@ ] }, - // multi find all - the first is the same behaviour as old [alt+f3], and it's the same as [alt+f3, ctrl+w], incuded for consistency - { "keys": ["ctrl+super+g", "ctrl+super+g"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + // multi find all - the first is the same behaviour as old [alt+f3] + { "keys": ["ctrl+super+g", "ctrl+super+g"], "command": "find_all_under"}, + + { "keys": ["super+alt+j"], "command": "multi_find_all" }, { "keys": ["ctrl+super+g", "c"], "command": "multi_find_all", "args": {"case": true}}, - { "keys": ["ctrl+super+g", "super+c"], "command": "multi_find_all", "args": {"case": false}}, + { "keys": ["ctrl+super+g", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, { "keys": ["ctrl+super+g", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, - { "keys": ["ctrl+super+g", "super+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + { "keys": ["ctrl+super+g", "ctrl+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, { "keys": ["ctrl+super+g", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, { "keys": ["super+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} }, diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index f32403c..8ac32c0 100755 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -11,8 +11,10 @@ ] }, - // multi find all - the first is the same behaviour as old [alt+f3], and it's the same as [alt+f3, ctrl+w], incuded for consistency - { "keys": ["alt+f3", "alt+f3"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + // multi find all - the first is the same behaviour as old [alt+f3] + { "keys": ["alt+f3", "alt+f3"], "command": "find_all_under"}, + + { "keys": ["ctrl+alt+f"], "command": "multi_find_all" }, { "keys": ["alt+f3", "c"], "command": "multi_find_all", "args": {"case": true}}, { "keys": ["alt+f3", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, { "keys": ["alt+f3", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, diff --git a/MultiEditUtils.py b/MultiEditUtils.py index dee348b..247f13d 100755 --- a/MultiEditUtils.py +++ b/MultiEditUtils.py @@ -33,7 +33,6 @@ def run(self, edit, case=True, word=False, ignore_comments=False): scope = view.scope_name(region.begin()) comment = re.search(r'\bcomment\b', scope) if comment: - print(comment.group(0)) deleted.append(region) newRegions = (region for region in newRegions if region not in deleted) diff --git a/README.md b/README.md index b1b021a..4c2fb18 100755 --- a/README.md +++ b/README.md @@ -67,18 +67,17 @@ When splitting your selection or performing other actions on your selection, it ### Quick Find All for multiple selections -Similar to the built-in "Quick Find All" functionality, MultiEditUtils provides a functionality which selects all occurrences of all active selections. These are the default keybindings for Windows/Linux (for OSX replace `alt+f3` with `ctrl+super+g`, and additional `ctrl` modifier with `super`). +Similar to the built-in "Quick Find All" functionality, MultiEditUtils provides a functionality which selects all occurrences of all active selections. The default keybinding of the ```multi_find_all``` command is **ctrl+alt+f** (on Mac it's **cmd+alt+j**). +These are additional keybindings for Windows/Linux (on Mac replace **alt+f3** with **ctrl+super+g**). ``` -alt+f3, alt+f3 case: false word: true +alt+f3, alt+f3 old 'find_all_under' command + alt+f3, c case: true alt+f3, ctrl+c case: false alt+f3, w case: true word: true alt+f3, ctrl+w case: false word: true alt+f3, q case: true word: true ignore_comments: true - -Note that the first keybinding works just the same as old `find_all_under` -(and replaces it), but it supports multiple selections. ``` ![](http://philippotto.github.io/Sublime-MultiEditUtils/screens/08%20multi%20find%20all.gif) From b29aeca8557ea8f8e44f5ea8e78cc9b086428083 Mon Sep 17 00:00:00 2001 From: mg979 Date: Sat, 30 Sep 2017 07:20:04 +0200 Subject: [PATCH 3/4] reworked a bit MultiFindAll, added MultiFindAllRegex, submenu from command palette, made keybindings inactive for these commands, updated readme --- Default (Linux).sublime-keymap | 24 ++++--- Default (OSX).sublime-keymap | 24 ++++--- Default (Windows).sublime-keymap | 24 ++++--- Default.sublime-commands | 2 +- MultiEditUtils.py | 113 +++++++++++++++++++++++++++---- README.md | 27 +++++--- 6 files changed, 169 insertions(+), 45 deletions(-) diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index 8ac32c0..5f8d93b 100755 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -11,15 +11,23 @@ ] }, - // multi find all - the first is the same behaviour as old [alt+f3] - { "keys": ["alt+f3", "alt+f3"], "command": "find_all_under"}, + // Multi Find All example keybindings, uncomment to activate + + // // main keybinding, set the search type you're most comfortable with, default is Case+Word + // { "keys": ["ctrl+alt+f", "ctrl+alt+f"], "command": "multi_find_all", "args": {"case": true, "word": true}}, + + // { "keys": ["ctrl+alt+f", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, + // { "keys": ["ctrl+alt+f", "c"], "command": "multi_find_all", "args": {"case": true}}, + // { "keys": ["ctrl+alt+f", "ctrl+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + // { "keys": ["ctrl+alt+f", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, + // { "keys": ["ctrl+alt+f", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, + + // // find all with regex search, additive(on top of current selection) or subtractive + // { "keys": ["ctrl+alt+f", "r"], "command": "multi_find_all_regex"}, + // { "keys": ["ctrl+alt+f", "ctrl+alt+r"], "command": "multi_find_all_regex", "args": {"subtract": true}}, + // { "keys": ["ctrl+alt+f", "ctrl+r"], "command": "multi_find_all_regex", "args": {"case": false}}, + // { "keys": ["ctrl+alt+f", "ctrl+alt+shift+r"], "command": "multi_find_all_regex", "args": {"subtract": true, "case": false}}, - { "keys": ["ctrl+alt+f"], "command": "multi_find_all" }, - { "keys": ["alt+f3", "c"], "command": "multi_find_all", "args": {"case": true}}, - { "keys": ["alt+f3", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, - { "keys": ["alt+f3", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, - { "keys": ["alt+f3", "ctrl+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, - { "keys": ["alt+f3", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, { "keys": ["ctrl+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} }, { "keys": ["escape"], "command": "selection_fields", diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index 9325397..83fefe2 100755 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -11,15 +11,23 @@ ] }, - // multi find all - the first is the same behaviour as old [alt+f3] - { "keys": ["ctrl+super+g", "ctrl+super+g"], "command": "find_all_under"}, + // Multi Find All example keybindings, uncomment to activate + + // // main keybinding, set the search type you're most comfortable with, default is Case+Word + // { "keys": ["ctrl+super+g", "ctrl+super+g"], "command": "multi_find_all", "args": {"case": true, "word": true}}, + + // { "keys": ["ctrl+super+g", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, + // { "keys": ["ctrl+super+g", "c"], "command": "multi_find_all", "args": {"case": true}}, + // { "keys": ["ctrl+super+g", "ctrl+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + // { "keys": ["ctrl+super+g", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, + // { "keys": ["ctrl+super+g", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, + + // // find all with regex search, additive(on top of current selection) or subtractive + // { "keys": ["ctrl+super+g", "r"], "command": "multi_find_all_regex"}, + // { "keys": ["ctrl+super+g", "ctrl+alt+r"], "command": "multi_find_all_regex", "args": {"subtract": true}}, + // { "keys": ["ctrl+super+g", "ctrl+r"], "command": "multi_find_all_regex", "args": {"case": false}}, + // { "keys": ["ctrl+super+g", "ctrl+alt+shift+r"], "command": "multi_find_all_regex", "args": {"subtract": true, "case": false}}, - { "keys": ["super+alt+j"], "command": "multi_find_all" }, - { "keys": ["ctrl+super+g", "c"], "command": "multi_find_all", "args": {"case": true}}, - { "keys": ["ctrl+super+g", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, - { "keys": ["ctrl+super+g", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, - { "keys": ["ctrl+super+g", "ctrl+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, - { "keys": ["ctrl+super+g", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, { "keys": ["super+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} }, { "keys": ["escape"], "command": "selection_fields", diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index 8ac32c0..5f8d93b 100755 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -11,15 +11,23 @@ ] }, - // multi find all - the first is the same behaviour as old [alt+f3] - { "keys": ["alt+f3", "alt+f3"], "command": "find_all_under"}, + // Multi Find All example keybindings, uncomment to activate + + // // main keybinding, set the search type you're most comfortable with, default is Case+Word + // { "keys": ["ctrl+alt+f", "ctrl+alt+f"], "command": "multi_find_all", "args": {"case": true, "word": true}}, + + // { "keys": ["ctrl+alt+f", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, + // { "keys": ["ctrl+alt+f", "c"], "command": "multi_find_all", "args": {"case": true}}, + // { "keys": ["ctrl+alt+f", "ctrl+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, + // { "keys": ["ctrl+alt+f", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, + // { "keys": ["ctrl+alt+f", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, + + // // find all with regex search, additive(on top of current selection) or subtractive + // { "keys": ["ctrl+alt+f", "r"], "command": "multi_find_all_regex"}, + // { "keys": ["ctrl+alt+f", "ctrl+alt+r"], "command": "multi_find_all_regex", "args": {"subtract": true}}, + // { "keys": ["ctrl+alt+f", "ctrl+r"], "command": "multi_find_all_regex", "args": {"case": false}}, + // { "keys": ["ctrl+alt+f", "ctrl+alt+shift+r"], "command": "multi_find_all_regex", "args": {"subtract": true, "case": false}}, - { "keys": ["ctrl+alt+f"], "command": "multi_find_all" }, - { "keys": ["alt+f3", "c"], "command": "multi_find_all", "args": {"case": true}}, - { "keys": ["alt+f3", "ctrl+c"], "command": "multi_find_all", "args": {"case": false}}, - { "keys": ["alt+f3", "w"], "command": "multi_find_all", "args": {"case": true, "word": true}}, - { "keys": ["alt+f3", "ctrl+w"], "command": "multi_find_all", "args": {"case": false, "word": true}}, - { "keys": ["alt+f3", "q"], "command": "multi_find_all", "args": {"case": true, "word": true, "ignore_comments": true}}, { "keys": ["ctrl+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} }, { "keys": ["escape"], "command": "selection_fields", diff --git a/Default.sublime-commands b/Default.sublime-commands index e39d1bd..c57624f 100755 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -8,6 +8,6 @@ { "command": "split_selection", "caption" : "MultiEditUtils: Split selection" }, { "command": "strip_selection", "caption" : "MultiEditUtils: Strip Selection" }, { "command": "remove_empty_regions", "caption" : "MultiEditUtils: Remove Empty Regions" }, - { "command": "multi_find_all", "caption" : "MultiEditUtils: Multi FindAll" }, + { "command": "multi_find_menu", "caption" : "MultiEditUtils: Multi FindAll" }, { "command": "preserve_case", "caption" : "MultiEditUtils: Preserve Case" } ] diff --git a/MultiEditUtils.py b/MultiEditUtils.py index 247f13d..c6ee635 100755 --- a/MultiEditUtils.py +++ b/MultiEditUtils.py @@ -4,10 +4,37 @@ class MultiFindAllCommand(sublime_plugin.TextCommand): - def run(self, edit, case=True, word=False, ignore_comments=False): + def run(self, edit, case=True, word=False, ignore_comments=False, expand=True): view = self.view newRegions = [] + + # filter selections in order to exclude duplicates since it can hang + # Sublime if search is performed on dozens of selections, this doesn't + # happen with built-in command because it works on a single selection + initial = [sel for sel in view.sel()] + regions, substrings = [], [] + for region in view.sel(): + if expand and region.empty(): + # if expanding substring will be the word + region = view.word(region.a) + # add the region since nothing is selected yet + view.sel().add(region) + # filter by substring (word or not) + substr = view.substr(region) + if substr and substr not in substrings: + regions.append(region) + substrings.append(substr) + view.sel().clear() + if regions: + for region in regions: + view.sel().add(region) + else: + view.window().status_message("Multi Find All: nothing selected") + for sel in initial: + view.sel().add(sel) + return + selected_words = [view.substr(view.word(sel)).lower() for sel in view.sel()] for region in view.sel(): @@ -21,24 +48,86 @@ def run(self, edit, case=True, word=False, ignore_comments=False): newRegions.append(region) if word: - deleted = [] - for region in newRegions: - if view.substr(view.word(region)).lower() not in selected_words: - deleted.append(region) + deleted = [region for region in newRegions + if view.substr(view.word(region)).lower() not in selected_words] newRegions = [region for region in newRegions if region not in deleted] if ignore_comments: - deleted = [] - for region in newRegions: - scope = view.scope_name(region.begin()) - comment = re.search(r'\bcomment\b', scope) - if comment: - deleted.append(region) - newRegions = (region for region in newRegions if region not in deleted) + deleted = [region for region in newRegions + if re.search(r'\bcomment\b', view.scope_name(region.a))] + newRegions = [region for region in newRegions if region not in deleted] for region in newRegions: view.sel().add(region) +class MultiFindAllRegexCommand(sublime_plugin.TextCommand): + + def on_done(self, regex): + + case = sublime.IGNORECASE if not self.case else 0 + regions = self.view.find_all(regex, case) + + # we don't clear the selection so it's additive, it's nice to just add a + # regex search on top of a previous search + if not self.subtract: + for region in regions: + self.view.sel().add(region) + + # the resulting regions will be subtracted instead + else: + for region in regions: + self.view.sel().subtract(region) + + # remove empty selections in both cases, so there aren't loose cursors + regions = [r for r in self.view.sel() if not r.empty()] + self.view.sel().clear() + for region in regions: + self.view.sel().add(region) + for region in self.view.sel(): + print(region) + + def run(self, edit, case=True, subtract=False): + + self.edit = edit + self.case = case + self.subtract = subtract + c = "Additive regex search:" if not subtract else "Subtractive regex search:" + sublime.active_window().show_input_panel(c, "", self.on_done, None, None) + +class MultiFindMenuCommand(sublime_plugin.TextCommand): + + def run(self, edit): + + choice = [ + "Find All Case + Word +", + "Find All Case + Word -", + "Find All Case - Word +", + "Find All Case - Word -", + "Find All Case + Word + Ignore Comments)", + "Find Regex (Additive)", + "Find Regex (Subtractive)" + ] + + def on_done(index): + + if index == -1: + return + if index == 0: + self.view.run_command('multi_find_all', {"case": True, "word": True}) + elif index == 1: + self.view.run_command('multi_find_all', {"case": True}) + elif index == 2: + self.view.run_command('multi_find_all', {"case": False, "word": True}) + elif index == 3: + self.view.run_command('multi_find_all', {"case": False}) + elif index == 4: + self.view.run_command('multi_find_all', {"case": True, "word": True, "ignore_comments": True}) + elif index == 5: + self.view.run_command('multi_find_all_regex') + elif index == 6: + self.view.run_command('multi_find_all_regex', {"subtract": True}) + + self.view.window().show_quick_panel(choice, on_done, 1, 0, None) class JumpToLastRegionCommand(sublime_plugin.TextCommand): diff --git a/README.md b/README.md index 4c2fb18..6f72144 100755 --- a/README.md +++ b/README.md @@ -67,18 +67,29 @@ When splitting your selection or performing other actions on your selection, it ### Quick Find All for multiple selections -Similar to the built-in "Quick Find All" functionality, MultiEditUtils provides a functionality which selects all occurrences of all active selections. The default keybinding of the ```multi_find_all``` command is **ctrl+alt+f** (on Mac it's **cmd+alt+j**). +Similar to the built-in "Quick Find All" functionality, MultiEditUtils provides a functionality which selects all occurrences of all active selections. By default, it will select the word the cursor is on, if the selection is empty, just like `find_all_under` command. If you don't like this behaviour, add the argument `"expand": false` -These are additional keybindings for Windows/Linux (on Mac replace **alt+f3** with **ctrl+super+g**). +These are just suggested keybindings, but you'll have to activate them in your keymap file first. Here shown for Windows/Linux: + +``` +ctrl+alt+f, ctrl+alt+f case: true word: true + +ctrl+alt+f, c case: true +ctrl+alt+f, ctrl+c case: false +ctrl+alt+f, w case: true word: true +ctrl+alt+f, ctrl+w case: false word: true +ctrl+alt+f, q case: true word: true ignore_comments: true ``` -alt+f3, alt+f3 old 'find_all_under' command -alt+f3, c case: true -alt+f3, ctrl+c case: false -alt+f3, w case: true word: true -alt+f3, ctrl+w case: false word: true -alt+f3, q case: true word: true ignore_comments: true +Additionally, you can perform a regex search that finds all occurrences of the entered regex. It can be **additive** (applied on top of your current selection) or **subtractive** (removes the results of the search instead). Example keybindings: + +``` +ctrl+alt+f, r +ctrl+alt+f, ctrl+alt+r subtract: true +ctrl+alt+f, ctrl+r case : false +ctrl+alt+f, ctrl+alt+shift+r subtract: true case: false ``` + ![](http://philippotto.github.io/Sublime-MultiEditUtils/screens/08%20multi%20find%20all.gif) From ee4b1d0d1afd7b4944b47dd77c99136cc8fe8458 Mon Sep 17 00:00:00 2001 From: mg979 Date: Sat, 30 Sep 2017 17:31:10 +0200 Subject: [PATCH 4/4] fixed typo on menu for MultiFindAll --- MultiEditUtils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MultiEditUtils.py b/MultiEditUtils.py index c6ee635..149b050 100755 --- a/MultiEditUtils.py +++ b/MultiEditUtils.py @@ -103,7 +103,7 @@ def run(self, edit): "Find All Case + Word -", "Find All Case - Word +", "Find All Case - Word -", - "Find All Case + Word + Ignore Comments)", + "Find All Case + Word + (Ignore Comments)", "Find Regex (Additive)", "Find Regex (Subtractive)" ]