Skip to content

Commit f001961

Browse files
committed
Fix contains \r in sample code
1 parent 9db2cee commit f001961

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

lib-n-ide/src/main/java/com/duy/ide/editor/theme/EditorThemeFragment.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ private void resolveLanguage() {
114114
mLanguage = Catalog.getModeByName("Pascal");
115115
}
116116
InputStream input = mContext.getAssets().open(fileName);
117-
mSampleCode = IOUtils.toString(input);
117+
mSampleCode = IOUtils.toString(input, "UTF-8");
118+
mSampleCode = mSampleCode.replace("\r\n", "\n");
119+
mSampleCode = mSampleCode.replace("\r", "\n");
118120
input.close();
119121
} catch (Exception e) {
120122
e.printStackTrace();
@@ -133,6 +135,7 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
133135
return new ViewHolder(view);
134136
}
135137

138+
@SuppressLint("UseSparseArrays")
136139
@Override
137140
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
138141
final EditorTheme editorTheme = mEditorThemes.get(position);
@@ -145,17 +148,22 @@ public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
145148
Highlighter highlighter = new Highlighter();
146149
editorView.setTheme(editorTheme);
147150

151+
String sampleData = getSampleData();
152+
148153
buffer.setMode(mLanguage, mContext);
149-
editorView.setText("");
150-
editorView.getText().insert(0, getSampleData());
154+
editorView.getEditableText().clearSpans();
155+
editorView.setText(sampleData);
151156

152157
buffer.setEditable(editorView.getText());
153-
buffer.insert(0, getSampleData());
154158

155-
@SuppressLint("UseSparseArrays")
156-
HashMap<Integer, ArrayList<? extends CharacterStyle>> colorsMap = new HashMap<>();
159+
buffer.insert(0, sampleData);
160+
157161
int lineCount = buffer.getLineManager().getLineCount();
158-
highlighter.highlight(buffer, editorTheme, colorsMap, editorView.getText(), 0, lineCount - 1);
162+
highlighter.highlight(buffer, editorTheme,
163+
new HashMap<Integer, ArrayList<? extends CharacterStyle>>(),
164+
editorView.getText(),
165+
0,
166+
lineCount - 1);
159167

160168
holder.mBtnSelect.setOnClickListener(new View.OnClickListener() {
161169
@Override
@@ -211,6 +219,7 @@ static class ViewHolder extends RecyclerView.ViewHolder {
211219

212220
ViewHolder(View itemView) {
213221
super(itemView);
222+
setIsRecyclable(false);
214223
mEditorView = itemView.findViewById(R.id.editor_view);
215224
mTxtName = itemView.findViewById(R.id.txt_name);
216225
mBtnSelect = itemView.findViewById(R.id.btn_select);

lib-n-ide/src/main/res/values-vi/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<string name="cursor_width">Chiều rộng con trỏ</string>
105105
<string name="editor">Soạn thảo</string>
106106
<string name="touch_to_adjust_text_size">Chạm để thay đổi kích thước văn bản</string>
107-
<string name="word_wrap_in_editor">Tự động ngắt dòng</string>
107+
<string name="word_wrap_in_editor">Ngắt dòng</string>
108108
<string name="show_linenumber">Hiển thị số dòng</string>
109109
<string name="show_whitespace">Hiển thị khoảng trắng</string>
110110
<string name="auto_indent">Tự động thụt lề</string>

lib-n-ide/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<string name="font_size">Font Size</string>
127127
<string name="cursor_width">Cursor Width</string>
128128
<string name="touch_to_adjust_text_size">Touch to change text size</string>
129-
<string name="word_wrap_in_editor">Auto wordwrap</string>
129+
<string name="word_wrap_in_editor">Wordwrap</string>
130130
<string name="show_linenumber">Show Linenumber</string>
131131
<string name="show_whitespace">Show Whitespace</string>
132132
<string name="auto_indent">Auto Indent</string>

lib-n-ide/src/main/res/xml/preference_editor.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
<CheckBoxPreference
1010
android:key="@string/pref_touch_to_adjust_text_size"
11+
android:summary="Change font size (Zoom) with two finger"
1112
android:title="@string/touch_to_adjust_text_size" />
1213

1314
<CheckBoxPreference
1415
android:key="@string/pref_word_wrap"
16+
android:summary="Use soft wrap in editor"
1517
android:title="@string/word_wrap_in_editor" />
1618

1719
<CheckBoxPreference
@@ -25,6 +27,7 @@
2527
<CheckBoxPreference
2628
android:key="@string/pref_auto_indent"
2729
android:title="@string/auto_indent" />
30+
2831
<CheckBoxPreference
2932
android:key="@string/pref_auto_pair"
3033
android:summary="@string/pref_desc_auto_pair"
@@ -44,6 +47,7 @@
4447

4548
<CheckBoxPreference
4649
android:key="@string/pref_auto_capitalize"
50+
android:summary="Not recommend"
4751
android:title="@string/auto_capitalize" />
4852

4953

@@ -52,11 +56,10 @@
5256
android:maxLines="7"
5357
android:negativeButtonText="@string/reset"
5458
android:scrollbars="vertical"
55-
android:summary=""
5659
android:title="@string/custom_symbol_list" />
5760

5861
<CheckBoxPreference
59-
android:id="@+id/pref_volume_move"
62+
android:key="@string/pref_volume_move"
6063
android:defaultValue="true"
6164
android:summary="Press volume up (+) to move cursor to right, press volume down (-) to move cursor to left"
6265
android:title="Volume move" />

0 commit comments

Comments
 (0)