Getting offset for a typed char
I have two questions.
First one is how to get properly the offset of text caret. Currently I do by using an editor: `editor.caretModel.offset`
However, it does not work properly because I must use the mouse to start it working in the first place. In addition,
sometime the offset is calculated but given by col number 0 and real col number. Here is the full offset calculation:
val offset = editor.caretModel.offset
val lineColumn = StringUtil.offsetToLineColumn(file.text, offset) -> Maybe I am wrong here
val col = lineColumn.column
val line = lineColumn.line
Second question is right now I can get changes only via typing (TypedHandlerDelegate) or via deleting (BackSpaceDelegate). I need to find a way to get changes for enter and a way to get a deleted word if it was selected.
This thing gets more complicated when I need to recieve updates for buttons like `Delete` or shortcuts like `Ctrl + Backspace`, `Ctrl + V`, `Ctrl + X`, `Ctrl + Delete`, etc.. Maybe there is a collective, better, more efficient way to receive all these updates at once and their offsets?
Please sign in to leave a comment.
Please see Editor topics https://plugins.jetbrains.com/docs/intellij/editor-basics.html which cover all about columns/lineoffset and related topics.
For 2nd question, approach from https://plugins.jetbrains.com/docs/intellij/documents.html#how-do-i-get-notified-when-documents-change might work
Yann Cebron I've checked the functions of
FileDocumentManagerListener
and at best the edited file is reloaded once every save (but not once every change). Am I missing something? Is there a way to get a changed document every x amount of time? (And then export the offset of caret and stuff like that, as well as document text, etc...)EDIT: Maybe I should use EditorFactory.getEventMulticaster().addDocumentListener() but I rly don't understand how can I run a code `from nothing` to use these functions? Let's say I just want to print `change has been made` for every change, I need to link the code somehow to plugin.xml or something? And that's via listener or extension? If there is a proper example for this I'll be happy to receive it
Create a Project-level service and register listener from its constructor, see com.intellij.ide.bookmarks.BookmarkManager#BookmarkManager