From 78a73cfd14c2c43473382b890886b68e6b2d174c Mon Sep 17 00:00:00 2001 From: Michael Hoffer Date: Fri, 5 Mar 2021 10:31:54 +0100 Subject: [PATCH] fix for #12 --- gradle/project-info.gradle | 2 +- src/main/java/eu/mihosoft/monacofx/Document.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gradle/project-info.gradle b/gradle/project-info.gradle index 73ede0d..5ec173c 100644 --- a/gradle/project-info.gradle +++ b/gradle/project-info.gradle @@ -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' diff --git a/src/main/java/eu/mihosoft/monacofx/Document.java b/src/main/java/eu/mihosoft/monacofx/Document.java index 9c4fa0f..e4f7d85 100644 --- a/src/main/java/eu/mihosoft/monacofx/Document.java +++ b/src/main/java/eu/mihosoft/monacofx/Document.java @@ -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; @@ -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); }