Skip to content

Commit 73ae662

Browse files
committed
Undo redo support, fast scroll
1 parent d001902 commit 73ae662

24 files changed

+1691
-296
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929

3030
</LinearLayout>
3131

32-
<com.duy.ide.editor.view.HighlightEditorView
32+
<com.duy.ide.editor.view.EditActionSupportEditor
3333
android:id="@+id/editor_view"
3434
android:layout_width="match_parent"
3535
android:layout_height="wrap_content"
3636
android:typeface="monospace">
3737

38-
</com.duy.ide.editor.view.HighlightEditorView>
38+
</com.duy.ide.editor.view.EditActionSupportEditor>
3939
</LinearLayout>
4040

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2018 Duy Tran Le
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.duy.ide.editor.content;
19+
20+
import android.content.ClipData;
21+
import android.content.ClipboardManager;
22+
import android.content.Context;
23+
import android.support.annotation.NonNull;
24+
import android.support.annotation.Nullable;
25+
26+
public class ClipboardCompat {
27+
@NonNull
28+
private Context mContext;
29+
@Nullable
30+
private ClipboardManager mClipboardManager;
31+
32+
public ClipboardCompat(@NonNull Context context) {
33+
mContext = context;
34+
mClipboardManager = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
35+
}
36+
37+
@Nullable
38+
public CharSequence getClipboard() {
39+
if (mClipboardManager == null) {
40+
return null;
41+
}
42+
// Examines the item on the clipboard. If getText() does not return null,
43+
// the clip item contains the
44+
// text. Assumes that this application can only handle one item at a time.
45+
ClipData.Item item = mClipboardManager.getPrimaryClip().getItemAt(0);
46+
// Gets the clipboard as text.
47+
return item.getText();
48+
}
49+
50+
public void setClipboard(@NonNull CharSequence content) {
51+
ClipData clipData = ClipData.newPlainText("", content);
52+
if (mClipboardManager != null) {
53+
mClipboardManager.setPrimaryClip(clipData);
54+
}
55+
}
56+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2018 Duy Tran Le
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.duy.ide.editor.content;
19+
20+
/**
21+
* Created by Duy on 26-Apr-18.
22+
*/
23+
public interface IUndoManager {
24+
boolean canRedo();
25+
26+
void undo();
27+
28+
void redo();
29+
30+
boolean canUndo();
31+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2018 Duy Tran Le
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.duy.ide.editor.content;
19+
20+
import com.duy.ide.editor.view.IEditAreaView;
21+
22+
public class UndoManager implements IUndoManager {
23+
private UndoRedoHelper mUndoRedoHelper;
24+
25+
public UndoManager(IEditAreaView editText) {
26+
mUndoRedoHelper = new UndoRedoHelper(editText);
27+
}
28+
29+
@Override
30+
public boolean canRedo() {
31+
return mUndoRedoHelper.canRedo();
32+
}
33+
34+
@Override
35+
public void undo() {
36+
if (canUndo()) {
37+
mUndoRedoHelper.undo();
38+
}
39+
}
40+
41+
@Override
42+
public void redo() {
43+
if (canUndo()) {
44+
mUndoRedoHelper.redo();
45+
}
46+
}
47+
48+
@Override
49+
public boolean canUndo() {
50+
return mUndoRedoHelper.canRedo();
51+
}
52+
}

libeditor/src/main/java/com/duy/ide/editor/content/UndoRedoHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
import android.content.SharedPreferences;
77
import android.content.SharedPreferences.Editor;
8-
import com.duy.ide.editor.core.content.IUndoManager;
9-
import com.duy.ide.editor.core.widget.BaseEditorView;
108
import android.text.Editable;
119
import android.text.Selection;
1210
import android.text.TextUtils;
1311
import android.text.TextWatcher;
1412
import android.text.style.UnderlineSpan;
1513

14+
import com.duy.ide.editor.view.IEditAreaView;
15+
1616
import java.util.LinkedList;
1717

1818
public class UndoRedoHelper implements IUndoManager {
@@ -22,10 +22,10 @@ public class UndoRedoHelper implements IUndoManager {
2222
private EditHistory mEditHistory;
2323

2424
private EditTextChangeListener mChangeListener;
25-
private BaseEditorView mTextView;
25+
private IEditAreaView mTextView;
2626

2727

28-
public UndoRedoHelper(BaseEditorView textView) {
28+
public UndoRedoHelper(IEditAreaView textView) {
2929
mTextView = textView;
3030
mEditHistory = new EditHistory();
3131
mChangeListener = new EditTextChangeListener();

libeditor/src/main/java/com/duy/ide/editor/content/UndoRedoManager.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

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

19+
import com.duy.ide.editor.content.IUndoManager;
1920
import com.duy.ide.editor.core.text.TextUtils;
2021
import android.os.Parcel;
2122
import android.os.Parcelable;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) {
678678
if (mFastScroller != null && getLayout() != null) {
679679
int h = getBottom() - getTop() - getExtendedPaddingBottom() - getExtendedPaddingTop();
680680
int h2 = getLayout().getHeight();
681-
mFastScroller.onScroll(this, vert, h, h2);
681+
mFastScroller.onScroll(vert, h, h2);
682682
}
683683
}
684684

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
package com.duy.ide.editor.core.widget;
2020

21-
import com.duy.ide.editor.core.text.SpannableStringBuilder;
2221
import android.text.Editable;
2322

23+
import com.duy.ide.editor.core.text.SpannableStringBuilder;
2424
import com.duy.ide.editor.view.IEditAreaView;
2525

2626
/**
2727
* @author Jecelyin Peng <jecelyin@gmail.com>
2828
*/
29-
class EditorHelper {
29+
public class EditorHelper {
3030
private final IEditAreaView editAreaView;
3131

3232
public EditorHelper(IEditAreaView editAreaView) {

0 commit comments

Comments
 (0)