Skip to content

Commit a99b1eb

Browse files
committed
fix not save edit history
1 parent 19c348c commit a99b1eb

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ public void run() {
130130

131131
onDocumentChanged();
132132
loaded = true;
133+
134+
String fileName = mDocument.getFile().getPath().replaceAll("[^A-Za-z0-9_]", "_");
135+
SharedPreferences historyData = mContext.getSharedPreferences(
136+
fileName, Context.MODE_PRIVATE);
137+
mEditText.restoreEditHistory(historyData);
133138
}
134139

135140
public Context getContext() {
@@ -168,7 +173,6 @@ public void onCreate(IEditAreaView editorView) {
168173
mContext = editorView.getContext();
169174
mEditText = editorView;
170175

171-
172176
mOrientation = mContext.getResources().getConfiguration().orientation;
173177

174178
TypedArray a = mContext.obtainStyledAttributes(new int[]{R.attr.findResultsKeyword});
@@ -194,24 +198,22 @@ public void onCreate(IEditAreaView editorView) {
194198
mEditText.addTextChangedListener(this);
195199
onDocumentChanged();
196200

197-
String fileName = mDocument.getFile().getPath().replaceAll("[^A-Za-z0-9_]", "_");
198-
SharedPreferences historyData = mContext.getSharedPreferences(
199-
fileName, Context.MODE_PRIVATE);
200-
mEditText.restoreEditHistory(historyData);
201+
201202
}
202203

203204
public void onDestroy() {
204205
if (mGenerateSuggestDataTask != null) {
205206
mGenerateSuggestDataTask.cancel(true);
206207
}
207-
208-
if (isChanged() && Preferences.getInstance(getContext()).isAutoSave()) {
209-
saveInBackground();
210-
}
211208
String fileName = mDocument.getFile().getPath().replaceAll("[^A-Za-z0-9_]", "_");
212209
SharedPreferences historyData = mContext.getSharedPreferences(
213210
fileName, Context.MODE_PRIVATE);
214211
mEditText.saveHistory(historyData);
212+
213+
if (isChanged() && Preferences.getInstance(getContext()).isAutoSave()) {
214+
saveInBackground();
215+
}
216+
215217
mEditText.removeTextChangedListener(mDocument);
216218
mEditText.removeTextChangedListener(this);
217219
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void enableUndoRedoFilter() {
154154

155155
@Override
156156
public void saveHistory(SharedPreferences preferences) {
157-
157+
mUndoManager.save(preferences);
158158
}
159159

160160
@Override

0 commit comments

Comments
 (0)