Skip to content

Commit

Permalink
KeyCode on TextArea DoneEvent (#3816)
Browse files Browse the repository at this point in the history
Added the keycode that triggered the done event to the ActionEvent that is sent.
  • Loading branch information
ImmediandoSrl authored Jun 17, 2024
1 parent fd6752a commit 1bf72d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
9 changes: 6 additions & 3 deletions CodenameOne/src/com/codename1/ui/TextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -2197,17 +2197,20 @@ public ActionListener getDoneListener() {
* Fire the done event to done listener
*/
public void fireDoneEvent() {
fireDoneEvent(-1);
}
public void fireDoneEvent(final int keyEvent) {
if (doneListener != null) {
if (!Display.getInstance().isEdt()) {
Display.getInstance().callSerially(new Runnable() {

public void run() {
fireDoneEvent();
fireDoneEvent(keyEvent);
}
});
return;
}
doneListener.actionPerformed(new ActionEvent(this,ActionEvent.Type.Done));
doneListener.actionPerformed(new ActionEvent(this,ActionEvent.Type.Done,keyEvent));
}
}

Expand Down
24 changes: 16 additions & 8 deletions Ports/Android/src/com/codename1/impl/android/InPlaceEditView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1105,10 +1105,6 @@ private boolean editorContains(int x, int y) {
return mIsEditing && mEditText != null && mEditText.mTextArea != null && mEditText.mTextArea.contains(x, y);
}

private synchronized void endEditing(int reason, boolean forceVKBOpen, int actionCode) {
endEditing(reason, forceVKBOpen, false, actionCode);
}

private Component getNextComponent(Component curr) {
Form f = curr.getComponentForm();
if (f != null) {
Expand All @@ -1117,11 +1113,19 @@ private Component getNextComponent(Component curr) {
return null;
}

private synchronized void endEditing(int reason, boolean forceVKBOpen, int actionCode) {
endEditing(reason, forceVKBOpen, false, actionCode);
}

private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode) {
endEditing(reason, forceVKBOpen, false, actionCode, -1);
}

/**
* Finish the in-place editing of the given text area, release the edit lock, and allow the synchronous call
* to 'edit' to return.
*/
private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode) {
private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode, int keyEvent) {
//if (cursorTimer != null) {
// cursorTimer.cancel();
//}
Expand Down Expand Up @@ -1167,11 +1171,9 @@ private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean f
if (reason == REASON_IME_ACTION
&& ((TextArea) mEditText.mTextArea).getDoneListener() != null
&& (actionCode == EditorInfo.IME_ACTION_DONE)|| actionCode == EditorInfo.IME_ACTION_SEARCH || actionCode == EditorInfo.IME_ACTION_SEND || actionCode == EditorInfo.IME_ACTION_GO) {
((TextArea) mEditText.mTextArea).fireDoneEvent();

((TextArea) mEditText.mTextArea).fireDoneEvent(keyEvent);
}


// Call this in onComplete instead
//mIsEditing = false;
mLastEditText = mEditText;
Expand Down Expand Up @@ -2157,6 +2159,12 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
case KeyEvent.KEYCODE_MENU:
endEditing(InPlaceEditView.REASON_SYSTEM_KEY, false, true, 0);
break;
case KeyEvent.KEYCODE_ENTER:
onEditorAction(EditorInfo.IME_ACTION_DONE);
break;
case KeyEvent.KEYCODE_ESCAPE:
endEditing(InPlaceEditView.REASON_IME_ACTION, false, true, EditorInfo.IME_ACTION_DONE, keyCode);
break;
case KeyEvent.KEYCODE_TAB:
onEditorAction(EditorInfo.IME_ACTION_NEXT);
break;
Expand Down

0 comments on commit 1bf72d5

Please sign in to comment.