From a85ea04a276dcf1bf74ce011277d4928a62fd85d Mon Sep 17 00:00:00 2001 From: pesckal Date: Sun, 21 Aug 2011 03:13:52 +0000 Subject: [PATCH] Fixed bug that caused Comment/Uncomment to register as multiple undos --- app/src/processing/app/Editor.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 3cf373a48..bde69dbe7 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -230,7 +230,7 @@ public abstract class Editor extends JFrame implements RunnerListener { public void caretUpdate(CaretEvent e) { String newText = textarea.getText(); - if (lastText.equals(newText)) { + if (lastText.equals(newText) && isDirectEdit()) { endTextEditHistory(); } lastText = newText; @@ -1367,14 +1367,16 @@ public abstract class Editor extends JFrame implements RunnerListener { document.addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { - if (isInserting) + if (isInserting && isDirectEdit()) { endTextEditHistory(); + } isInserting = false; } public void insertUpdate(DocumentEvent e) { - if (!isInserting) + if (!isInserting && isDirectEdit()) { endTextEditHistory(); + } isInserting = true; } @@ -1420,6 +1422,14 @@ public abstract class Editor extends JFrame implements RunnerListener { redoAction.updateRedoState(); } + /** + * @return true if the text is being edited from direct input from typing and + * not shortcuts that manipulate text + */ + boolean isDirectEdit() { + return endUndoEvent != null; + } + void startTimerEvent() { endUndoEvent = new TimerTask() { public void run() {