shabegom / buttons

Buttons in Obsidian
The Unlicense
453 stars 47 forks source link

Error when pressed button #195

Closed adamalbu closed 5 months ago

adamalbu commented 7 months ago

I get an error whenever I press the button. Here is the code for the button:

type template
action templater.testReplace
templater true

Here is the template:

<%*

let linestart = 0

//get file content and replace checked boxes for unchecked
var noteContent = tp.file.content.replaceAll ("foo","bar");

//select all in note
let cmEditorAct = this.app.workspace.activeLeaf.view.editor;
cmEditorAct.setSelection({ line: 0, ch: 0 }, { line: 9999, ch: 9999 });

//replace content
tR = noteContent.split("<%*")[0];

%>

Whenever I press the button, this error appears in the console:

plugin:buttons:186 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'lineStart')
    at eval (plugin:buttons:186:34)

Here is the line where the error is:

.splice(position.lineStart, position.lineEnd - position.lineStart)
Makeshift commented 6 months ago

I'm also getting this error and it appears to be new, as my button was working fine before. Any ideas how to resolve it?

shabegom commented 5 months ago

Should be fixed. reopen if this is still a problem