Skip to content

Commit d9a8da7

Browse files
committed
improve handle key event
1 parent 8675c9c commit d9a8da7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib-n-ide/src/main/java/com/duy/ide/editor/view/SuggestionEditor.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ private void showDropDownImpl() {
226226
mPopup.show();
227227
ListView list = mPopup.getListView();
228228
list.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
229-
if (mAdapter.getCount() > 0) {
230-
list.setSelection(0);
231-
}
229+
list.setSelection(-1);
232230
}
233231

234232

@@ -474,7 +472,19 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
474472
}
475473
return handled;
476474
} else {
477-
return super.onKeyDown(keyCode, event);
475+
switch (keyCode) {
476+
//always return true because we need focus to editor
477+
case KeyEvent.KEYCODE_DPAD_UP:
478+
case KeyEvent.KEYCODE_DPAD_UP_LEFT:
479+
case KeyEvent.KEYCODE_DPAD_UP_RIGHT:
480+
case KeyEvent.KEYCODE_DPAD_DOWN:
481+
case KeyEvent.KEYCODE_DPAD_DOWN_LEFT:
482+
case KeyEvent.KEYCODE_DPAD_DOWN_RIGHT:
483+
super.onKeyDown(keyCode, event);
484+
return true;
485+
default:
486+
return super.onKeyDown(keyCode, event);
487+
}
478488
}
479489
}
480490

@@ -501,6 +511,7 @@ private void performCompletion(int position) {
501511

502512
if (!mPopup.isDropDownAlwaysVisible()) {
503513
dismissDropDown();
514+
requestFocus();
504515
}
505516
}
506517

0 commit comments

Comments
 (0)