Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: space as pagedown in read-only #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Project/Src/Actions/MiscActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,36 @@ public override void Execute(TextArea textArea)
}
}

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>
Expand Down
2 changes: 1 addition & 1 deletion Project/Src/Gui/TextArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
18 changes: 14 additions & 4 deletions Project/Src/Gui/TextEditorControlBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public abstract class TextEditorControlBase : UserControl
/// </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;

Expand Down Expand Up @@ -183,14 +189,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];
}
Expand Down Expand Up @@ -231,6 +237,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();
Expand Down