From 0222105d7ca127ee4a5cede6bd63c69bae9c88bd Mon Sep 17 00:00:00 2001 From: tznind Date: Wed, 30 Dec 2020 18:32:50 +0000 Subject: [PATCH] Added PositionCursor implementation --- Terminal.Gui/Views/TreeView.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Terminal.Gui/Views/TreeView.cs b/Terminal.Gui/Views/TreeView.cs index aae03a845..2551d0747 100644 --- a/Terminal.Gui/Views/TreeView.cs +++ b/Terminal.Gui/Views/TreeView.cs @@ -649,6 +649,28 @@ namespace Terminal.Gui { return false; } + /// + /// Positions the cursor at the start of the selected objects line (if visible) + /// + public override void PositionCursor() + { + if (CanFocus && HasFocus && Visible && SelectedObject != null) + { + var map = BuildLineMap(); + var idx = Array.FindIndex(map,b=>b.Model.Equals(SelectedObject)); + + // if currently selected line is visible + if(idx - ScrollOffset >= 0 && idx - ScrollOffset < Bounds.Height) + Move(0,idx - ScrollOffset); + else + base.PositionCursor(); + + } else { + base.PositionCursor(); + } + } + + /// /// Determines systems behaviour when the left arrow key is pressed. Default behaviour is to collapse the current tree node if possible otherwise changes selection to current branches parent ///