Fixed bug that caused Comment/Uncomment to register as multiple undos

This commit is contained in:
pesckal
2011-08-21 03:13:52 +00:00
parent ce06706f5f
commit a85ea04a27

View File

@@ -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() {