text-snippets-obsidian
text-snippets-obsidian copied to clipboard
[BUG] Plugin doesn't work in obsidian version v0.13.14
- Running the snippet replacement gives an error in the console of
VM158:1 Uncaught ReferenceError: editor.findWordAt is not defined
- Fix
Replace editor.findWordAt
with editor.wordAt
and anchor / head
with from / to
Also using tab only or space doesn't work
I believe this is because the event isn't being registered, sinse when I console.log this.cmEditors
after running this.registerCodeMirror
I get an empty array
Thanks @Timber1900, I've applied a monkey patch in main.js to temporarly keep going and allowing the text snippet being replaced by pressing Ctrl+Tab.
@@ -97,12 +99,12 @@ class TextSnippets extends obsidian.Plugin {
getWordBoundaries(editor) {
var cursor = editor.getCursor();
var line = cursor.line;
- var word = editor.findWordAt({
+ var word = editor.wordAt({
line: line,
ch: cursor.ch
});
- var wordStart = word.anchor.ch;
- var wordEnd = word.head.ch;
+ var wordStart = word.from.ch;
+ var wordEnd = word.to.ch;
return {
start: {
line: line,
Nevertheless, I haven't been to fix the additional error TypeError: cm.getSearchCursor is not a function at TextSnippets.nextStop
which leaves strings like the stop symbol $tb$
inside the replaced content.
Hope the issue gets fixed completely
A new plugin user here. Snippet replacement doesn't run when the cursor is in the beginning or inside a non-empty string. Is this a related issue?
Clarification: I don't use Live Preview, as I use vim mode
Thanks @andrezgz, and getSearchCursor should be replaced by searchCursor
@@ -97,12 +97,12 @@ class TextSnippets extends obsidian.Plugin {
getWordBoundaries(editor) {
var cursor = editor.getCursor();
var line = cursor.line;
- var word = editor.findWordAt({
+ var word = editor.wordAt({
line: line,
ch: cursor.ch
});
- var wordStart = word.anchor.ch;
- var wordEnd = word.head.ch;
+ var wordStart = word.from.ch;
+ var wordEnd = word.to.ch;
return {
start: {
line: line,
@@ -240,7 +240,7 @@ class TextSnippets extends obsidian.Plugin {
if (cursorSt.ch >= 0 && cursorSt.line >= 0) { //paste text from clipboard
cm.getCursor();
navigator.clipboard.readText().then((clipText) => {
- var search = cm.getSearchCursor(this.settings.pasteSymbol, cursorSt);
+ var search = cm.searchCursor(this.settings.pasteSymbol, cursorSt);
if (search.findNext()) {
search.replace(clipText);
}
@@ -251,7 +251,7 @@ class TextSnippets extends obsidian.Plugin {
nextStop() {
let activeLeaf = this.app.workspace.activeLeaf;
let cm = activeLeaf.view.sourceMode.cmEditor;
- var search = cm.getSearchCursor(this.settings.stopSymbol, cm.getCursor());
+ var search = cm.searchCursor(this.settings.stopSymbol, cm.getCursor());
if (search.findNext()) {
search.replace("");
cm.setCursor(search.from());
getSearchCursor should be replaced by searchCursor
That great @into233, you've unlocked me! Now $tb$
symbol gets replaced but the cursor is not positioned right there.
There's a new error: TypeError: Cannot read property 'from' of undefined at TextSnippets.nextStop
if (search.findNext()) {
search.replace("");
cm.setCursor(search.from()); // <--- HERE
return true;
}
So, I've came with this additional change: search.from()
should be replaced with search.current().from
nextStop() {
let activeLeaf = this.app.workspace.activeLeaf;
let cm = activeLeaf.view.sourceMode.cmEditor;
- var search = cm.getSearchCursor(this.settings.stopSymbol, cm.getCursor());
+ var search = cm.searchCursor(this.settings.stopSymbol, cm.getCursor());
if (search.findNext()) {
search.replace("");
- cm.setCursor(search.from());
+ cm.setCursor(search.current().from);
return true;
}
And all of the sudden all my snippets are working again.
Maybe these group of diffs isn't a complete fix to give this plugin compatibility with CM6, but it's on track.
Difference between Code Mirror 5 and 6: https://codemirror.net/6/docs/migration/
Thank you for your assistance! Live Preview support added in 0.0.7. Be sure to check the toggle in settings and restart the plugin.
We found a temporary fix to the "Space and Tab not working" in issue #47 , if that can help anyone