From 917ddef60315c44b79852942a7368b39a98a9213 Mon Sep 17 00:00:00 2001 From: CaptainDaVinci Date: Fri, 8 Mar 2019 19:59:39 +0530 Subject: [PATCH] Adding support for input methods Fixes #4474 --- .../org/jabref/gui/entryeditor/SourceTab.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java index 397e3abd921..89f97ffbf2e 100644 --- a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java @@ -11,7 +11,9 @@ import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.ListChangeListener; +import javafx.geometry.Point2D; import javafx.scene.control.Tooltip; +import javafx.scene.input.InputMethodRequests; import org.jabref.gui.DialogService; import org.jabref.gui.icon.IconTheme; @@ -77,9 +79,42 @@ private static String getSourceString(BibEntry entry, BibDatabaseMode type, Late return stringWriter.getBuffer().toString(); } + /* Work around for different input methods. + * https://github.com/FXMisc/RichTextFX/issues/146 + */ + private class InputMethodRequestsObject implements InputMethodRequests { + + @Override + public String getSelectedText() { + return ""; + } + + @Override + public int getLocationOffset(int x, int y) { + return 0; + } + + @Override + public void cancelLatestCommittedText() { + return; + } + + @Override + public Point2D getTextLocation(int offset) { + return new Point2D(0, 0); + } + } + private CodeArea createSourceEditor() { CodeArea codeArea = new CodeArea(); codeArea.setWrapText(true); + codeArea.setInputMethodRequests(new InputMethodRequestsObject()); + codeArea.setOnInputMethodTextChanged(event -> { + String committed = event.getCommitted(); + if (!committed.isEmpty()) { + codeArea.insertText(codeArea.getCaretPosition(), committed); + } + }); return codeArea; }