SublimeText / WordHighlight

Highlight all copies of the currently selected word.
MIT License
180 stars 24 forks source link

Add enable toggle? #16

Closed johnburnett closed 12 years ago

johnburnett commented 12 years ago

This is handy to have if files are huge, causing Sublime to bog down with highlighting. A better approach might be to back off on highlighting if it takes over a certain threshold of time, or something... but this was "good enough" for my needs :)

adzenith commented 12 years ago

It looks good; I'm just wondering if, like you said, we should take some other approach to this. What do you think?

johnburnett commented 12 years ago

There's two approaches I was thinking of:

1-Dynamically backing off the selection_delay (and ramping it back up again after some period). 2-Only searching in the currently visible text.

My gut says #1 would require a fair amount of tweaking to make it "feel good". It also wouldn't fix the underlying "search the whole file and be slow" problem with large files.

2 isn't entirely solvable given the Sublime API right now (see this post ). However, I guess you could have a heartbeat thread that watches for changes in view.visible_region, and do a pend_highlight_occurences if it's changed? (EDIT: and actually - I'm not sure that works in any case due to the lack of a "toPosition" argument on view.find, to limit the scope of the search... though I guess you could always use view.substr and search manually, but....)

Regardless, both take a sec to implement, and it feels like those could easily be added in addition to a "master enable switch" feature, which is useful now ;).

adzenith commented 12 years ago

I rebased this and pushed it. There was another change that makes it so that we don't search files over 4MB or something, but now this'll be in there too in case people want it.