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

Merged
merged 2 commits into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions Project/Src/Gui/TextEditorControlBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class TextEditorControlBase : UserControl
/// action.
/// </summary>
protected Dictionary<Keys, IEditAction> editactions = new Dictionary<Keys, IEditAction>();
protected HashSet<Keys> readonlyactions = new HashSet<Keys>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected HashSet<Keys> readonlyactions = new HashSet<Keys>();
protected HashSet<Keys> readonlyonlyactions = new HashSet<Keys>();

or add a regarding xmldoc. Without a clarification here or in IsEditAction it is hard to grasp.


private Encoding encoding;
private int updateLevel;
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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();
Expand Down