mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
trying to simplify #4599
This commit is contained in:
@@ -1177,8 +1177,7 @@ public abstract class InputHandler extends KeyAdapter
|
||||
|
||||
/**
|
||||
* Called when input method support committed a character.
|
||||
* @param c The input character
|
||||
*/
|
||||
public void onCommittedFromInputMethodSupport(char c) {
|
||||
public void handleInputMethodCommit() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,13 +192,15 @@ public class JEditTextArea extends JComponent
|
||||
public InputMethodRequests getInputMethodRequests() {
|
||||
if (Preferences.getBoolean("editor.input_method_support")) {
|
||||
if (inputMethodSupport == null) {
|
||||
inputMethodSupport = new InputMethodSupport(this);
|
||||
inputMethodSupport = new InputMethodSupport(this, inputHandler);
|
||||
/*
|
||||
inputMethodSupport.setCallback(new InputMethodSupport.Callback() {
|
||||
@Override
|
||||
public void onCommitted(char c) {
|
||||
inputHandler.onCommittedFromInputMethodSupport(c);
|
||||
inputHandler.onInputMethodCommit(c);
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
return inputMethodSupport;
|
||||
}
|
||||
@@ -1379,14 +1381,14 @@ public class JEditTextArea extends JComponent
|
||||
/**
|
||||
* Replaces the selection with the specified text.
|
||||
* @param selectedText The replacement text for the selection
|
||||
* @param recordCompoundEdit Whether the replacement should be
|
||||
* @param recordCompoundEdit Whether the replacement should be
|
||||
* recorded as a compound edit
|
||||
*/
|
||||
public void setSelectedText(String selectedText, boolean recordCompoundEdit) {
|
||||
if (!editable) {
|
||||
throw new InternalError("Text component read only");
|
||||
}
|
||||
|
||||
|
||||
if (recordCompoundEdit) {
|
||||
document.beginCompoundEdit();
|
||||
}
|
||||
@@ -1477,7 +1479,7 @@ public class JEditTextArea extends JComponent
|
||||
// Don't overstrike if there is a selection
|
||||
if(!overwrite || selectionStart != selectionEnd)
|
||||
{
|
||||
// record the whole operation as a compound edit if
|
||||
// record the whole operation as a compound edit if
|
||||
// selected text is being replaced
|
||||
boolean isSelectAndReplaceOp = (selectionStart != selectionEnd);
|
||||
setSelectedText(str, isSelectAndReplaceOp);
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.text.AttributedString;
|
||||
import processing.app.Base;
|
||||
import processing.app.Messages;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.syntax.InputHandler;
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
import processing.app.syntax.TextAreaPainter;
|
||||
|
||||
@@ -38,29 +39,38 @@ import processing.app.syntax.TextAreaPainter;
|
||||
*/
|
||||
public class InputMethodSupport implements InputMethodRequests, InputMethodListener {
|
||||
|
||||
/*
|
||||
public interface Callback {
|
||||
public void onCommitted(char c);
|
||||
}
|
||||
|
||||
private Callback callback;
|
||||
*/
|
||||
|
||||
static private final Attribute[] CUSTOM_IM_ATTRIBUTES = {
|
||||
TextAttribute.INPUT_METHOD_HIGHLIGHT,
|
||||
};
|
||||
|
||||
private int committedCount = 0;
|
||||
private JEditTextArea textArea;
|
||||
private AttributedString composedTextString;
|
||||
private Callback callback;
|
||||
private InputHandler inputHandler;
|
||||
|
||||
public InputMethodSupport(JEditTextArea textArea) {
|
||||
private int committedCount = 0;
|
||||
private AttributedString composedTextString;
|
||||
|
||||
public InputMethodSupport(JEditTextArea textArea, InputHandler inputHandler) {
|
||||
this.textArea = textArea;
|
||||
this.textArea.enableInputMethods(true);
|
||||
this.textArea.addInputMethodListener(this);
|
||||
this.inputHandler = inputHandler;
|
||||
|
||||
textArea.enableInputMethods(true);
|
||||
textArea.addInputMethodListener(this);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void setCallback(Callback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -182,9 +192,7 @@ public class InputMethodSupport implements InputMethodRequests, InputMethodListe
|
||||
}
|
||||
// Insert this as a compound edit
|
||||
textArea.setSelectedText(new String(insertion), true);
|
||||
if (callback != null) {
|
||||
callback.onCommitted(c);
|
||||
}
|
||||
inputHandler.handleInputMethodCommit();
|
||||
|
||||
CompositionTextPainter compositionPainter = textArea.getPainter().getCompositionTextpainter();
|
||||
if (Base.DEBUG) {
|
||||
|
||||
@@ -335,9 +335,8 @@ public class JavaInputHandler extends PdeInputHandler {
|
||||
|
||||
|
||||
@Override
|
||||
public void onCommittedFromInputMethodSupport(char c) {
|
||||
Sketch sketch = editor.getSketch();
|
||||
sketch.setModified(true);
|
||||
public void handleInputMethodCommit() {
|
||||
editor.getSketch().setModified(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user