Meta Bind insert text after at cursor

What I’m trying to do

Creating a button which paste a fixed text after the button or in the previous focused editor position

Things I have tried

In the Input example using the search popup text is inserted well, but not in the editor

```meta-bind-button
style: primary
label: Test Focus Commands
actions:
- type: command
  command: editor:focus
- type: sleep
  ms: 500
- type: input
  str: help me at cursor
```

Your problem indeed seems to be the focus of the editor. As soon as you press the button, it is the focused element. Nothing saves the previous position of the cursor. I’m not even sure you can do what you want to do with just a Meta Bind button.

If you want to simply put fixed text after the button itself, though, I can see three solutions for you:

1. The button is at a fixed line

If you are sure the text before the button in the note won’t be modified (which is a pretty strong assumption, I agree), you can use an insertIntoNote action instead of input.

style: primary
label: Test Focus Commands
actions:
- type: insertIntoNote
  line: 9
  value: "My value"

2. Have some placeholder Obsidian comment to replace

Find where to add the text by replacing a comment (which won’t be visible to the user, but will be to the plugin) using a regexpReplaceInNote action.

```meta-bind-button
style: primary
label: Test Focus Commands
action:
  type: "regexpReplaceInNote"
  regexp: "^%%Replace me%%$"
  regexpFlags: "gm"
  replacement: "%%Replace me%%\nHi there"
```
%%Replace me%%

3. Use a script

Write a custom JavaScript file that somehow finds where to add the text and adds it. This is more customizable but requires more work, of course.

Then use a js action for the button.

Hope this helps !

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.