From 71e719fb2b9ed32140a17e992ad7ee855e84fd96 Mon Sep 17 00:00:00 2001 From: Thomas Nind <31306100+tznind@users.noreply.github.com> Date: Sun, 2 May 2021 19:22:04 +0100 Subject: [PATCH] Made CursorLeft/CursorRight change focus when cursor position is at start/end of a TextView (#1271) --- Terminal.Gui/Views/TextView.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 48a2be04d..9717ad193 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1944,6 +1944,25 @@ namespace Terminal.Gui { int restCount; List 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) {