Skip to content

Commit 26b5610

Browse files
committed
Improve undo redo
1 parent 73ae662 commit 26b5610

File tree

11 files changed

+47
-46
lines changed

11 files changed

+47
-46
lines changed

libeditor/src/main/java/com/duy/ide/core/SimpleEditorActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,9 @@ public RecyclerView getTabRecyclerView() {
739739

740740
@CallSuper
741741
public void invalidateEditMenu(Document document, IEditAreaView mEditText) {
742-
setMenuStatus(R.id.action_save, document.isChanged() ? MenuDef.STATUS_NORMAL : MenuDef.STATUS_DISABLED);
743-
setMenuStatus(R.id.action_undo, mEditText != null && mEditText.canUndo() ? MenuDef.STATUS_NORMAL : MenuDef.STATUS_DISABLED);
744-
setMenuStatus(R.id.action_redo, mEditText != null && mEditText.canRedo() ? MenuDef.STATUS_NORMAL : MenuDef.STATUS_DISABLED);
742+
// setMenuStatus(R.id.action_save, document.isChanged() ? MenuDef.STATUS_NORMAL : MenuDef.STATUS_DISABLED);
743+
// setMenuStatus(R.id.action_undo, mEditText != null && mEditText.isCanUndo() ? MenuDef.STATUS_NORMAL : MenuDef.STATUS_DISABLED);
744+
// setMenuStatus(R.id.action_redo, mEditText != null && mEditText.isCanRedo() ? MenuDef.STATUS_NORMAL : MenuDef.STATUS_DISABLED);
745745
}
746746

747747

libeditor/src/main/java/com/duy/ide/editor/core/content/UndoManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616

1717
package com.duy.ide.editor.core.content;
1818

19-
import com.duy.ide.editor.content.IUndoManager;
20-
import com.duy.ide.editor.core.text.TextUtils;
2119
import android.os.Parcel;
2220
import android.os.Parcelable;
2321
import android.support.v4.util.ArrayMap;
2422

23+
import com.duy.ide.editor.content.IUndoManager;
24+
import com.duy.ide.editor.core.text.TextUtils;
25+
2526
import java.util.ArrayList;
2627

2728
/**

libeditor/src/main/java/com/duy/ide/editor/core/widget/EditAreaView.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import com.duy.ide.editor.core.text.Selection;
4040
import com.duy.ide.editor.core.text.method.ArrowKeyMovementMethod;
4141
import com.duy.ide.editor.core.text.method.MovementMethod;
42-
import com.duy.ide.editor.core.widget.model.EditorIndex;
42+
import com.duy.ide.editor.model.EditorIndex;
4343
import com.duy.ide.editor.view.IEditAreaView;
4444
import com.jecelyin.common.utils.LimitedQueue;
4545
import com.jecelyin.editor.v2.Preferences;
@@ -281,23 +281,23 @@ public void undo() {
281281
undoManager.undo();
282282
}
283283

284-
public boolean canRedo() {
284+
public boolean isCanRedo() {
285285
return undoManager.canRedo();
286286
}
287287

288-
public boolean canUndo() {
288+
public boolean isCanUndo() {
289289
return undoManager.canUndo();
290290
}
291291

292-
public boolean copy() {
292+
public boolean doCopy() {
293293
return canCopy() && onTextContextMenuItem(ID_COPY);
294294
}
295295

296-
public boolean paste() {
296+
public boolean doPaste() {
297297
return canPaste() && onTextContextMenuItem(ID_PASTE);
298298
}
299299

300-
public boolean cut() {
300+
public boolean doCut() {
301301
return canCut() && onTextContextMenuItem(ID_CUT);
302302
}
303303

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.duy.ide.editor.core.widget.model;
17+
package com.duy.ide.editor.model;
1818

1919
/**
2020
* Created by Duy on 30-Apr-18.

libeditor/src/main/java/com/duy/ide/editor/theme/ThemeLoader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.content.res.AssetManager;
55

6+
import com.duy.common.DLog;
67
import com.duy.ide.editor.theme.model.EditorTheme;
78

89
import org.apache.commons.io.IOUtils;
@@ -18,6 +19,7 @@ public class ThemeLoader {
1819
private static final String ASSET_PATH = "themes/vscode";
1920
private static final String DEFAULT_EDITOR_THEME_LIGHT = "github-light.json.properties";
2021
private static final HashMap<String, EditorTheme> CACHED = new HashMap<>();
22+
private static final String TAG = "ThemeLoader";
2123

2224
public static void init(Context context) {
2325
try {
@@ -74,13 +76,12 @@ private static EditorTheme loadFromAsset(AssetManager assets, String fileName) {
7476
editorTheme.setFileName(fileName);
7577
return editorTheme;
7678
} catch (IOException e) {
77-
e.printStackTrace();
79+
if (DLog.DEBUG) DLog.w(TAG, "loadFromAsset: Can not load theme " + fileName);
7880
}
7981

8082
return null;
8183
}
8284

83-
8485
private static EditorTheme loadTheme(Properties properties) {
8586
EditorTheme editorTheme = new EditorTheme();
8687
editorTheme.load(properties);

libeditor/src/main/java/com/duy/ide/editor/view/EditActionSupportEditor.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
import android.util.AttributeSet;
2626

2727
import com.duy.ide.editor.content.ClipboardCompat;
28-
import com.duy.ide.editor.core.content.UndoManager;
29-
import com.duy.ide.editor.core.widget.model.EditorIndex;
28+
import com.duy.ide.editor.content.IUndoManager;
29+
import com.duy.ide.editor.content.UndoManager;
30+
import com.duy.ide.editor.model.EditorIndex;
3031

3132
public class EditActionSupportEditor extends ZoomSupportEditor {
32-
private UndoManager mUndoManager;
33+
private IUndoManager mUndoManager;
3334
private ClipboardCompat mClipboard;
3435
private KeyListener mLastKeyListener;
3536

@@ -49,7 +50,7 @@ public EditActionSupportEditor(Context context, AttributeSet attrs, int defStyle
4950
}
5051

5152
private void init(Context context) {
52-
mUndoManager = new UndoManager();
53+
mUndoManager = new UndoManager(this);
5354
mClipboard = new ClipboardCompat(context);
5455
}
5556

@@ -61,17 +62,17 @@ public void undo() {
6162
mUndoManager.undo();
6263
}
6364

64-
public boolean canRedo() {
65+
public boolean isCanRedo() {
6566
return mUndoManager.canRedo();
6667
}
6768

6869
@Override
69-
public boolean canUndo() {
70+
public boolean isCanUndo() {
7071
return mUndoManager.canUndo();
7172
}
7273

7374
@Override
74-
public boolean copy() {
75+
public boolean doCopy() {
7576
if (!onTextContextMenuItem(android.R.id.copy)) {
7677
int selectionStart = getSelectionStart();
7778
int selectionEnd = getSelectionEnd();
@@ -88,7 +89,7 @@ public boolean copy() {
8889

8990
@Override
9091

91-
public boolean paste() {
92+
public boolean doPaste() {
9293
if (!onTextContextMenuItem(android.R.id.paste)) {
9394
CharSequence clipboard = mClipboard.getClipboard();
9495
if (clipboard != null) {
@@ -105,7 +106,7 @@ public boolean paste() {
105106

106107
@Override
107108

108-
public boolean cut() {
109+
public boolean doCut() {
109110
if (!onTextContextMenuItem(android.R.id.cut)) {
110111
int selectionStart = getSelectionStart();
111112
int selectionEnd = getSelectionEnd();

libeditor/src/main/java/com/duy/ide/editor/view/HighlightEditorView.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import android.graphics.Typeface;
2525
import android.support.annotation.NonNull;
2626
import android.support.annotation.Nullable;
27-
import android.support.v7.widget.AppCompatEditText;
2827
import android.text.InputFilter;
2928
import android.text.Layout;
3029
import android.text.Spanned;
@@ -46,7 +45,8 @@
4645
import java.lang.reflect.Field;
4746
import java.util.List;
4847

49-
public abstract class HighlightEditorView extends AppCompatEditText implements IEditAreaView, SharedPreferences.OnSharedPreferenceChangeListener {
48+
public abstract class HighlightEditorView extends android.support.v7.widget.AppCompatEditText
49+
implements IEditAreaView, SharedPreferences.OnSharedPreferenceChangeListener {
5050
private static final String TAG = "EditAreaView2";
5151
private final LayoutContext mLayoutContext = new LayoutContext();
5252
protected Preferences mPreferences;
@@ -344,11 +344,12 @@ private void updateTabChar() {
344344
float spaceWidth = getPaint().measureText(" ");
345345
float tabWidth = spaceWidth * (mPreferences == null ? 4 : mPreferences.getTabSize());
346346
try {
347-
Field tabIncrement = ReflectionUtil.getField(getLayout().getClass(), "TAB_INCREMENT", true);
347+
Field tabIncrement = ReflectionUtil.getField(getLayout().getClass(),
348+
"TAB_INCREMENT", true);
348349
ReflectionUtil.setFinalStatic(tabIncrement, (int) tabWidth);
349350
postInvalidate();
350351
} catch (Exception e) {
351-
e.printStackTrace();
352+
if (DLog.DEBUG) DLog.w(TAG, "updateTabChar: can not set tab width");
352353
}
353354
}
354355

@@ -375,7 +376,7 @@ private void updateGutterSize() {
375376
int newPaddingLeft = mLayoutContext.getGutterWidth() + gutterPaddingRight;
376377
setPadding(newPaddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom());
377378
}
378-
379+
379380
public int getMaxScrollY() {
380381
if (getLayout() == null)
381382
return 0;

libeditor/src/main/java/com/duy/ide/editor/view/IEditActionSupport.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717

1818
package com.duy.ide.editor.view;
1919

20-
interface IEditActionSupport {
20+
public interface IEditActionSupport {
2121
void undo();
2222

2323
void redo();
2424

25-
boolean canUndo();
25+
boolean isCanUndo();
2626

27-
boolean canRedo();
27+
boolean isCanRedo();
2828

29-
boolean cut();
29+
boolean doCut();
3030

31-
boolean copy();
31+
boolean doCopy();
3232

33-
boolean paste();
33+
boolean doPaste();
3434

3535
void selectAll();
3636

libeditor/src/main/java/com/duy/ide/editor/view/IdeEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.duy.ide.editor.view;
1919

20-
import com.duy.ide.editor.core.widget.model.EditorIndex;
20+
import com.duy.ide.editor.model.EditorIndex;
2121

2222
import com.duy.ide.editor.theme.model.EditorTheme;
2323

libeditor/src/main/java/com/duy/ide/editor/view/ZoomSupportEditor.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131

3232
import com.jecelyin.editor.v2.Preferences;
3333

34-
/**
35-
* @author Jecelyin Peng <jecelyin@gmail.com>
36-
*/
3734
public abstract class ZoomSupportEditor extends HighlightEditorView implements IEditAreaView {
3835
/**
3936
* Indicates that we are not in the middle of a touch gesture

0 commit comments

Comments
 (0)