From 1cccf5165b891eb95c85932474bb872ab0fbe638 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 28 Jul 2024 09:48:13 +1000 Subject: Add SCI_GETUNDOSEQUENCE to determine whether an undo sequence is active and its nesting depth. --- src/CellBuffer.cxx | 4 ++++ src/CellBuffer.h | 1 + src/Document.cxx | 4 ++++ src/Document.h | 1 + src/Editor.cxx | 3 +++ src/UndoHistory.cxx | 4 ++++ src/UndoHistory.h | 1 + 7 files changed, 18 insertions(+) (limited to 'src') diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index b0b9d9c39..4985517e0 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -1070,6 +1070,10 @@ void CellBuffer::EndUndoAction() noexcept { uh->EndUndoAction(); } +int CellBuffer::UndoSequenceDepth() const noexcept { + return uh->UndoSequenceDepth(); +} + void CellBuffer::AddUndoAction(Sci::Position token, bool mayCoalesce) { bool startSequence = false; uh->AppendAction(ActionType::container, token, nullptr, 0, startSequence, mayCoalesce); diff --git a/src/CellBuffer.h b/src/CellBuffer.h index 3a72601a6..d5d9a0467 100644 --- a/src/CellBuffer.h +++ b/src/CellBuffer.h @@ -166,6 +166,7 @@ public: bool IsCollectingUndo() const noexcept; void BeginUndoAction(bool mayCoalesce=false) noexcept; void EndUndoAction() noexcept; + int UndoSequenceDepth() const noexcept; void AddUndoAction(Sci::Position token, bool mayCoalesce); void DeleteUndoHistory() noexcept; diff --git a/src/Document.cxx b/src/Document.cxx index 3ae8964ba..88b876ebd 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1543,6 +1543,10 @@ Sci::Position Document::Redo() { return newPos; } +int Document::UndoSequenceDepth() const noexcept { + return cb.UndoSequenceDepth(); +} + void Document::DelChar(Sci::Position pos) { DeleteChars(pos, LenChar(pos)); } diff --git a/src/Document.h b/src/Document.h index efb1ae6d6..fa1c3fe42 100644 --- a/src/Document.h +++ b/src/Document.h @@ -397,6 +397,7 @@ public: bool IsCollectingUndo() const noexcept { return cb.IsCollectingUndo(); } void BeginUndoAction(bool coalesceWithPrior=false) noexcept { cb.BeginUndoAction(coalesceWithPrior); } void EndUndoAction() noexcept { cb.EndUndoAction(); } + int UndoSequenceDepth() const noexcept; void AddUndoAction(Sci::Position token, bool mayCoalesce) { cb.AddUndoAction(token, mayCoalesce); } void SetSavePoint(); bool IsSavePoint() const noexcept { return cb.IsSavePoint(); } diff --git a/src/Editor.cxx b/src/Editor.cxx index 390c83898..0561b42f8 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -6636,6 +6636,9 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { pdoc->EndUndoAction(); return 0; + case Message::GetUndoSequence: + return pdoc->UndoSequenceDepth(); + case Message::GetUndoActions: return pdoc->UndoActions(); diff --git a/src/UndoHistory.cxx b/src/UndoHistory.cxx index c4b241103..c0d7ba5f2 100644 --- a/src/UndoHistory.cxx +++ b/src/UndoHistory.cxx @@ -350,6 +350,10 @@ void UndoHistory::EndUndoAction() noexcept { } } +int UndoHistory::UndoSequenceDepth() const noexcept { + return undoSequenceDepth; +} + void UndoHistory::DropUndoSequence() noexcept { undoSequenceDepth = 0; } diff --git a/src/UndoHistory.h b/src/UndoHistory.h index 8cde395ae..be639c541 100644 --- a/src/UndoHistory.h +++ b/src/UndoHistory.h @@ -101,6 +101,7 @@ public: void BeginUndoAction(bool mayCoalesce=false) noexcept; void EndUndoAction() noexcept; + int UndoSequenceDepth() const noexcept; void DropUndoSequence() noexcept; void DeleteUndoHistory() noexcept; -- cgit v1.2.3