ahn / vaadin-aceeditor

Vaadin wrapper for Ace editor
Apache License 2.0
25 stars 37 forks source link

Caret positioning manipulation #38

Open zakhav opened 9 years ago

zakhav commented 9 years ago

Current our work with AceEditor when insert text programatically is following:

private void insertTextInCursorPosition(final String textPart) {
    int position = editor.getCursorPosition();
    StringBuilder text = new StringBuilder(editor.getDoc().getText());
    text.insert(position, textPart);
    editor.setDoc(new AceDoc(text.toString()));
    editor.setCursorPosition(position + textPart.length());
}

we have problem that on next invocations of this method text is inserted in wrong position.

Scenario of these steps works well on standard Vaadin TextField component which has same ancestor with AceEditor and almost same API (at least in terms of caret positioning, value set etc)

zakhav commented 9 years ago

detected in version 0.8.11. The problem also occurs in 0.8.13

ahn commented 9 years ago

I tried the insertTextInCursorPosition function and it seems to work as expected, at least in basic case. insertTextInCursorPosition("hello") adds the text hello to the cursor position. Also when calling it multiple times.

Can you tell how exactly does this fail for you?