Callback on line deleted/added

I’m working on a Bookmarks extension for Nova, and it needs to be notified when some lines of the document with bookmarks are deleted/added, so it can adjust the line number of bookmarks. However, I don’t find any APIs that can help to archive this goal.

Hi,

How are you saving the bookmarks?

If you’re storing the line-number AND the bookmarked-text then you can search for string with Scanner & scanUpToString on the TextEditor file contents when onDidSave event is triggered. Then you can assert the new line number and save.

I hope that moves things forward for you.
Danny

Thanks for your reply.

How are you saving the bookmarks?

I only save the line number and get the content of the line when sidebar view is created.

If you’re storing the line-number AND the bookmarked-text then you can search for string with Scanner & scanUpToString on the TextEditor file contents when onDidSave event is triggered.

However, if users modify a line with a bookmark, the scanUpToString cannot locate the line.

Hi,

With just a stored line-number and no stored line-text you’ll have no upfront-user-intent-reference to the bookmarked text with which recalibrate when the numbers change.

You might be able to keep track of line numbers changes in some other way, but I cant think through how it might work with your current approach (no reference to what the user actually wants to retain - a text snippet) - I went down that route initially myself.

With just a stored line-number and no stored line-text you’ll have no upfront-user-intent-reference to the bookmarked text with which recalibrate when the numbers change.

The followings are what I want to achieve:

  • If a user delete a line before a bookmarked-line, the line number of the bookmark should decrement.
  • If a user add a line before a bookmarked-line, the line number of the bookmark should increment.
  • If a user delete a bookmarked-line, the bookmark should be removed.

You might be able to keep track of line numbers changes in some other way, but I cant think through how it might work with your current approach

This is just why I request a feature to detect line deletion.