From 7b8888a93a71953622b204cec72c3f25130d5fa4 Mon Sep 17 00:00:00 2001 From: Shigeru KANEMOTO Date: Wed, 26 Oct 2011 02:42:02 +0900 Subject: [PATCH] Fix for full-width space bug. Imported from Processing development r6687 on http://code.google.com/p/processing Close #1 --- .../app/syntax/im/CompositionTextManager.java | 13 ++++++++++++- .../app/syntax/im/InputMethodSupport.java | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/syntax/im/CompositionTextManager.java b/app/src/processing/app/syntax/im/CompositionTextManager.java index 3c2bec063..ba9ee155f 100644 --- a/app/src/processing/app/syntax/im/CompositionTextManager.java +++ b/app/src/processing/app/syntax/im/CompositionTextManager.java @@ -54,6 +54,18 @@ public class CompositionTextManager { public boolean getIsInputProcess() { return isInputProcess; } + /** + * Insert full width space + */ + public void insertFullWidthSpace() { + initialCaretPosition = textArea.getCaretPosition(); + int layoutCaretPosition = initialCaretPosition; + try { + textArea.getDocument().insertString(layoutCaretPosition, "\u3000", null); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } /** * Called when a user begins input from input method. @@ -115,7 +127,6 @@ public class CompositionTextManager { * @param commited_count Numbers of committed characters in text. */ public void endCompositionText(AttributedCharacterIterator text, int committed_count) { - isInputProcess = false; /* * If there are no committed characters, remove it all from textarea. * This case will happen if a user delete all composing characters by backspace or delete key. diff --git a/app/src/processing/app/syntax/im/InputMethodSupport.java b/app/src/processing/app/syntax/im/InputMethodSupport.java index 33a86bb1a..461be3d16 100644 --- a/app/src/processing/app/syntax/im/InputMethodSupport.java +++ b/app/src/processing/app/syntax/im/InputMethodSupport.java @@ -73,6 +73,11 @@ public class InputMethodSupport implements InputMethodRequests, public void inputMethodTextChanged(InputMethodEvent event) { AttributedCharacterIterator text = event.getText(); committed_count = event.getCommittedCharacterCount(); + if(isFullWidthSpaceInput(text)){ + textManager.insertFullWidthSpace(); + caretPositionChanged(event); + return; + } if(isBeginInputProcess(text, textManager)){ textManager.beginCompositionText(text, committed_count); caretPositionChanged(event); @@ -86,11 +91,21 @@ public class InputMethodSupport implements InputMethodRequests, textManager.endCompositionText(text, committed_count); caretPositionChanged(event); } - + + private boolean isFullWidthSpaceInput(AttributedCharacterIterator text){ + if(text == null) + return false; + if(textManager.getIsInputProcess()) + return false; + return (String.valueOf(text.first()).equals("\u3000")); + } + private boolean isBeginInputProcess(AttributedCharacterIterator text, CompositionTextManager textManager){ if(text == null) return false; - return (isInputProcess(text) && !textManager.getIsInputProcess()); + if(textManager.getIsInputProcess()) + return false; + return (isInputProcess(text)); } private boolean isInputProcess(AttributedCharacterIterator text){