Skip to content

Commit bf7fcd4

Browse files
authored
feat: space as pagedown in read-only (#47)
Similar shift-space as pageup, as in browsers, command line
1 parent 48f506b commit bf7fcd4

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

Project/Src/Actions/MiscActions.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,36 @@ public override void Execute(TextArea textArea)
655655
}
656656
}
657657

658+
public class Space : AbstractEditAction
659+
{
660+
/// <remarks>
661+
/// Executes this edit action
662+
/// </remarks>
663+
/// <param name="textArea">The <see cref="ItextArea" /> which is used for callback purposes</param>
664+
public override void Execute(TextArea textArea)
665+
{
666+
if (!textArea.Document.ReadOnly)
667+
return;
668+
669+
(new MovePageDown()).Execute(textArea);
670+
}
671+
}
672+
673+
public class ShiftSpace : AbstractEditAction
674+
{
675+
/// <remarks>
676+
/// Executes this edit action
677+
/// </remarks>
678+
/// <param name="textArea">The <see cref="ItextArea" /> which is used for callback purposes</param>
679+
public override void Execute(TextArea textArea)
680+
{
681+
if (!textArea.Document.ReadOnly)
682+
return;
683+
684+
(new MovePageUp()).Execute(textArea);
685+
}
686+
}
687+
658688
public class Return : AbstractEditAction
659689
{
660690
/// <remarks>

Project/Src/Gui/TextArea.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ public bool ExecuteDialogKey(Keys keyData)
803803
return true;
804804

805805
// if not (or the process was 'silent', use the standard edit actions
806-
var action = MotherTextEditorControl?.GetEditAction(keyData);
806+
var action = MotherTextEditorControl?.GetEditAction(keyData, Document.ReadOnly);
807807
AutoClearSelection = true;
808808
if (action != null)
809809
{

Project/Src/Gui/TextEditorControlBase.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public abstract class TextEditorControlBase : UserControl
3737
/// </summary>
3838
protected Dictionary<Keys, IEditAction> editactions = new Dictionary<Keys, IEditAction>();
3939

40+
/// <summary>
41+
/// Key combinations for actions only available in read-only mode.
42+
/// In read-write these keys are ignored.
43+
/// </summary>
44+
protected HashSet<Keys> readonlyactions = new();
45+
4046
private Encoding encoding;
4147
private int updateLevel;
4248

@@ -183,14 +189,14 @@ protected virtual void OnReloadHighlighting(object sender, EventArgs e)
183189
}
184190
}
185191

186-
public bool IsEditAction(Keys keyData)
192+
public bool IsEditAction(Keys keyData, bool readOnly)
187193
{
188-
return editactions.ContainsKey(keyData);
194+
return editactions.ContainsKey(keyData) && (readOnly || !readonlyactions.Contains(keyData));
189195
}
190196

191-
internal IEditAction GetEditAction(Keys keyData)
197+
internal IEditAction GetEditAction(Keys keyData, bool readOnly)
192198
{
193-
if (!IsEditAction(keyData))
199+
if (!IsEditAction(keyData, readOnly))
194200
return null;
195201
return editactions[keyData];
196202
}
@@ -231,6 +237,10 @@ private void GenerateDefaultActions()
231237
editactions[Keys.PageUp | Keys.Shift] = new ShiftMovePageUp();
232238
editactions[Keys.PageDown] = new MovePageDown();
233239
editactions[Keys.PageDown | Keys.Shift] = new ShiftMovePageDown();
240+
editactions[Keys.Space] = new Space();
241+
readonlyactions.Add(Keys.Space);
242+
editactions[Keys.Space | Keys.Shift] = new ShiftSpace();
243+
readonlyactions.Add(Keys.Space | Keys.Shift);
234244

235245
editactions[Keys.Return] = new Return();
236246
editactions[Keys.Tab] = new Tab();

0 commit comments

Comments
 (0)