plugins icon indicating copy to clipboard operation
plugins copied to clipboard

🧩 logseq.Editor.insertAtEditingCursor

Open utterances-bot opened this issue 1 year ago • 2 comments

https://plugins-doc.logseq.com/logseq/Editor/insertAtEditingCursor

utterances-bot avatar Apr 27 '24 19:04 utterances-bot

Is there a command to insert around editing cursor? Eg. I want smth like

insertAroundEditingCursor('[[', ']]')

so that I can create a shortcut for "insert a page reference"

neongreen avatar Apr 27 '24 19:04 neongreen

@neongreen

Is there a command to insert around editing cursor? Eg. I want smth like

insertAroundEditingCursor('[[', ']]')

so that I can create a shortcut for "insert a page reference"

Several steps are required. The "pos" accept the position of the letter. https://logseq.github.io/plugins/types/BlockCursorPosition.html Thus, the following process is possible.

const blockEntity = await logseq.Editor.getCurrentBlock()
if(blockEntity){
  const blockPos = await logseq.Editor.getEditingCursorPosition()
  if(blockPos){
    await logseq.Editor.insertAtEditingCursor("[[]]")
    setTimeout(() => { 
      await logseq.Editor.editBlock(blockEntity.uuid, { pos: blockPos.pos+2 })
    }, 200)
  }
}

I have never done anything similar so I am guessing. This is a TypeScript expression. (Sorry, I forgot how to write JavaScript)

YU000jp avatar Jun 22 '24 23:06 YU000jp