aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2024-02-16 09:52:43 +1100
committerNeil <nyamatongwe@gmail.com>2024-02-16 09:52:43 +1100
commitf39367fc4c7af72caef8e20b1e9b1a038e242b0a (patch)
treeb5f2fddf5ad5d2b79e72e93ebefa8cf8e7abe4d4 /src
parent1681b7fc9da6d455ab73a96816a47f6ba263017c (diff)
downloadscintilla-mirror-f39367fc4c7af72caef8e20b1e9b1a038e242b0a.tar.gz
Implement detach point access with SCI_SETUNDODETACH and SCI_GETUNDODETACH.
Write more documentation for undo history.
Diffstat (limited to 'src')
-rw-r--r--src/CellBuffer.cxx16
-rw-r--r--src/CellBuffer.h6
-rw-r--r--src/Document.cxx16
-rw-r--r--src/Document.h6
-rw-r--r--src/Editor.cxx15
-rw-r--r--src/UndoHistory.cxx12
-rw-r--r--src/UndoHistory.h4
7 files changed, 59 insertions, 16 deletions
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<int>(wParam));
+ case Message::SetUndoDetach:
+ pdoc->SetUndoDetach(static_cast<int>(wParam));
break;
- case Message::GetUndoCurrent:
- return pdoc->UndoCurrent();
+ case Message::GetUndoDetach:
+ return pdoc->UndoDetach();
case Message::SetUndoTentative:
pdoc->SetUndoTentative(static_cast<int>(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<int>(wParam));
+ break;
+
+ case Message::GetUndoCurrent:
+ return pdoc->UndoCurrent();
+
case Message::GetUndoActionType:
return pdoc->UndoActionType(static_cast<int>(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;