Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyCode on TextArea DoneEvent #3816

Merged
merged 9 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading