Replies: 4 comments 4 replies
-
Writing this helped ;-). The docs should read: /// <summary>
/// Invokes all <see cref="Command"/>s that are bound to <paramref name="keyEvent"/> in <see cref="KeyBindings"/>.
/// </summary>
/// <param name="keyEvent">The key event passed.</param>
/// <returns><see langword="null"/> if no matching command was found in <see cref="KeyBindings"/>. Otherwise, <see langword="true"/> if any invoked command indicated
/// the key was handled; <see langword="false"/> otherwise.</returns> I still don't understand the AddCommand (Command.Right, () => { ChangeSelectionByOffset (1, 0, false); return true; });
AddCommand (Command.Left, () => { ChangeSelectionByOffset (-1, 0, false); return true; });
AddCommand (Command.LineUp, () => { ChangeSelectionByOffset (0, -1, false); return true; });
AddCommand (Command.LineDown, () => { ChangeSelectionByOffset (0, 1, false); return true; });
AddCommand (Command.PageUp, () => { PageUp (false); return true; });
AddCommand (Command.PageDown, () => { PageDown (false); return true; });
AddCommand (Command.LeftHome, () => { ChangeSelectionToStartOfRow (false); return true; });
AddCommand (Command.RightEnd, () => { ChangeSelectionToEndOfRow (false); return true; });
AddCommand (Command.TopHome, () => { ChangeSelectionToStartOfTable (false); return true; });
AddCommand (Command.BottomEnd, () => { ChangeSelectionToEndOfTable (false); return true; });
AddCommand (Command.RightExtend, () => { ChangeSelectionByOffset (1, 0, true); return true; });
AddCommand (Command.LeftExtend, () => { ChangeSelectionByOffset (-1, 0, true); return true; });
AddCommand (Command.LineUpExtend, () => { ChangeSelectionByOffset (0, -1, true); return true; });
AddCommand (Command.LineDownExtend, () => { ChangeSelectionByOffset (0, 1, true); return true; });
AddCommand (Command.PageUpExtend, () => { PageUp (true); return true; });
AddCommand (Command.PageDownExtend, () => { PageDown (true); return true; });
AddCommand (Command.LeftHomeExtend, () => { ChangeSelectionToStartOfRow (true); return true; });
AddCommand (Command.RightEndExtend, () => { ChangeSelectionToEndOfRow (true); return true; });
AddCommand (Command.TopHomeExtend, () => { ChangeSelectionToStartOfTable (true); return true; });
AddCommand (Command.BottomEndExtend, () => { ChangeSelectionToEndOfTable (true); return true; });
AddCommand (Command.SelectAll, () => { SelectAll (); return true; });
AddCommand (Command.Accept, () => { OnCellActivated (new CellActivatedEventArgs (Table, SelectedColumn, SelectedRow)); return true; });
AddCommand (Command.ToggleChecked, () => { ToggleCurrentCellSelection (); return true; }); I believe the public override bool OnKeyPressed (KeyEventArgs keyEvent)
{
if (base.OnKeyPressed (keyEvent)) {
return true;
}
if (TableIsNullOrInvisible ()) {
PositionCursor ();
return false;
}
var result = InvokeKeyBindings (keyEvent);
if (result ?? true) {
PositionCursor ();
return true;
}
if (CollectionNavigator != null &&
this.HasFocus &&
Table.Rows != 0 &&
Terminal.Gui.CollectionNavigator.IsCompatibleKey (keyEvent) &&
!keyEvent.Key.HasFlag (Key.CtrlMask) &&
!keyEvent.Key.HasFlag (Key.AltMask) &&
char.IsLetterOrDigit ((char)keyEvent.KeyValue)) {
return CycleToNextTableEntryBeginningWith (keyEvent);
}
return false;
} RIght? |
Beta Was this translation helpful? Give feedback.
-
Got it. All good. I'll ensure the docs are correct via #2926 |
Beta Was this translation helpful? Give feedback.
-
var result = InvokeKeybindings (keyEvent);
if (result != null) {
PositionCursor ();
return true;
} I think this code is about preventing re-entry into the key handling logic e.g. via a base class call. It is probably just defensive coding. It is saying 'if keybinding existed for this keystroke swallow the event'. Could also be a precaution against going into key navigator when theres a keybinding existing.
I think your proposed new code |
Beta Was this translation helpful? Give feedback.
-
Specially on Linux the
Yes, I really regret implementing it. You can remove them without any problems.
For me, go for it. Thanks. |
Beta Was this translation helpful? Give feedback.
-
I don't understand why
InvokeKeyBindings
doesn't just return abool
@tznind & @BDisp, what am I missing? It seems needlessly complex.
Most calling code looks like this:
But in a few cases (e.g.
TableView
) we do this:I don't understand this logic!
Beta Was this translation helpful? Give feedback.
All reactions