miho / MonacoFX

JavaFX editor node based on the powerful Monaco editor that drives VS Code
MIT License
78 stars 25 forks source link

Result of the document content is not updated #12

Closed chqu1012 closed 3 years ago

chqu1012 commented 3 years ago

After editing some text in monacofx, I tried to get the result of the document, but for some times, it doesn't represents the whole text by calling Document#getText(). I added a another method to get the text value and this seems to work

public class Document{
...
    public String getValue() {
         return (String) editor.call("getValue");
    }
}

In some case this method wasn't called.

 window.setMember("contentChangeListener", new JFunction( args -> {

            String text = (String) editor.call("getValue");
            if(text!=null) {
                setText(text);
                numberOfLinesProperty.setValue(text.split("\\R").length);
            }
            return null;
        }));
miho commented 3 years ago

It looks like this issue is caused by this https://www.hissenit.com/javafx-webview-webkit-fehler-javascript-java-kommunikation-java-8-frank-hissen-it-blog.html

We will keep a reference to the callback function. this should fix the issue.