Skip to content

Commit 07ebbda

Browse files
Shigeru KANEMOTOShigeru KANEMOTO
Shigeru KANEMOTO
authored and
Shigeru KANEMOTO
committed
Fix for full-width space bug.
Imported from Processing development r6687 on http://code.google.com/p/processing Close arduino#1
1 parent 2068d12 commit 07ebbda

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

app/src/processing/app/syntax/im/CompositionTextManager.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ public CompositionTextManager(JEditTextArea textArea) {
5454
public boolean getIsInputProcess() {
5555
return isInputProcess;
5656
}
57+
/**
58+
* Insert full width space
59+
*/
60+
public void insertFullWidthSpace() {
61+
initialCaretPosition = textArea.getCaretPosition();
62+
int layoutCaretPosition = initialCaretPosition;
63+
try {
64+
textArea.getDocument().insertString(layoutCaretPosition, "\u3000", null);
65+
} catch (BadLocationException e) {
66+
e.printStackTrace();
67+
}
68+
}
5769

5870
/**
5971
* Called when a user begins input from input method.
@@ -115,7 +127,6 @@ private boolean canRemovePreviousInput(int committed_count){
115127
* @param commited_count Numbers of committed characters in text.
116128
*/
117129
public void endCompositionText(AttributedCharacterIterator text, int committed_count) {
118-
isInputProcess = false;
119130
/*
120131
* If there are no committed characters, remove it all from textarea.
121132
* This case will happen if a user delete all composing characters by backspace or delete key.

app/src/processing/app/syntax/im/InputMethodSupport.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public AttributedCharacterIterator getSelectedText(
7373
public void inputMethodTextChanged(InputMethodEvent event) {
7474
AttributedCharacterIterator text = event.getText();
7575
committed_count = event.getCommittedCharacterCount();
76+
if(isFullWidthSpaceInput(text)){
77+
textManager.insertFullWidthSpace();
78+
caretPositionChanged(event);
79+
return;
80+
}
7681
if(isBeginInputProcess(text, textManager)){
7782
textManager.beginCompositionText(text, committed_count);
7883
caretPositionChanged(event);
@@ -86,11 +91,21 @@ public void inputMethodTextChanged(InputMethodEvent event) {
8691
textManager.endCompositionText(text, committed_count);
8792
caretPositionChanged(event);
8893
}
89-
94+
95+
private boolean isFullWidthSpaceInput(AttributedCharacterIterator text){
96+
if(text == null)
97+
return false;
98+
if(textManager.getIsInputProcess())
99+
return false;
100+
return (String.valueOf(text.first()).equals("\u3000"));
101+
}
102+
90103
private boolean isBeginInputProcess(AttributedCharacterIterator text, CompositionTextManager textManager){
91104
if(text == null)
92105
return false;
93-
return (isInputProcess(text) && !textManager.getIsInputProcess());
106+
if(textManager.getIsInputProcess())
107+
return false;
108+
return (isInputProcess(text));
94109
}
95110

96111
private boolean isInputProcess(AttributedCharacterIterator text){

0 commit comments

Comments
 (0)