aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Document.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2025-01-22 21:34:54 +1100
committerNeil <nyamatongwe@gmail.com>2025-01-22 21:34:54 +1100
commit3de9d37c7b8f4501558d309ada718dc52533e94c (patch)
treece87afaff43a86c26c562fefcf0c9a5ea409ef6b /src/Document.cxx
parentbac32d7fde0b1d052ac9e926c6b3c96afe39bcfd (diff)
downloadscintilla-mirror-3de9d37c7b8f4501558d309ada718dc52533e94c.tar.gz
Bug [#1224]. Remember selection in undo history. SCI_SETSELECTIONUNDOHISTORY.
Diffstat (limited to 'src/Document.cxx')
-rw-r--r--src/Document.cxx48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index ac398fcd3..379a88786 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -18,6 +18,7 @@
#include <string_view>
#include <vector>
#include <array>
+#include <map>
#include <forward_list>
#include <optional>
#include <algorithm>
@@ -1320,6 +1321,10 @@ bool Document::DeleteChars(Sci::Position pos, Sci::Position len) {
} else {
enteredModification++;
if (!cb.IsReadOnly()) {
+ if (cb.IsCollectingUndo() && cb.CanRedo()) {
+ // Abandoning some undo actions so truncate any later selections
+ TruncateUndoComments(cb.UndoCurrent());
+ }
NotifyModified(
DocModification(
ModificationFlags::BeforeDelete | ModificationFlags::User,
@@ -1373,6 +1378,10 @@ Sci::Position Document::InsertString(Sci::Position position, const char *s, Sci:
s = insertion.c_str();
insertLength = insertion.length();
}
+ if (cb.IsCollectingUndo() && cb.CanRedo()) {
+ // Abandoning some undo actions so truncate any later selections
+ TruncateUndoComments(cb.UndoCurrent());
+ }
NotifyModified(
DocModification(
ModificationFlags::BeforeInsert | ModificationFlags::User,
@@ -1556,6 +1565,20 @@ Sci::Position Document::Redo() {
return newPos;
}
+void Document::EndUndoAction() noexcept {
+ cb.EndUndoAction();
+ if (UndoSequenceDepth() == 0) {
+ // Broadcast notification to views to allow end of group processing.
+ // NotifyGroupCompleted may throw (for memory exhaustion) but this method
+ // may not as it is called in UndoGroup destructor so ignore exception.
+ try {
+ NotifyGroupCompleted();
+ } catch (...) {
+ // Ignore any exception
+ }
+ }
+}
+
int Document::UndoSequenceDepth() const noexcept {
return cb.UndoSequenceDepth();
}
@@ -2504,6 +2527,25 @@ void Document::SetLexInterface(std::unique_ptr<LexInterface> pLexInterface) noex
pli = std::move(pLexInterface);
}
+void Document::SetViewState(void *view, ViewStateShared pVSS) {
+ viewData[view] = pVSS;
+}
+
+ViewStateShared Document::GetViewState(void *view) const noexcept {
+ const std::map<void *, ViewStateShared>::const_iterator it = viewData.find(view);
+
+ if (it != viewData.end()) {
+ return it->second;
+ }
+ return {};
+}
+
+void Document::TruncateUndoComments(int action) {
+ for (auto &[key, value] : viewData) {
+ value->TruncateUndo(action);
+ }
+}
+
int SCI_METHOD Document::SetLineState(Sci_Position line, int state) {
const int statePrevious = States()->SetLineState(line, state, LinesTotal());
if (state != statePrevious) {
@@ -2700,6 +2742,12 @@ void Document::NotifySavePoint(bool atSavePoint) {
}
}
+void Document::NotifyGroupCompleted() noexcept {
+ for (const WatcherWithUserData &watcher : watchers) {
+ watcher.watcher->NotifyGroupCompleted(this, watcher.userData);
+ }
+}
+
void Document::NotifyModified(DocModification mh) {
if (FlagSet(mh.modificationType, ModificationFlags::InsertText)) {
decorations->InsertSpace(mh.position, mh.length);