Skip to content

Commit

Permalink
fix for #12
Browse files Browse the repository at this point in the history
  • Loading branch information
miho committed Mar 5, 2021
1 parent 577eeb3 commit 78a73cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle/project-info.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// -----------------------------------------------------------------------------
ext.publishing.artifactId = project.name.toLowerCase()
ext.publishing.groupId = 'eu.mihosoft.monacofx'
ext.publishing.versionId = '0.0.4'
ext.publishing.versionId = '0.0.5'

ext.publishing.developerName = 'Michael Hoffer'
ext.publishing.developerAlias = 'miho'
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/eu/mihosoft/monacofx/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class Document {
private final StringProperty languageProperty = new SimpleStringProperty();
private final IntegerProperty numberOfLinesProperty = new SimpleIntegerProperty();

private JFunction jsfListener;

void setEditor(WebEngine engine, JSObject window, JSObject editor) {
this.engine = engine;
this.editor = editor;
Expand All @@ -51,16 +53,18 @@ void setEditor(WebEngine engine, JSObject window, JSObject editor) {
editor.call("setValue", getText());
});

// text changes <- js
window.setMember("contentChangeListener", new JFunction( args -> {

// keep a global reference because it's garbage collected otherwise
jsfListener = new JFunction( args -> {
String text = (String) editor.call("getValue");
if(text!=null) {
setText(text);
numberOfLinesProperty.setValue(text.split("\\R").length);
}
return null;
}));
});

// text changes <- js
window.setMember("contentChangeListener", jsfListener);

}

Expand Down

0 comments on commit 78a73cf

Please sign in to comment.