Sublime Forum

Dynamic highlighting

#1

What would be the recommended way of highlighting parts of a view as the selection changes? I’ve been fiddling with updating the WordHighlight plugin, and have the moral equivalent of the following:

[code]import sublime_plugin

class HighlightCommand(sublime_plugin.TextCommand):
def run(self, edit):
pass

class TestListener(sublime_plugin.EventListener):
def on_selection_modified(self, view):
view.run_command(‘highlight’)
[/code]
…however, this seems to throw a wrench into undo grouping somehow, in that while this plugin is active each character inserted becomes its own undo entry.

0 Likes

#2

Thought I’d re-ping on this, and see if there was any official guidance here?

0 Likes

#3

It’s probably because “HighlightCommand” is a TextCommand, and thus gets its own edit object (you can see it there in the definition). Just have a separate highlight function and have both TestListener and HighlightCommand call it.
Seems like empty edits should be ignored, but I guess they’re not being.

0 Likes

#4

The only way I have found out to get around the undo problem is to open up a temporary tab on top…

0 Likes

#5

Did my recommendation not work?

0 Likes