Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracting snippets at the end of a file causes tabout and bugs the editor #70

Closed
vlad2305m opened this issue Oct 19, 2022 · 7 comments

Comments

@vlad2305m
Copy link

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...

@vlad2305m
Copy link
Author

vlad2305m commented Oct 19, 2022

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.

@vlad2305m
Copy link
Author

So here is how it happens:

  1. 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. 👏

@vlad2305m
Copy link
Author

Just by changing view.state.doc.length to docLength everything works again.
Awesome code design 👏🏻 👏🏻 👏🏻

@vlad2305m
Copy link
Author

here

@artisticat1
Copy link
Owner

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!

@vlad2305m
Copy link
Author

vlad2305m commented Oct 20, 2022

I never use automatic snippets )
Feel like Tab is better than Ctrl+z
So without options.

@artisticat1
Copy link
Owner

Fixed in 1.6.2, thanks for providing the solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants