diff options
author | Neil <nyamatongwe@gmail.com> | 2024-01-02 10:25:50 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2024-01-02 10:25:50 +1100 |
commit | 57dfd337e97eadd7366b71545627d32a5325e0bb (patch) | |
tree | 685b268ac30521ef055e1f10493be88c13384ae2 | |
parent | ec0e53dc6711aeb827eccd65b6f0779aa841aad2 (diff) | |
download | scintilla-mirror-57dfd337e97eadd7366b71545627d32a5325e0bb.tar.gz |
Simplify choosing caret position when undoing contiguous deletions.
Stop considering container actions as they are supposed to be transparent. The
mayCoalesce flag is private to the undo code and may be removed in the future.
Use Range type to unify state implementing coalescing.
-rw-r--r-- | src/Document.cxx | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index aea2cfd0b..1a8c4020f 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1363,10 +1363,7 @@ Sci::Position Document::Undo() { bool multiLine = false; const int steps = cb.StartUndo(); //Platform::DebugPrintf("Steps=%d\n", steps); - Sci::Position coalescedRemovePos = -1; - Sci::Position coalescedRemoveLen = 0; - Sci::Position prevRemoveActionPos = -1; - Sci::Position prevRemoveActionLen = 0; + Range coalescedRemove; // Default is empty at 0 for (int step = 0; step < steps; step++) { const Sci::Line prevLinesTotal = LinesTotal(); const Action &action = cb.GetUndoStep(); @@ -1377,12 +1374,6 @@ Sci::Position Document::Undo() { DocModification dm(ModificationFlags::Container | ModificationFlags::Undo); dm.token = action.position; NotifyModified(dm); - if (!action.mayCoalesce) { - coalescedRemovePos = -1; - coalescedRemoveLen = 0; - prevRemoveActionPos = -1; - prevRemoveActionLen = 0; - } } else { NotifyModified(DocModification( ModificationFlags::BeforeDelete | ModificationFlags::Undo, action)); @@ -1398,22 +1389,15 @@ Sci::Position Document::Undo() { if (action.at == ActionType::remove) { newPos += action.lenData; modFlags |= ModificationFlags::InsertText; - if ((coalescedRemoveLen > 0) && - (action.position == prevRemoveActionPos || action.position == (prevRemoveActionPos + prevRemoveActionLen))) { - coalescedRemoveLen += action.lenData; - newPos = coalescedRemovePos + coalescedRemoveLen; + if (coalescedRemove.Contains(action.position)) { + coalescedRemove.end += action.lenData; + newPos = coalescedRemove.end; } else { - coalescedRemovePos = action.position; - coalescedRemoveLen = action.lenData; + coalescedRemove = Range(action.position, action.position + action.lenData); } - prevRemoveActionPos = action.position; - prevRemoveActionLen = action.lenData; } else if (action.at == ActionType::insert) { modFlags |= ModificationFlags::DeleteText; - coalescedRemovePos = -1; - coalescedRemoveLen = 0; - prevRemoveActionPos = -1; - prevRemoveActionLen = 0; + coalescedRemove = Range(); } if (steps > 1) modFlags |= ModificationFlags::MultiStepUndoRedo; |