ArianaKhit / text-snippets-obsidian

Snippets plugin for obsidian
190 stars 23 forks source link

Will Snippets work in the new version of the editor? #29

Open skq1998 opened 2 years ago

skq1998 commented 2 years ago

I found that snippets work fine in older versions of the editor, when will newer versions be supported?

jonnyg23 commented 2 years ago

Same for me. Snippets doesn't work in the new Live Preview mode.

olivierdagenais commented 2 years ago

I used the dev tools to find out what's going on; there's this stacktrace that shows up when invoking the command in Live Preview:

TypeError: editor.findWordAt is not a function
    at TextSnippets.getWordBoundaries (eval at <anonymous> (app.js:1), <anonymous>:100:27)
    at TextSnippets.insertSnippet (eval at <anonymous> (app.js:1), <anonymous>:173:14)
    at TextSnippets.SnippetOnTrigger (eval at <anonymous> (app.js:1), <anonymous>:237:18)
    at Object.callback (eval at <anonymous> (app.js:1), <anonymous>:44:38)
    at uR (app.js:1)
    at t.executeCommandById (app.js:1)
    at t.onTrigger (app.js:1)
    at t.handleKey (app.js:1)
    at t.onKeyEvent (app.js:1)

CodeMirror indeed exposes a findWordAt() method (search for it at https://codemirror.net/doc/manual.html#api_selection) but, in Live Preview mode, the CodeMirror.Editor instance in editor indeed does not expose that method; according to Release v0.13.0, we could be calling the wordAt() method (which seems to call the internal findWordAt() method!), instead, which I confirmed was available by setting a breakpoint and adding the following watches in the debugger:

editor.findWordAt === undefined // yields true
editor.wordAt === undefined // yields false

It seems to me detecting which one of those is available before invoking it would fix this obstacle that's preventing the use of this plugin.

olivierdagenais commented 2 years ago

Huh, someone else figured it out in #25, so this could be closed as a duplicate.

skq1998 commented 2 years ago

Huh, someone else figured it out in #25, so this could be closed as a duplicate.

Thanks! Following your tips, I have solved the problem.

ArianaKhit commented 2 years ago

Live Preview support added in 0.0.7. Be sure to check the toggle in settings and restart the plugin.