Skip to content

Commit df7afde

Browse files
committed
improve UI show error, fix not change tab character in setting
1 parent 9da8492 commit df7afde

File tree

7 files changed

+39
-15
lines changed

7 files changed

+39
-15
lines changed

app/src/main/java/com/duy/pascal/frontend/autocomplete/autofix/AutoFixHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public void execute(EditorView editable) {
397397
Matcher matcher = Patterns.VAR.matcher(scope.getText());
398398
if (matcher.find()) {
399399
insertPosition = matcher.end();
400-
textToInsert = "\n" + AutoIndentEditText.TAB_CHARACTER + name + ": ";
400+
textToInsert = "\n" + editable.getTabCharacter() + name + ": ";
401401

402402
startSelect = textToInsert.length();
403403
endSelect = startSelect + type.length();
@@ -411,7 +411,7 @@ public void execute(EditorView editable) {
411411
} else if ((matcher = Patterns.PROGRAM.matcher(scope.getText())).find()) {
412412
insertPosition = matcher.end();
413413
}
414-
textToInsert = "\nvar\n" + AutoIndentEditText.TAB_CHARACTER + name + ": ";
414+
textToInsert = "\nvar\n" + editable.getTabCharacter() + name + ": ";
415415

416416
startSelect = textToInsert.length();
417417
endSelect = startSelect + type.length();

app/src/main/java/com/duy/pascal/frontend/autocomplete/autofix/dialog/ErrorAndQuickFixDialog.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public void onClick(View v) {
8484
});
8585

8686
if (exception instanceof ParsingException && ((ParsingException) exception).canQuickFix()) {
87+
view.findViewById(R.id.container_command).setVisibility(View.VISIBLE);
88+
8789
RecyclerView listCommand = view.findViewById(R.id.list_command);
8890
listCommand.setLayoutManager(new LinearLayoutManager(getActivity()));
8991
listCommand.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
@@ -97,7 +99,8 @@ public void onClick(AutoFixCommand command) {
9799
}
98100
});
99101

100-
view.findViewById(R.id.txt_hint).setVisibility(View.VISIBLE);
102+
} else {
103+
view.findViewById(R.id.container_command).setVisibility(View.GONE);
101104
}
102105
}
103106

app/src/main/java/com/duy/pascal/frontend/editor/EditorActivity.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.duy.pascal.frontend.autocomplete.completion.model.Description;
4848
import com.duy.pascal.frontend.code.CompileManager;
4949
import com.duy.pascal.frontend.code.sample.activities.DocumentActivity;
50-
import com.duy.pascal.frontend.editor.view.AutoIndentEditText;
5150
import com.duy.pascal.frontend.editor.view.EditorView;
5251
import com.duy.pascal.frontend.file.util.FileUtils;
5352
import com.duy.pascal.frontend.setting.PascalPreferences;
@@ -119,7 +118,21 @@ public void invalidateOptionsMenu() {
119118
}
120119

121120
private void insertTab(View v) {
122-
onKeyClick(v, AutoIndentEditText.TAB_CHARACTER);
121+
EditorFragment currentFragment = mPagerAdapter.getCurrentFragment();
122+
if (currentFragment != null) {
123+
currentFragment.exciteCommand(new AutoFixCommand() {
124+
@Override
125+
public void execute(EditorView editable) {
126+
editable.insert(editable.getTabCharacter());
127+
}
128+
129+
@NonNull
130+
@Override
131+
public CharSequence getTitle(Context context) {
132+
return null;
133+
}
134+
});
135+
}
123136
}
124137

125138
@Override

app/src/main/java/com/duy/pascal/frontend/editor/view/AutoIndentEditText.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
*/
3535

3636
public class AutoIndentEditText extends AppCompatEditText {
37-
public static final String TAB_CHARACTER = " ";
3837
public static final String CURSOR = "\u2622";
3938
private static final String TAG = "AutoIndentEditText";
39+
protected String mTabStr = " ";
4040
protected EditorSetting mEditorSetting;
4141
private TextWatcher mBracketWatcher = new TextWatcher() {
4242
private int start;
@@ -115,7 +115,7 @@ public void applyTabWidth() {
115115

116116
private void init(Context context) {
117117
mEditorSetting = new EditorSetting(context);
118-
118+
mTabStr = mEditorSetting.getTabCharacter();
119119
setFilters(new InputFilter[]{mInputFilter});
120120
addTextChangedListener(mBracketWatcher);
121121
}
@@ -219,7 +219,7 @@ else if (c == ')')
219219
indent += dest.subSequence(indexStart, indexEnd);
220220
}
221221
if (parenthesesCount < 0) {
222-
indent += TAB_CHARACTER;
222+
indent += mTabStr;
223223
}
224224
Log.d(TAG, "indentLine: " + dest.charAt(dend) + " " + dest.charAt(dstart));
225225

@@ -245,6 +245,6 @@ else if (c == ')')
245245
}
246246

247247
public String getTabCharacter() {
248-
return TAB_CHARACTER;
248+
return mTabStr;
249249
}
250250
}

app/src/main/java/com/duy/pascal/frontend/editor/view/UndoRedoSupportEditText.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,10 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
228228
} else {
229229
switch (keyCode) {
230230
case KeyEvent.KEYCODE_TAB:
231-
String textToInsert = TAB_CHARACTER;
232231
int start, end;
233232
start = Math.max(getSelectionStart(), 0);
234233
end = Math.max(getSelectionEnd(), 0);
235-
getText().replace(Math.min(start, end), Math.max(start, end),
236-
textToInsert, 0, textToInsert.length());
234+
getText().replace(Math.min(start, end), Math.max(start, end), mTabStr, 0, mTabStr.length());
237235
return true;
238236
default:
239237
try {

app/src/main/java/com/duy/pascal/frontend/setting/PascalPreferences.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,14 @@ public void setTheme(String name) {
346346
public boolean useAutoInsert() {
347347
return getBoolean(context.getString(R.string.key_auto_insert_bracket), false);
348348
}
349+
350+
public String getTabCharacter() {
351+
int tabWidth = getInt("key_pref_tab_width", 2);
352+
tabWidth = Math.min(6, Math.max(0, tabWidth));
353+
String res = "";
354+
for (int i = 0; i < tabWidth; i++) {
355+
res += " ";
356+
}
357+
return res;
358+
}
349359
}

app/src/main/res/layout/dialog_error.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
android:layout_height="match_parent"
4444
android:layout_marginBottom="8dp"
4545
android:layout_weight="1"
46-
android:paddingTop="8dp"
46+
android:gravity="center_vertical"
4747
android:text="@string/compile_error"
4848
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
4949

@@ -69,6 +69,7 @@
6969
</android.support.v7.widget.CardView>
7070

7171
<android.support.v7.widget.CardView
72+
android:id="@+id/container_command"
7273
android:layout_width="match_parent"
7374
android:layout_height="wrap_content"
7475
app:cardUseCompatPadding="true">
@@ -84,8 +85,7 @@
8485
android:layout_width="match_parent"
8586
android:layout_height="wrap_content"
8687
android:text="@string/some_suggestion"
87-
android:textColor="?colorAccent"
88-
android:visibility="gone" />
88+
android:textColor="?colorAccent" />
8989

9090
<android.support.v7.widget.RecyclerView
9191
android:id="@+id/list_command"

0 commit comments

Comments
 (0)