Menu

[Scripting] Use which function to move the cursor / caret to a specific position inside the note panel?

2016-07-27
2016-07-28
  • Robertonisola

    Robertonisola - 2016-07-27

    Hi everyone,

    I would like to know which API function can be used to move the cursor / caret to a specific position inside the note panel?

    (I have searched this forum, the Freeplane API website, and other resources... for 2 days but I haven't found the answer yet).

    Thank you very much.

    Roberto.

     
  • Volker Börchers

    Hi Roberto,

    the scripting API works almost completely on the data models and not on the GUI components built on top of them. That's why there are not many scripts dealing with GUI components.

    But I think that this should be enough to get you started:

    import org.freeplane.features.note.NoteController
    
    def pane = NoteController.controller?.noteViewerComponent?.editorPane
    
    if (pane && pane.isVisible()) {
        if (pane.document.length > 3) {
            pane.setCaretPosition(3)
        }
        else {
            c.statusInfo = "a nice note, but to short to place the cursor at this position"
        }
    }
    else {
        c.statusInfo = "note editor not visible"
    }
    

    pane has type JEditorPane.html.

    Volker

     
    • Robertonisola

      Robertonisola - 2016-07-28

      Hi Volker,

      I think I can proceed from this code snippet :)

      Thank you very much for your valuable help.

      Roberto.