mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Merge pull request #175 from nking07049925/fix_tab_switch_undo
Fix undo/redo when switching between tabs
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
package processing.app;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Stack;
|
||||
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
@@ -64,7 +65,15 @@ public class SketchCode {
|
||||
* Editor.undo will be set to this object when this code is the tab
|
||||
* that's currently the front.
|
||||
*/
|
||||
private UndoManager undo = new UndoManager();
|
||||
private final UndoManager undo = new UndoManager();
|
||||
|
||||
/**
|
||||
* Caret positions for this tab.
|
||||
* Editor.caretUndoStack and Editor.caretRedoStack will be set to these
|
||||
* when this code is the tab that's currently the front.
|
||||
*/
|
||||
private final Stack<Integer> caretUndoStack = new Stack<>();
|
||||
private final Stack<Integer> caretRedoStack = new Stack<>();
|
||||
|
||||
/** What was on top of the undo stack when last saved. */
|
||||
// private UndoableEdit lastEdit;
|
||||
@@ -238,6 +247,13 @@ public class SketchCode {
|
||||
return undo;
|
||||
}
|
||||
|
||||
public Stack<Integer> getCaretRedoStack() {
|
||||
return caretRedoStack;
|
||||
}
|
||||
|
||||
public Stack<Integer> getCaretUndoStack() {
|
||||
return caretUndoStack;
|
||||
}
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
@@ -138,8 +138,11 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
/** Menu Actions updated on the opening of the edit menu. */
|
||||
protected List<UpdatableAction> editMenuUpdatable = new ArrayList<>();
|
||||
|
||||
/** The currently selected tab's undo manager */
|
||||
/** The currently selected tab's undo manager and caret positions*/
|
||||
private UndoManager undo;
|
||||
// maintain caret position during undo operations
|
||||
private Stack<Integer> caretUndoStack = new Stack<>();
|
||||
private Stack<Integer> caretRedoStack = new Stack<>();
|
||||
// used internally for every edit. Groups hotkey-event text manipulations and
|
||||
// groups multi-character inputs into a single undos.
|
||||
private CompoundEdit compoundEdit;
|
||||
@@ -148,9 +151,6 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
private TimerTask endUndoEvent;
|
||||
// true if inserting text, false if removing text
|
||||
private boolean isInserting;
|
||||
// maintain caret position during undo operations
|
||||
private final Stack<Integer> caretUndoStack = new Stack<>();
|
||||
private final Stack<Integer> caretRedoStack = new Stack<>();
|
||||
|
||||
private FindReplace find;
|
||||
JMenu toolsMenu;
|
||||
@@ -1904,7 +1904,12 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
// textarea.requestFocus(); // get the caret blinking
|
||||
textarea.requestFocusInWindow(); // required for caret blinking
|
||||
|
||||
// end edits in the previous tab
|
||||
endTextEditHistory();
|
||||
// update the UndoManager and caret positions to the selected tab
|
||||
this.undo = code.getUndo();
|
||||
caretUndoStack = code.getCaretUndoStack();
|
||||
caretRedoStack = code.getCaretRedoStack();
|
||||
undoAction.updateUndoState();
|
||||
redoAction.updateRedoState();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user