Browse Source

feat: space as pagedown in read-only (#47)

Similar shift-space as pageup, as in browsers, command line
pull/50/head
Gerhard Olsson 4 months ago
committed by GitHub
parent
commit
bf7fcd4e75
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 30
      Project/Src/Actions/MiscActions.cs
  2. 2
      Project/Src/Gui/TextArea.cs
  3. 18
      Project/Src/Gui/TextEditorControlBase.cs

30
Project/Src/Actions/MiscActions.cs

@ -655,6 +655,36 @@ namespace ICSharpCode.TextEditor.Actions
}
}
public class Space : AbstractEditAction
{
/// <remarks>
/// Executes this edit action
/// </remarks>
/// <param name="textArea">The <see cref="ItextArea" /> which is used for callback purposes</param>
public override void Execute(TextArea textArea)
{
if (!textArea.Document.ReadOnly)
return;
(new MovePageDown()).Execute(textArea);
}
}
public class ShiftSpace : AbstractEditAction
{
/// <remarks>
/// Executes this edit action
/// </remarks>
/// <param name="textArea">The <see cref="ItextArea" /> which is used for callback purposes</param>
public override void Execute(TextArea textArea)
{
if (!textArea.Document.ReadOnly)
return;
(new MovePageUp()).Execute(textArea);
}
}
public class Return : AbstractEditAction
{
/// <remarks>

2
Project/Src/Gui/TextArea.cs

@ -803,7 +803,7 @@ namespace ICSharpCode.TextEditor
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)
{

18
Project/Src/Gui/TextEditorControlBase.cs

@ -37,6 +37,12 @@ namespace ICSharpCode.TextEditor
/// </summary>
protected Dictionary<Keys, IEditAction> editactions = new Dictionary<Keys, IEditAction>();
/// <summary>
/// Key combinations for actions only available in read-only mode.
/// In read-write these keys are ignored.
/// </summary>
protected HashSet<Keys> readonlyactions = new();
private Encoding encoding;
private int updateLevel;
@ -183,14 +189,14 @@ namespace ICSharpCode.TextEditor
}
}
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 +237,10 @@ namespace ICSharpCode.TextEditor
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();

Loading…
Cancel
Save