From f39367fc4c7af72caef8e20b1e9b1a038e242b0a Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 16 Feb 2024 09:52:43 +1100 Subject: Implement detach point access with SCI_SETUNDODETACH and SCI_GETUNDODETACH. Write more documentation for undo history. --- src/CellBuffer.cxx | 16 ++++++++++++---- src/CellBuffer.h | 6 ++++-- src/Document.cxx | 16 ++++++++++++---- src/Document.h | 6 ++++-- src/Editor.cxx | 15 +++++++++++---- src/UndoHistory.cxx | 12 ++++++++++++ src/UndoHistory.h | 4 ++++ 7 files changed, 59 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 691a811dd..6dde7eb84 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -1160,12 +1160,12 @@ int CellBuffer::UndoSavePoint() const noexcept { return uh->SavePoint(); } -void CellBuffer::SetUndoCurrent(int action) { - uh->SetCurrent(action, Length()); +void CellBuffer::SetUndoDetach(int action) noexcept { + uh->SetDetachPoint(action); } -int CellBuffer::UndoCurrent() const noexcept { - return uh->Current(); +int CellBuffer::UndoDetach() const noexcept { + return uh->DetachPoint(); } void CellBuffer::SetUndoTentative(int action) noexcept { @@ -1176,6 +1176,14 @@ int CellBuffer::UndoTentative() const noexcept { return uh->TentativePoint(); } +void CellBuffer::SetUndoCurrent(int action) { + uh->SetCurrent(action, Length()); +} + +int CellBuffer::UndoCurrent() const noexcept { + return uh->Current(); +} + int CellBuffer::UndoActionType(int action) const noexcept { return uh->Type(action); } diff --git a/src/CellBuffer.h b/src/CellBuffer.h index 916937845..1c598480f 100644 --- a/src/CellBuffer.h +++ b/src/CellBuffer.h @@ -183,10 +183,12 @@ public: int UndoActions() const noexcept; void SetUndoSavePoint(int action) noexcept; int UndoSavePoint() const noexcept; - void SetUndoCurrent(int action); - int UndoCurrent() const noexcept; + void SetUndoDetach(int action) noexcept; + int UndoDetach() const noexcept; void SetUndoTentative(int action) noexcept; int UndoTentative() const noexcept; + void SetUndoCurrent(int action); + int UndoCurrent() const noexcept; int UndoActionType(int action) const noexcept; Sci::Position UndoActionPosition(int action) const noexcept; std::string_view UndoActionText(int action) const noexcept; diff --git a/src/Document.cxx b/src/Document.cxx index 8ab837daa..5f77ec2de 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -363,12 +363,12 @@ int Document::UndoSavePoint() const noexcept { return cb.UndoSavePoint(); } -void Document::SetUndoCurrent(int action) { - cb.SetUndoCurrent(action); +void Document::SetUndoDetach(int action) noexcept { + cb.SetUndoDetach(action); } -int Document::UndoCurrent() const noexcept { - return cb.UndoCurrent(); +int Document::UndoDetach() const noexcept { + return cb.UndoDetach(); } void Document::SetUndoTentative(int action) noexcept { @@ -379,6 +379,14 @@ int Document::UndoTentative() const noexcept { return cb.UndoTentative(); } +void Document::SetUndoCurrent(int action) { + cb.SetUndoCurrent(action); +} + +int Document::UndoCurrent() const noexcept { + return cb.UndoCurrent(); +} + int Document::UndoActionType(int action) const noexcept { return cb.UndoActionType(action); } diff --git a/src/Document.h b/src/Document.h index 66f954724..912c719b5 100644 --- a/src/Document.h +++ b/src/Document.h @@ -409,10 +409,12 @@ public: int UndoActions() const noexcept; void SetUndoSavePoint(int action) noexcept; int UndoSavePoint() const noexcept; - void SetUndoCurrent(int action); - int UndoCurrent() const noexcept; + void SetUndoDetach(int action) noexcept; + int UndoDetach() const noexcept; void SetUndoTentative(int action) noexcept; int UndoTentative() const noexcept; + void SetUndoCurrent(int action); + int UndoCurrent() const noexcept; int UndoActionType(int action) const noexcept; Sci::Position UndoActionPosition(int action) const noexcept; std::string_view UndoActionText(int action) const noexcept; diff --git a/src/Editor.cxx b/src/Editor.cxx index e6aec550a..343529510 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -6605,12 +6605,12 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::GetUndoSavePoint: return pdoc->UndoSavePoint(); - case Message::SetUndoCurrent: - pdoc->SetUndoCurrent(static_cast(wParam)); + case Message::SetUndoDetach: + pdoc->SetUndoDetach(static_cast(wParam)); break; - case Message::GetUndoCurrent: - return pdoc->UndoCurrent(); + case Message::GetUndoDetach: + return pdoc->UndoDetach(); case Message::SetUndoTentative: pdoc->SetUndoTentative(static_cast(wParam)); @@ -6619,6 +6619,13 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::GetUndoTentative: return pdoc->UndoTentative(); + case Message::SetUndoCurrent: + pdoc->SetUndoCurrent(static_cast(wParam)); + break; + + case Message::GetUndoCurrent: + return pdoc->UndoCurrent(); + case Message::GetUndoActionType: return pdoc->UndoActionType(static_cast(wParam)); diff --git a/src/UndoHistory.cxx b/src/UndoHistory.cxx index 62f871a60..810cd9a14 100644 --- a/src/UndoHistory.cxx +++ b/src/UndoHistory.cxx @@ -395,6 +395,18 @@ bool UndoHistory::AfterSavePoint() const noexcept { return (savePoint >= 0) && (savePoint <= currentAction); } +void UndoHistory::SetDetachPoint(int action) noexcept { + if (action == -1) { + detach = {}; + } else { + detach = action; + } +} + +int UndoHistory::DetachPoint() const noexcept { + return detach.value_or(-1); +} + bool UndoHistory::AfterDetachPoint() const noexcept { return detach && (*detach < currentAction); } diff --git a/src/UndoHistory.h b/src/UndoHistory.h index 13aaca98c..10660a195 100644 --- a/src/UndoHistory.h +++ b/src/UndoHistory.h @@ -110,6 +110,10 @@ public: bool BeforeOrAtSavePoint() const noexcept; bool BeforeReachableSavePoint() const noexcept; bool AfterSavePoint() const noexcept; + + /// The detach point is the last action that was before an inaccessible missing save point. + void SetDetachPoint(int action) noexcept; + [[nodiscard]] int DetachPoint() const noexcept; bool AfterDetachPoint() const noexcept; bool AfterOrAtDetachPoint() const noexcept; -- cgit v1.2.3