Skip to content

Commit f4ce14a

Browse files
committed
trying to simplify processing#4599
1 parent 28bddc2 commit f4ce14a

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

app/src/processing/app/syntax/InputHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,7 @@ public static int findWordEnd(String line, int pos, String noWordSep) {
11771177

11781178
/**
11791179
* Called when input method support committed a character.
1180-
* @param c The input character
11811180
*/
1182-
public void onCommittedFromInputMethodSupport(char c) {
1181+
public void handleInputMethodCommit() {
11831182
}
11841183
}

app/src/processing/app/syntax/JEditTextArea.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,15 @@ protected TextAreaPainter createPainter(final TextAreaDefaults defaults) {
192192
public InputMethodRequests getInputMethodRequests() {
193193
if (Preferences.getBoolean("editor.input_method_support")) {
194194
if (inputMethodSupport == null) {
195-
inputMethodSupport = new InputMethodSupport(this);
195+
inputMethodSupport = new InputMethodSupport(this, inputHandler);
196+
/*
196197
inputMethodSupport.setCallback(new InputMethodSupport.Callback() {
197198
@Override
198199
public void onCommitted(char c) {
199-
inputHandler.onCommittedFromInputMethodSupport(c);
200+
inputHandler.onInputMethodCommit(c);
200201
}
201202
});
203+
*/
202204
}
203205
return inputMethodSupport;
204206
}
@@ -1379,14 +1381,14 @@ public void setSelectedText(String selectedText) {
13791381
/**
13801382
* Replaces the selection with the specified text.
13811383
* @param selectedText The replacement text for the selection
1382-
* @param recordCompoundEdit Whether the replacement should be
1384+
* @param recordCompoundEdit Whether the replacement should be
13831385
* recorded as a compound edit
13841386
*/
13851387
public void setSelectedText(String selectedText, boolean recordCompoundEdit) {
13861388
if (!editable) {
13871389
throw new InternalError("Text component read only");
13881390
}
1389-
1391+
13901392
if (recordCompoundEdit) {
13911393
document.beginCompoundEdit();
13921394
}
@@ -1477,7 +1479,7 @@ public void overwriteSetSelectedText(String str)
14771479
// Don't overstrike if there is a selection
14781480
if(!overwrite || selectionStart != selectionEnd)
14791481
{
1480-
// record the whole operation as a compound edit if
1482+
// record the whole operation as a compound edit if
14811483
// selected text is being replaced
14821484
boolean isSelectAndReplaceOp = (selectionStart != selectionEnd);
14831485
setSelectedText(str, isSelectAndReplaceOp);

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import processing.app.Base;
2222
import processing.app.Messages;
2323
import processing.app.Preferences;
24+
import processing.app.syntax.InputHandler;
2425
import processing.app.syntax.JEditTextArea;
2526
import processing.app.syntax.TextAreaPainter;
2627

@@ -38,29 +39,38 @@
3839
*/
3940
public class InputMethodSupport implements InputMethodRequests, InputMethodListener {
4041

42+
/*
4143
public interface Callback {
4244
public void onCommitted(char c);
4345
}
4446
47+
private Callback callback;
48+
*/
49+
4550
static private final Attribute[] CUSTOM_IM_ATTRIBUTES = {
4651
TextAttribute.INPUT_METHOD_HIGHLIGHT,
4752
};
4853

49-
private int committedCount = 0;
5054
private JEditTextArea textArea;
55+
private InputHandler inputHandler;
56+
57+
private int committedCount = 0;
5158
private AttributedString composedTextString;
52-
private Callback callback;
5359

54-
public InputMethodSupport(JEditTextArea textArea) {
60+
public InputMethodSupport(JEditTextArea textArea, InputHandler inputHandler) {
5561
this.textArea = textArea;
56-
this.textArea.enableInputMethods(true);
57-
this.textArea.addInputMethodListener(this);
62+
this.inputHandler = inputHandler;
63+
64+
textArea.enableInputMethods(true);
65+
textArea.addInputMethodListener(this);
5866
}
5967

6068

69+
/*
6170
public void setCallback(Callback callback) {
6271
this.callback = callback;
6372
}
73+
*/
6474

6575

6676
/////////////////////////////////////////////////////////////////////////////
@@ -182,9 +192,7 @@ public void inputMethodTextChanged(InputMethodEvent event) {
182192
}
183193
// Insert this as a compound edit
184194
textArea.setSelectedText(new String(insertion), true);
185-
if (callback != null) {
186-
callback.onCommitted(c);
187-
}
195+
inputHandler.handleInputMethodCommit();
188196

189197
CompositionTextPainter compositionPainter = textArea.getPainter().getCompositionTextpainter();
190198
if (Base.DEBUG) {

java/src/processing/mode/java/JavaInputHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,8 @@ public boolean handleTyped(KeyEvent event) {
335335

336336

337337
@Override
338-
public void onCommittedFromInputMethodSupport(char c) {
339-
Sketch sketch = editor.getSketch();
340-
sketch.setModified(true);
338+
public void handleInputMethodCommit() {
339+
editor.getSketch().setModified(true);
341340
}
342341

343342

0 commit comments

Comments
 (0)