Sublime Forum

Techniques for listening to changes to a region(s)?

#1

I’m attempting to write a plugin that will modify one file based on changes made to a separate file. I have thought about several techniques that could be used to accomplish this, but would appreciate some feedback from those more knowledgeable than I.

I have successfully identified the regions that I am concerned with changes to. My challenge at this point is to modify the second file based on changes to these regions in the first file. Ideally, what I would like to do is trigger an event when the user enters one of these regions and then leaves that region. Is this possible?

Another possible approach would be to listen to changes throughout the whole document, and then see if those changes are inside the specified regions, possibly using a timer, but this approach is less than ideal and would require some hacky workarounds to maintain the desired functionality without becoming a hindrance.

Appreciate any feedback on this, thank you.

0 Likes

#2

you could use the on_selection_modified API and check whether a cursor is within your region: http://www.sublimetext.com/docs/3/api_reference.html#sublime_plugin.EventListener

this thread may also be of interest: Retrieving inserted and deleted text

0 Likes