Sublime Forum

[API][CONCEALER] Best way to have inline Phantom update


Hello there, I was working on a sublime concealer for LaTeX in my free time, and the prototype works fairly well. See the dropbox link for a demo. Preview is disabled because of ubuntu’s default screencast format.

In short, here’s how the concealer works:

  1. Takes in everything inside the $ $ delimiters, converts it to utf-8.
  2. Folds the tex code
  3. Replaces it with a phantom containing the utf as html

The only feature that I would like to add now is to be able to do the following two things happen in real time:

  1. If point is in line N, then the phantoms in line N disappear.
  2. When you leave line N, the plugin auto-adds phantoms in line N.

I am currently using a ViewEventListener, but I see a couple of issues.

  1. If I update phantoms from the beginning of the file after every keystroke, sublime will crash.
  2. There does not seem to be adequate API methods to erase phantoms (say, by line number).

Does anyone have any suggestions on how best to go about doing this? Otherwise I might create a key binding that conceals everything in a selected region (EDIT: did this, the gif above is proof). That won’t be ideal for obvious reasons ;-;

TLDR. Trying to use phantoms to replicate vim’s conceal feature.

EDIT 2: Here’s some code without much explanation: (P.S: requires a key-binding to work).

EDIT: I had a thought after posting this. Perhaps I could use add_phantoms() and use key = line number. Then I can use erase_phantoms(key). There is only one issue, the line number can and will change :confused: Perhaps there could be some way of making the key a function of the line number, but that requires changing how phantoms work themselves(?)