obsidian-latex-suite
obsidian-latex-suite copied to clipboard
Contracting snippets at the end of a file causes tabout and bugs the editor
Snippets like {"^>"→"⟳"}, aka contracting snippets cause Tab to act on the browser interface (and tab outside the editor) instead of eating it, which makes the editor pane go crazy (into some weird insert-mode, tuning off saving the document once bugged). Currently investigating further...
Maybe it happens when cursor ends up outside the file, but app.vault.modify()
works fine with that when I use Templater.
This appers twice in the console:
RangeError: Invalid change range 94 to 96 (in doc of length 95)
at e (app.js:1:272982)
at e (app.js:1:272725)
at Function.t.of (app.js:1:273231)
at SnippetManager.expandSnippets (plugin:obsidian-latex-suite:7783:47)
at LatexSuitePlugin.runSnippets (plugin:obsidian-latex-suite:8177:43)
at LatexSuitePlugin.handleKeydown (plugin:obsidian-latex-suite:8101:26)
at Object.LatexSuitePlugin.onKeydown (plugin:obsidian-latex-suite:8086:28)
at e.runCustomHandlers (app.js:1:376149)
at HTMLDivElement.<anonymous> (app.js:1:374890)
ro @ app.js:1
e.runCustomHandlers @ app.js:1
(anonymous) @ app.js:1
First one is ChangeSet.of()
when moving tabstops over after changes are applied to the document. You should definetely fix that!
Seems that after it, all key presses try to expand the same snippet:
changes: [
{
"from": 94,
"to": 96,
"insert": "→",
"keyPressed": "Tab"
}
]
does not go away, crashing at tabstops moving, with history still disabled and all button presses showing up in the editor, but being mistaken with valid target for the snippet. (How could you not double-check just before "expanding" that trigger is still there?)
Second one is after const undoKeyPresses
, same trick.
So here is how it happens:
- line 7779:
view.dispatch()
with
combinedChanges = '[94,[2,"→"]]'
combinedChanges.inserted = '[[""],["→"]]'
combinedChanges.sections = '[94,-1,2,1]'
-length: 96
-newLength: 95
shrinks the document.
2. view.state.doc.length[=95]
you use instead of docLength[=96]
to create changeSet of the changes for the old document is incompatibe with the changes, so the whole thing stops execution by crashing, causing undefined behaviour of uncleared snippets queue. :clap:
Just by changing view.state.doc.length
to docLength
everything works again.
Awesome code design 👏🏻 👏🏻 👏🏻
Hi! Thanks for the report. I don't notice any issues with the snippet
{trigger: "^>", replacement: "⟳", options: "A"}
However, after removing the "auto" option so that the snippet has to be triggered with Tab, I find that pressing Tab to trigger the snippet does cause you to tab out of the editor, which is very strange. What do you mean by "contracting snippets"?
I'll look into the issue and your proposed solution when I have time!
I never use automatic snippets ) Feel like Tab is better than Ctrl+z So without options.
Fixed in 1.6.2, thanks for providing the solution!