editor.setCursor() not working when cursor is in table in preview mode

In my plugin I have commands which also move the cursor to headings. The work fine except when the cursor is in a table cell and preview is activated. It also works fine when source mode is activated.
I guess that the table editor is kidnapping the cursor after execution of any command. :frowning:

1 Like

Can you provide a full code snippet of what you’re trying to do?

I also have come across this problem. This is what I’m trying to do, and it works, except when my initially selected text is inside a table cell in live preview.

 const selection = editor.getSelection();
  const linkTextString = `[[|${escLinkText(selection)}]]`;
  editor.replaceSelection(linkTextString);

  //now the cursor is at the end of the recently inserted text, find its position and convert it to an offset
  const updatedCursor = editor.getCursor();
  const updatedOffset = editor.posToOffset(updatedCursor);

  //subtract the replacement text's length from the current offset (and add two, to place the cursor just inside the link)
  const startOffset = updatedOffset - linkTextString.length + 2;
  //convert the offset back into a position
  const updatedPos = editor.offsetToPos(startOffset);

  //place the cursor in the place to type the link
  editor.setCursor(updatedPos);
1 Like