text-snippets-obsidian icon indicating copy to clipboard operation
text-snippets-obsidian copied to clipboard

Will Snippets work in the new version of the editor?

Open skq1998 opened this issue 3 years ago • 5 comments

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

skq1998 avatar Jan 10 '22 14:01 skq1998

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

jonnyg23 avatar Jan 10 '22 17:01 jonnyg23

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 avatar Jan 12 '22 19:01 olivierdagenais

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

olivierdagenais avatar Jan 12 '22 19:01 olivierdagenais

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.

skq1998 avatar Jan 17 '22 10:01 skq1998

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

ArianaKhit avatar Mar 03 '22 11:03 ArianaKhit