Skip to content

Commit

Permalink
Made CursorLeft/CursorRight change focus when cursor position is at s…
Browse files Browse the repository at this point in the history
…tart/end of a TextView (gui-cs#1271)
  • Loading branch information
tznind committed May 2, 2021
1 parent 8dabd16 commit 71e719f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Terminal.Gui/Views/TextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,25 @@ public override bool ProcessKey (KeyEvent kb)
int restCount;
List<Rune> rest;

// if the user presses Left (without any control keys) and they are at the start of the text
if(kb.Key == Key.CursorLeft && currentColumn == 0 && currentRow == 0) {
// do not respond (this lets the key press fall through to navigation system - which usually changes focus backward)
return false;
}

// if the user presses Right (without any control keys)
if (kb.Key == Key.CursorRight) {

// determine where the last cursor position in the text is
var lastRow = model.Count - 1;
var lastCol = model.GetLine (lastRow).Count;

// if they are at the very end of all the text do not respond (this lets the key press fall through to navigation system - which usually changes focus forward)
if (currentColumn == lastCol && currentRow == lastRow) {
return false;
}
}

// Handle some state here - whether the last command was a kill
// operation and the column tracking (up/down)
switch (kb.Key) {
Expand Down

0 comments on commit 71e719f

Please sign in to comment.