def match(self, view, force_match=True): """Preform matching brackets surround the selection(s).""" if view is None: return # Ensure nothing else calls BH until done view.settings().set("BracketHighlighterBusy", True) # Abort if disabled if not GLOBAL_ENABLE: for region_key in view.settings().get("bh_regions", []): view.erase_regions(region_key) view.settings().set("BracketHighlighterBusy", False) return # Handle key command quirks if self.keycommand: BhCore.plugin_reload = True if not self.keycommand and BhCore.plugin_reload: self.setup() BhCore.plugin_reload = False # Setup view self.view = view sels = view.sel() num_sels = len(sels) # Abort if selections are beyond the threshold and "kill" is enabled if not self.ignore_threshold and self.kill_highlight_on_threshold: if self.use_selection_threshold and num_sels > self.auto_selection_threshold: self.regions.reset(view, num_sels) self.regions.highlight(HIGH_VISIBILITY) view.settings().set("BracketHighlighterBusy", False) return # Initialize if self.unique(sels) or force_match: # Prepare for match self.init_match(num_sels) # Nothing to search for if not self.rules.enabled: view.settings().set("BracketHighlighterBusy", False) return # Process selections. multi_select_count = 0 for sel in sels: if not self.ignore_threshold and multi_select_count >= self.auto_selection_threshold: # Exceeded threshold, only what must be done # and break if not self.regions.alter_select: break self.regions.store_sel([sel]) continue # Subsearch guard for recursive matching of scopes self.recursive_guard = False # Prepare for search self.bracket_style = None self.search = bh_search.Search( view, self.rules, sel, self.selection_threshold if not self.ignore_threshold else None) # Find and match if not self.find_scopes(sel): self.sub_search_mode = False self.find_matches(sel) multi_select_count += 1 # Highlight, focus, and display lines etc. self.regions.highlight(HIGH_VISIBILITY) # Free up BH self.search = None self.view = None view.settings().set("BracketHighlighterBusy", False)
def match(self, view, force_match=True, clone_view=False): """Preform matching brackets surround the selection(s).""" if view is None: return # Ensure nothing else calls BH until done view.settings().set("bracket_highlighter.busy", True) if clone_view: view.settings().set("bracket_highlighter.clone", view.id()) elif view.id() == view.settings().set("bracket_highlighter.clone", -1): # Catch situations for a manual command invokes this and it is not known this is a clone. clone_view = True view.settings().set("bracket_highlighter.clone", view.id()) regions_key = "bracket_highlighter.clone_regions" if clone_view else "bracket_highlighter.regions" locations_key = "bracket_highlighter.clone_locations" if clone_view else "bracket_highlighter.locations" # Abort if disabled if not GLOBAL_ENABLE: for region_key in view.settings().get(regions_key, []): view.erase_regions(region_key) view.settings().set(locations_key, {}) view.settings().set("bracket_highlighter.busy", False) return # Handle key command quirks if self.keycommand: BhCore.plugin_reload = True if not self.keycommand and BhCore.plugin_reload: self.setup() BhCore.plugin_reload = False # Setup view self.view = view self.refresh_match = False sels = view.sel() num_sels = len(sels) # Abort if selections are beyond the threshold and "kill" is enabled if not self.ignore_threshold and self.kill_highlight_on_threshold: if self.use_selection_threshold and num_sels > self.auto_selection_threshold: self.regions.reset(view, num_sels) self.regions.highlight(HIGH_VISIBILITY, clone_view) view.settings().set("bracket_highlighter.busy", False) return # Initialize if self.unique(sels) or force_match: # Prepare for match self.init_match(num_sels) # Nothing to search for if not self.rules.enabled: view.settings().set("bracket_highlighter.busy", False) return # Process selections. multi_select_count = 0 for sel in sels: if not self.ignore_threshold and multi_select_count >= self.auto_selection_threshold: # Exceeded threshold, only what must be done # and break if not self.regions.alter_select: break self.regions.store_sel([sel]) continue # Subsearch guard for recursive matching of scopes self.recursive_guard = False # Prepare for search self.bracket_style = None self.search = bh_search.Search( view, self.rules, sel, self.selection_threshold if not self.ignore_threshold else None) # Find and match if not self.find_scopes(sel): self.sub_search_mode = False self.find_matches(sel) multi_select_count += 1 # Highlight, focus, and display lines etc. self.regions.highlight(HIGH_VISIBILITY, clone_view) # Free up BH self.search = None self.view = None # Setup thread to do another match to refresh the match if self.refresh_match: bh_thread.type = BH_MATCH_TYPE_SELECTION bh_thread.modified = True bh_thread.time = time() view.settings().set("bracket_highlighter.busy", False)