diff options
author | Neil <nyamatongwe@gmail.com> | 2025-04-18 09:20:38 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-04-18 09:20:38 +1000 |
commit | c1de3774867127539b9b93efd4a0832a3f3a9fcf (patch) | |
tree | 8109f426718be98882a78c9369fbd9c4ca64224f | |
parent | d36d669ddfd447fbbe28faef18457177bf102881 (diff) | |
download | scintilla-mirror-c1de3774867127539b9b93efd4a0832a3f3a9fcf.tar.gz |
Control restoring vertical scroll position for undo with
SC_UNDO_SELECTION_HISTORY_SCROLL flag to SCI_SETUNDOSELECTIONHISTORY.
-rw-r--r-- | doc/ScintillaDoc.html | 8 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
-rw-r--r-- | include/Scintilla.h | 1 | ||||
-rw-r--r-- | include/Scintilla.iface | 1 | ||||
-rw-r--r-- | include/ScintillaTypes.h | 1 | ||||
-rw-r--r-- | src/EditModel.cxx | 2 | ||||
-rw-r--r-- | src/Editor.cxx | 8 |
7 files changed, 21 insertions, 4 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 28010507f..667acb7b3 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -2054,6 +2054,14 @@ struct Sci_TextToFindFull { <td>Restore selection for each undo and redo.</td> </tr> + <tr> + <th align="left"><code>SC_UNDO_SELECTION_HISTORY_SCROLL</code></th> + + <td>2</td> + + <td>Restore vertical scroll position. Has no effect without <code>SC_UNDO_SELECTION_HISTORY_ENABLED</code>.</td> + </tr> + </tbody> </table> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 4d69143ac..4da325dae 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -601,6 +601,10 @@ Released 2 April 2025. </li> <li> + Add SC_UNDO_SELECTION_HISTORY_SCROLL flag to SCI_SETUNDOSELECTIONHISTORY which controls + whether undo and redo restore vertical scroll position. + </li> + <li> Tweak SC_MARK_BAR to be slightly wider by using next higher whole pixel instead of next lower for margin width / 3. </li> </ul> diff --git a/include/Scintilla.h b/include/Scintilla.h index 213dde52e..a90dd3571 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -534,6 +534,7 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SCI_GETCHANGEHISTORY 2781 #define SC_UNDO_SELECTION_HISTORY_DISABLED 0 #define SC_UNDO_SELECTION_HISTORY_ENABLED 1 +#define SC_UNDO_SELECTION_HISTORY_SCROLL 2 #define SCI_SETUNDOSELECTIONHISTORY 2782 #define SCI_GETUNDOSELECTIONHISTORY 2783 #define SCI_SETSELECTIONSERIALIZED 2784 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index e1814eb5a..47896b63f 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1337,6 +1337,7 @@ get ChangeHistoryOption GetChangeHistory=2781(,) enu UndoSelectionHistoryOption=SC_UNDO_SELECTION_HISTORY_ val SC_UNDO_SELECTION_HISTORY_DISABLED=0 val SC_UNDO_SELECTION_HISTORY_ENABLED=1 +val SC_UNDO_SELECTION_HISTORY_SCROLL=2 # Enable or disable undo selection history. set void SetUndoSelectionHistory=2782(UndoSelectionHistoryOption undoSelectionHistory,) diff --git a/include/ScintillaTypes.h b/include/ScintillaTypes.h index 71e2be398..0991a1480 100644 --- a/include/ScintillaTypes.h +++ b/include/ScintillaTypes.h @@ -302,6 +302,7 @@ enum class ChangeHistoryOption { enum class UndoSelectionHistoryOption { Disabled = 0, Enabled = 1, + Scroll = 2, }; enum class FoldLevel { diff --git a/src/EditModel.cxx b/src/EditModel.cxx index e12aab38e..65d39f9e7 100644 --- a/src/EditModel.cxx +++ b/src/EditModel.cxx @@ -172,7 +172,7 @@ int EditModel::GetMark(Sci::Line line) const { } void EditModel::EnsureModelState() { - if (!modelState && (undoSelectionHistoryOption == UndoSelectionHistoryOption::Enabled)) { + if (!modelState && (undoSelectionHistoryOption != UndoSelectionHistoryOption::Disabled)) { if (ViewStateShared vss = pdoc->GetViewState(this)) { modelState = std::dynamic_pointer_cast<ModelState>(vss); } else { diff --git a/src/Editor.cxx b/src/Editor.cxx index ead69617d..334600461 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2409,12 +2409,14 @@ void Editor::SelectAll() { void Editor::RestoreSelection(Sci::Position newPos, UndoRedo history) { EnsureModelState(); - if ((undoSelectionHistoryOption == UndoSelectionHistoryOption::Enabled) && modelState) { + if (FlagSet(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 SelectionWithScroll selAndLine = modelState->SelectionFromStack(index, history); if (!selAndLine.selection.empty()) { - ScrollTo(selAndLine.topLine); + if (FlagSet(undoSelectionHistoryOption, UndoSelectionHistoryOption::Scroll)) { + ScrollTo(selAndLine.topLine); + } sel = Selection(selAndLine.selection); if (sel.IsRectangular()) { const size_t mainForRectangular = sel.Main(); @@ -2799,7 +2801,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { view.llc.Invalidate(LineLayout::ValidLevel::checkTextAndStyle); } } else { - if ((undoSelectionHistoryOption == UndoSelectionHistoryOption::Enabled) && + if (FlagSet(undoSelectionHistoryOption, UndoSelectionHistoryOption::Enabled) && FlagSet(mh.modificationType, ModificationFlags::User)) { if (FlagSet(mh.modificationType, ModificationFlags::BeforeInsert | ModificationFlags::BeforeDelete)) { RememberSelectionForUndo(pdoc->UndoCurrent()); |