Mercurial Hosting > luan
changeset 1910:bb58f0d24f22
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 16 Apr 2025 09:38:28 -0600 |
parents | 474f7ab2d1c2 |
children | cd4c11d7dc7e |
files | src/luan/modules/swing/UndoManagerLuan.java |
diffstat | 1 files changed, 12 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/swing/UndoManagerLuan.java Tue Apr 15 22:12:54 2025 -0600 +++ b/src/luan/modules/swing/UndoManagerLuan.java Wed Apr 16 09:38:28 2025 -0600 @@ -1,8 +1,6 @@ package luan.modules.swing; import java.util.WeakHashMap; -import java.util.List; -import java.util.ArrayList; import javax.swing.event.UndoableEditListener; import javax.swing.event.UndoableEditEvent; import javax.swing.undo.UndoManager; @@ -25,7 +23,8 @@ private final WeakHashMap<LuanFunction,Boolean> map = new WeakHashMap<LuanFunction,Boolean>(); private final Luan luan; private UndoableEdit unedited = null; - private final List<CompoundEdit> transactions = new ArrayList<CompoundEdit>(); + private CompoundEdit transaction; + private int transactionNesting = 0; public UndoManagerLuan(Luan luan) { this.luan = luan; @@ -42,12 +41,11 @@ } @Override public void undoableEditHappened(UndoableEditEvent event) { - int n = transactions.size(); - if( n == 0 ) { + if( transactionNesting == 0 ) { super.undoableEditHappened(event); notifyListeners(); } else { - if( !transactions.get(n-1).addEdit( event.getEdit() ) ) throw new RuntimeException(); + if( !transaction.addEdit( event.getEdit() ) ) throw new RuntimeException(); } } @@ -82,19 +80,18 @@ public void beginTransaction() { //logger.info("beginTransaction"); - transactions.add(new CompoundEdit()); + if( transactionNesting == 0 ) + transaction = new CompoundEdit(); + transactionNesting++; } public void endTransaction() { //logger.info("endTransaction"); - int n = transactions.size(); - CompoundEdit ce = transactions.remove(n-1); - ce.end(); - if( n == 1 ) { - if( !addEdit(ce) ) throw new RuntimeException(); - } else { - if( !transactions.get(n-2).addEdit(ce) ) throw new RuntimeException(); + transactionNesting--; + if( transactionNesting == 0 ) { + transaction.end(); + if( !addEdit(transaction) ) throw new RuntimeException(); + notifyListeners(); } - notifyListeners(); } }