From ccaff3b3e630cb8976f167145c67de6ddc6be5fe Mon Sep 17 00:00:00 2001 From: Gerhard Olsson Date: Tue, 28 Jan 2025 22:14:20 +0100 Subject: [PATCH 1/2] feat: space as pagedown in read-only Similar shift-space as pageup, as in browsers etc. --- Project/Src/Actions/MiscActions.cs | 30 ++++++++++++++++++++++++ Project/Src/Gui/TextArea.cs | 2 +- Project/Src/Gui/TextEditorControlBase.cs | 13 ++++++---- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Project/Src/Actions/MiscActions.cs b/Project/Src/Actions/MiscActions.cs index b509379..566bf3e 100644 --- a/Project/Src/Actions/MiscActions.cs +++ b/Project/Src/Actions/MiscActions.cs @@ -655,6 +655,36 @@ public override void Execute(TextArea textArea) } } + public class Space : AbstractEditAction + { + /// + /// Executes this edit action + /// + /// The which is used for callback purposes + public override void Execute(TextArea textArea) + { + if (!textArea.Document.ReadOnly) + return; + + (new MovePageDown()).Execute(textArea); + } + } + + public class ShiftSpace : AbstractEditAction + { + /// + /// Executes this edit action + /// + /// The which is used for callback purposes + public override void Execute(TextArea textArea) + { + if (!textArea.Document.ReadOnly) + return; + + (new MovePageUp()).Execute(textArea); + } + } + public class Return : AbstractEditAction { /// diff --git a/Project/Src/Gui/TextArea.cs b/Project/Src/Gui/TextArea.cs index 56e2c24..7fef5fc 100644 --- a/Project/Src/Gui/TextArea.cs +++ b/Project/Src/Gui/TextArea.cs @@ -803,7 +803,7 @@ public bool ExecuteDialogKey(Keys keyData) return true; // if not (or the process was 'silent', use the standard edit actions - var action = MotherTextEditorControl?.GetEditAction(keyData); + var action = MotherTextEditorControl?.GetEditAction(keyData, Document.ReadOnly); AutoClearSelection = true; if (action != null) { diff --git a/Project/Src/Gui/TextEditorControlBase.cs b/Project/Src/Gui/TextEditorControlBase.cs index dcf239a..c916ad3 100644 --- a/Project/Src/Gui/TextEditorControlBase.cs +++ b/Project/Src/Gui/TextEditorControlBase.cs @@ -36,6 +36,7 @@ public abstract class TextEditorControlBase : UserControl /// action. /// protected Dictionary editactions = new Dictionary(); + protected HashSet readonlyactions = new HashSet(); private Encoding encoding; private int updateLevel; @@ -183,14 +184,14 @@ protected virtual void OnReloadHighlighting(object sender, EventArgs e) } } - public bool IsEditAction(Keys keyData) + public bool IsEditAction(Keys keyData, bool readOnly) { - return editactions.ContainsKey(keyData); + return editactions.ContainsKey(keyData) && (readOnly || !readonlyactions.Contains(keyData)); } - internal IEditAction GetEditAction(Keys keyData) + internal IEditAction GetEditAction(Keys keyData, bool readOnly) { - if (!IsEditAction(keyData)) + if (!IsEditAction(keyData, readOnly)) return null; return editactions[keyData]; } @@ -231,6 +232,10 @@ private void GenerateDefaultActions() editactions[Keys.PageUp | Keys.Shift] = new ShiftMovePageUp(); editactions[Keys.PageDown] = new MovePageDown(); editactions[Keys.PageDown | Keys.Shift] = new ShiftMovePageDown(); + editactions[Keys.Space] = new Space(); + readonlyactions.Add(Keys.Space); + editactions[Keys.Space | Keys.Shift] = new ShiftSpace(); + readonlyactions.Add(Keys.Space | Keys.Shift); editactions[Keys.Return] = new Return(); editactions[Keys.Tab] = new Tab(); From ca72e35bb48b86d6263731b56d566cb5113db71a Mon Sep 17 00:00:00 2001 From: Gerhard Olsson Date: Sun, 2 Feb 2025 13:24:29 +0100 Subject: [PATCH 2/2] fixup! review comments to add doc --- Project/Src/Gui/TextEditorControlBase.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Project/Src/Gui/TextEditorControlBase.cs b/Project/Src/Gui/TextEditorControlBase.cs index c916ad3..07aa010 100644 --- a/Project/Src/Gui/TextEditorControlBase.cs +++ b/Project/Src/Gui/TextEditorControlBase.cs @@ -36,7 +36,12 @@ public abstract class TextEditorControlBase : UserControl /// action. /// protected Dictionary editactions = new Dictionary(); - protected HashSet readonlyactions = new HashSet(); + + /// + /// Key combinations for actions only available in read-only mode. + /// In read-write these keys are ignored. + /// + protected HashSet readonlyactions = new(); private Encoding encoding; private int updateLevel;