io12 / org-fragtog

Automatically toggle Org mode LaTeX fragment previews as the cursor enters and exits them
MIT License
397 stars 14 forks source link

Obtain new bounds of previous fragment when enabling #27

Closed awth13 closed 3 years ago

awth13 commented 3 years ago

Rationale

Working on #25, I discovered another issue with the way prev-frag is enabled upon leaving. When an active (disabled) fragment is edited, its bounds change; org-fragtog, however, still uses the old bounds (stored in prev-frag) when the cursor leaves and the fragment is enabled. This is not an issue most of the time since org-latex-preview and org-clear-latex-preview are smart with how they treat toggled regions. Under certain conditions, however, this may cause another fragment to be incorrectly disabled. Here's an example:

$This LaTeX fragment$

$Next LaTeX fragment$

If we delete the word "LaTeX" in this fragment and move the cursor to the empty line that follows, the next LaTeX fragment will be disabled.

Testing

The next LaTeX fragment is no longer disabled in the situation described above.

Comments

I had and fixed the same issue in org-appear some time ago but didn't think it also affects org-fragtog. Turns out org-clear-latex-preview is not smart enough. I decided not to implement this fix within #25 because it's an unrelated issue.

io12 commented 3 years ago

Can you change the indents to use spaces instead of tabs? Otherwise this looks great thanks!

awth13 commented 3 years ago

Done and noted! Sorry for the inconvenience.