Tiptap: How do I get the cursor position?

Created on 19 Jun 2019  路  4Comments  路  Source: ueberdosis/tiptap

Sorry for the poor English.
Thanks for using tiptap.

Ask about the position of the cursor on the tip tap editor.
(I'm sorry if it was the question of "prosemirror")

  • the purpose
    I want to track the cursor position on the editor in real time.
    I want to use the handleKeyDown event to get the cursor position when I enter some characters.

  • Question
    The current cursor position was found by referring to "editor.view.state.selection. $ Anchor.pos".
    However, if you press the arrow keys, the position information will appear to point to the previous position.(The same is true for Backspace.)
    In this case, how can I get the correct cursor position information?

I am very happy if you can give me your advice.
Thank you.

bug

Most helpful comment

@Dangary-pleiades This should work:

new Editor({
  onTransaction: ({ state }) => {
    console.log(state.selection.anchor)
  },
})

All 4 comments

Thank you for your reply!

I saw the contents of that thread.
The ultimate goal was the same.

However, I did not know how to get the correct cursor position ...
What is the tip for getting the cursor position of the user who is operating the editor?

(Should I ask questions in that thread?)

@Dangary-pleiades This should work:

new Editor({
  onTransaction: ({ state }) => {
    console.log(state.selection.anchor)
  },
})

Thank you!
It worked as expected.

Thank you both!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asseti6 picture asseti6  路  3Comments

jetacpp picture jetacpp  路  3Comments

ageeye-cn picture ageeye-cn  路  3Comments

git-mischa picture git-mischa  路  3Comments

klaasgeldof picture klaasgeldof  路  3Comments