Skip to content

Commit 80b69ea

Browse files
committed
Fix crash when using format
1 parent d9a8da7 commit 80b69ea

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

app/src/main/java/com/duy/ccppcompiler/ide/editor/CppIdeActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ public ArrayList<SuggestItem> getSuggestions(Editor editor) {
149149
ArrayList<SuggestItem> items = new ArrayList<>();
150150
int size = (int) (Math.random() * 10);
151151
for (int i = 0; i <= size; i++) {
152-
items.add(new DefaultSuggestItem("toString", "", "int", "s", 0));
152+
items.add(new DefaultSuggestItem("toString", "",
153+
"int", "s", 0));
153154
}
154155
return items;
155156
}

lib-n-ide/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ task copyReleaseToJavaNIDE << {
118118
File settingsFile = new File(javaIdeDir, "settings.gradle");
119119
String content = fileToString(settingsFile);
120120
//comment it
121-
content = content.replaceAll("include\\s+':${Pattern.quote(oldModuleName)}'", "//include ':${newModuleName}'");
121+
content = content.replaceAll("include\\s+':${Pattern.quote(oldModuleName)}'", "include ':${newModuleName}'");
122122
FileOutputStream output = new FileOutputStream(settingsFile);
123123
output.write(content.getBytes());
124124
output.close();

lib-n-ide/src/main/java/com/duy/ide/editor/task/FormatSourceTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected void onPostExecute(CharSequence formatted) {
7575
mProgressDialog.dismiss();
7676
if (formatted != null) {
7777
mEditText.setText(formatted);
78-
if (mEditText.length() <= mOldSelection) {
78+
if (mOldSelection <= mEditText.length()) {
7979
mEditText.setSelection(mOldSelection);
8080
}
8181
Toast.makeText(mContext, R.string.formated_source, Toast.LENGTH_SHORT).show();

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ private void showDropDownImpl() {
226226
mPopup.show();
227227
ListView list = mPopup.getListView();
228228
list.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
229-
list.setSelection(-1);
230229
}
231230

232231

@@ -253,6 +252,10 @@ public void setSuggestData(@NonNull List<SuggestItem> data) {
253252

254253
if (data.size() > 0) {
255254
showDropDown();
255+
} else {
256+
if (isPopupShowing()) {
257+
dismissDropDown();
258+
}
256259
}
257260
}
258261

@@ -428,18 +431,17 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
428431
if (isPopupShowing()) {
429432
//editor support press tab to insert tab character
430433
if (keyCode != KeyEvent.KEYCODE_TAB) {
431-
if (getSelectedItemPosition() >= 0) {
432-
switch (keyCode) {
433-
// if the list accepts the key events and the key event
434-
// was a click, the text view gets the selected item
435-
// from the drop down as its content
436-
case KeyEvent.KEYCODE_ENTER:
437-
case KeyEvent.KEYCODE_DPAD_CENTER:
438-
if (event.hasNoModifiers()) {
439-
performCompletion();
440-
}
441-
return true;
442-
}
434+
mPopup.onKeyUp(keyCode, event);
435+
switch (keyCode) {
436+
// if the list accepts the key events and the key event
437+
// was a click, the text view gets the selected item
438+
// from the drop down as its content
439+
case KeyEvent.KEYCODE_ENTER:
440+
case KeyEvent.KEYCODE_DPAD_CENTER:
441+
if (event.hasNoModifiers()) {
442+
performCompletion();
443+
}
444+
return true;
443445
}
444446
}
445447
}
@@ -461,7 +463,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
461463
}
462464

463465
//editor support press tab to insert tab character
464-
if (keyCode != KeyEvent.KEYCODE_TAB && mPopup.isShowing()) {
466+
if (keyCode != KeyEvent.KEYCODE_TAB) {
465467
if (mPopup.onKeyDown(keyCode, event)) {
466468
return true;
467469
}

0 commit comments

Comments
 (0)