mirror of
https://github.com/processing/processing4.git
synced 2026-02-02 21:29:17 +01:00
Simple attempt to fix #35
This commit is contained in:
@@ -125,6 +125,8 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
private Runnable exportHandler;
|
||||
private Runnable exportAppHandler;
|
||||
|
||||
private final Stack<Integer> caretUndoStack = new Stack<Integer>();
|
||||
private final Stack<Integer> caretRedoStack = new Stack<Integer>();
|
||||
|
||||
public Editor(Base ibase, String path, int[] location) {
|
||||
super("Processing");
|
||||
@@ -1109,6 +1111,13 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
final Integer caret = caretUndoStack.pop();
|
||||
caretRedoStack.push(caret);
|
||||
textarea.setCaretPosition(caret);
|
||||
textarea.scrollToCaret();
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
try {
|
||||
undo.undo();
|
||||
} catch (CannotUndoException ex) {
|
||||
@@ -1154,6 +1163,12 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
//System.out.println("Unable to redo: " + ex);
|
||||
//ex.printStackTrace();
|
||||
}
|
||||
try {
|
||||
final Integer caret = caretRedoStack.pop();
|
||||
caretUndoStack.push(caret);
|
||||
textarea.setCaretPosition(caret);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
updateRedoState();
|
||||
undoAction.updateUndoState();
|
||||
}
|
||||
@@ -1433,8 +1448,9 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
public void undoableEditHappened(UndoableEditEvent e) {
|
||||
if (compoundEdit != null) {
|
||||
compoundEdit.addEdit(e.getEdit());
|
||||
|
||||
} else if (undo != null) {
|
||||
caretUndoStack.push(textarea.getCaretPosition());
|
||||
caretRedoStack.clear();
|
||||
undo.addEdit(e.getEdit());
|
||||
undoAction.updateUndoState();
|
||||
redoAction.updateRedoState();
|
||||
|
||||
Reference in New Issue
Block a user