From f2bc1988dba5ca23692020017aa6f9ee2b4d71cf Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 25 Jan 2025 08:40:06 +1100 Subject: Bug [#1224]. Use enum for undo selection history and make API names more consistent as 'undo selection' instead of 'selection undo' as more closely associated with undo than selection. --- call/ScintillaCall.cxx | 8 ++++---- doc/ScintillaDoc.html | 33 +++++++++++++++++++++++++++------ doc/ScintillaHistory.html | 2 +- include/Scintilla.h | 6 ++++-- include/Scintilla.iface | 12 ++++++++---- include/ScintillaCall.h | 4 ++-- include/ScintillaMessages.h | 4 ++-- include/ScintillaTypes.h | 5 +++++ src/EditModel.cxx | 2 +- src/EditModel.h | 2 +- src/Editor.cxx | 13 +++++++------ 11 files changed, 62 insertions(+), 29 deletions(-) diff --git a/call/ScintillaCall.cxx b/call/ScintillaCall.cxx index 32855b9be..550adc710 100644 --- a/call/ScintillaCall.cxx +++ b/call/ScintillaCall.cxx @@ -1259,12 +1259,12 @@ ChangeHistoryOption ScintillaCall::ChangeHistory() { return static_cast(Call(Message::GetChangeHistory)); } -void ScintillaCall::SetSelectionUndoHistory(bool selectionUndoHistory) { - Call(Message::SetSelectionUndoHistory, selectionUndoHistory); +void ScintillaCall::SetUndoSelectionHistory(Scintilla::UndoSelectionHistoryOption undoSelectionHistory) { + Call(Message::SetUndoSelectionHistory, static_cast(undoSelectionHistory)); } -bool ScintillaCall::SelectionUndoHistory() { - return Call(Message::GetSelectionUndoHistory); +UndoSelectionHistoryOption ScintillaCall::UndoSelectionHistory() { + return static_cast(Call(Message::GetUndoSelectionHistory)); } Line ScintillaCall::FirstVisibleLine() { diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 44df71562..3bc5acd90 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -1938,8 +1938,8 @@ struct Sci_TextToFindFull { SCI_ENDUNDOACTION
SCI_GETUNDOSEQUENCE → int
SCI_ADDUNDOACTION(int token, int flags)
- SCI_SETSELECTIONUNDOHISTORY(bool selectionUndoHistory)
- SCI_GETSELECTIONUNDOHISTORY → bool
+ SCI_SETUNDOSELECTIONHISTORY(int undoSelectionHistory)
+ SCI_GETUNDOSELECTIONHISTORY → int

SCI_UNDO
@@ -2018,14 +2018,35 @@ struct Sci_TextToFindFull { look like typing or deletions that look like multiple uses of the Backspace or Delete keys.

-

SCI_SETSELECTIONUNDOHISTORY(bool selectionUndoHistory)
- SCI_GETSELECTIONUNDOHISTORY → bool
+

SCI_SETUNDOSELECTIONHISTORY(int undoSelectionHistory)
+ SCI_GETUNDOSELECTIONHISTORY → int
The selection for each action can be saved and then restored when undo or redo is performed. - SCI_SETSELECTIONUNDOHISTORY controls this. - The current bool argument may change to a set of flags. + SCI_SETUNDOSELECTIONHISTORY controls this. There is a memory cost for this feature with a minimum of 150 bytes for each of undo and redo for each recorded action. Recording may be turned on at any time.

+

The undoSelectionHistory argument can be:

+ + + + + + + + + + + + + + + + + + + +
SC_UNDO_SELECTION_HISTORY_DISABLED0The default: undo selection history turned off.
SC_UNDO_SELECTION_HISTORY_ENABLED1Restore selection for each undo and redo.
+

Undo Save and Restore

This feature is unfinished and has limitations. diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 5f28aae36..7cb5ebcee 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -595,7 +595,7 @@ Released 18 December 2024.

  • - Remember selection with undo and redo. Controlled with SCI_SETSELECTIONUNDOHISTORY. + Remember selection with undo and redo. Controlled with SCI_SETUNDOSELECTIONHISTORY. Feature #1273, Bug #1479, Bug #1224. diff --git a/include/Scintilla.h b/include/Scintilla.h index 9f5b4e7a2..736a7e2d5 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -532,8 +532,10 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SC_CHANGE_HISTORY_INDICATORS 4 #define SCI_SETCHANGEHISTORY 2780 #define SCI_GETCHANGEHISTORY 2781 -#define SCI_SETSELECTIONUNDOHISTORY 2782 -#define SCI_GETSELECTIONUNDOHISTORY 2783 +#define SC_UNDO_SELECTION_HISTORY_DISABLED 0 +#define SC_UNDO_SELECTION_HISTORY_ENABLED 1 +#define SCI_SETUNDOSELECTIONHISTORY 2782 +#define SCI_GETUNDOSELECTIONHISTORY 2783 #define SCI_GETFIRSTVISIBLELINE 2152 #define SCI_GETLINE 2153 #define SCI_GETLINECOUNT 2154 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index ba37ceaf3..65d3d157b 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1334,11 +1334,15 @@ set void SetChangeHistory=2780(ChangeHistoryOption changeHistory,) # Report change history status. get ChangeHistoryOption GetChangeHistory=2781(,) -# Enable or disable selection undo history. -set void SetSelectionUndoHistory=2782(bool selectionUndoHistory,) +enu UndoSelectionHistoryOption=SC_UNDO_SELECTION_HISTORY_ +val SC_UNDO_SELECTION_HISTORY_DISABLED=0 +val SC_UNDO_SELECTION_HISTORY_ENABLED=1 -# Report selection undo history status. -get bool GetSelectionUndoHistory=2783(,) +# Enable or disable undo selection history. +set void SetUndoSelectionHistory=2782(UndoSelectionHistoryOption undoSelectionHistory,) + +# Report undo selection history status. +get UndoSelectionHistoryOption GetUndoSelectionHistory=2783(,) # Retrieve the display line at the top of the display. get line GetFirstVisibleLine=2152(,) diff --git a/include/ScintillaCall.h b/include/ScintillaCall.h index ab0bb3306..bcd462be9 100644 --- a/include/ScintillaCall.h +++ b/include/ScintillaCall.h @@ -360,8 +360,8 @@ public: Position FormatRangeFull(bool draw, RangeToFormatFull *fr); void SetChangeHistory(Scintilla::ChangeHistoryOption changeHistory); Scintilla::ChangeHistoryOption ChangeHistory(); - void SetSelectionUndoHistory(bool selectionUndoHistory); - bool SelectionUndoHistory(); + void SetUndoSelectionHistory(Scintilla::UndoSelectionHistoryOption undoSelectionHistory); + Scintilla::UndoSelectionHistoryOption UndoSelectionHistory(); Line FirstVisibleLine(); Position GetLine(Line line, char *text); std::string GetLine(Line line); diff --git a/include/ScintillaMessages.h b/include/ScintillaMessages.h index 02dd42e24..f60be4d52 100644 --- a/include/ScintillaMessages.h +++ b/include/ScintillaMessages.h @@ -285,8 +285,8 @@ enum class Message { FormatRangeFull = 2777, SetChangeHistory = 2780, GetChangeHistory = 2781, - SetSelectionUndoHistory = 2782, - GetSelectionUndoHistory = 2783, + SetUndoSelectionHistory = 2782, + GetUndoSelectionHistory = 2783, GetFirstVisibleLine = 2152, GetLine = 2153, GetLineCount = 2154, diff --git a/include/ScintillaTypes.h b/include/ScintillaTypes.h index 6d3e2a705..af726b2ab 100644 --- a/include/ScintillaTypes.h +++ b/include/ScintillaTypes.h @@ -299,6 +299,11 @@ enum class ChangeHistoryOption { Indicators = 4, }; +enum class UndoSelectionHistoryOption { + Disabled = 0, + Enabled = 1, +}; + enum class FoldLevel { None = 0x0, Base = 0x400, diff --git a/src/EditModel.cxx b/src/EditModel.cxx index 60848e6dc..1f9c2d064 100644 --- a/src/EditModel.cxx +++ b/src/EditModel.cxx @@ -181,7 +181,7 @@ int EditModel::GetMark(Sci::Line line) const { } void EditModel::EnsureModelState() { - if (!modelState && rememberingSelectionForUndo) { + if (!modelState && (undoSelectionHistoryOption == UndoSelectionHistoryOption::Enabled)) { if (ViewStateShared vss = pdoc->GetViewState(this)) { modelState = std::dynamic_pointer_cast(vss); } else { diff --git a/src/EditModel.h b/src/EditModel.h index 716fd5788..f75cece44 100644 --- a/src/EditModel.h +++ b/src/EditModel.h @@ -92,7 +92,7 @@ public: Document *pdoc; - bool rememberingSelectionForUndo = false; + Scintilla::UndoSelectionHistoryOption undoSelectionHistoryOption = UndoSelectionHistoryOption::Disabled; bool needRedoRemembered = false; ModelStateShared modelState; diff --git a/src/Editor.cxx b/src/Editor.cxx index 8a7b15719..d63f43f3f 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2399,7 +2399,7 @@ void Editor::SelectAll() { } void Editor::RestoreSelection(Sci::Position newPos, UndoRedo history) { - if (rememberingSelectionForUndo && modelState) { + if ((undoSelectionHistoryOption == UndoSelectionHistoryOption::Enabled) && modelState) { // Undo wants the element after the current as it just undid it const int index = pdoc->UndoCurrent() + (history == UndoRedo::undo ? 1 : 0); const SelectionSimple *pss = modelState->SelectionFromStack(index, history); @@ -2789,7 +2789,8 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { view.llc.Invalidate(LineLayout::ValidLevel::checkTextAndStyle); } } else { - if (rememberingSelectionForUndo && FlagSet(mh.modificationType, ModificationFlags::User)) { + if ((undoSelectionHistoryOption == UndoSelectionHistoryOption::Enabled) && + FlagSet(mh.modificationType, ModificationFlags::User)) { if (FlagSet(mh.modificationType, ModificationFlags::BeforeInsert | ModificationFlags::BeforeDelete)) { RememberSelectionForUndo(pdoc->UndoCurrent()); } @@ -8687,12 +8688,12 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::GetChangeHistory: return static_cast(changeHistoryOption); - case Message::SetSelectionUndoHistory: - rememberingSelectionForUndo = wParam; + case Message::SetUndoSelectionHistory: + undoSelectionHistoryOption = static_cast(wParam); break; - case Message::GetSelectionUndoHistory: - return rememberingSelectionForUndo; + case Message::GetUndoSelectionHistory: + return static_cast(undoSelectionHistoryOption); case Message::SetExtraAscent: vs.extraAscent = static_cast(wParam); -- cgit v1.2.3