From 93e5d7fc0cc2b73a3d746e9ffc30a9d6b06af3eb Mon Sep 17 00:00:00 2001 From: Thomas Nind Date: Tue, 29 Jun 2021 07:08:01 +0100 Subject: [PATCH] Made selected cell first character inverted colors This allows users to tell which cell is driving navigation etc in multi cell selections --- Terminal.Gui/Views/TableView.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/TableView.cs b/Terminal.Gui/Views/TableView.cs index aa4409191..d295a6e1d 100644 --- a/Terminal.Gui/Views/TableView.cs +++ b/Terminal.Gui/Views/TableView.cs @@ -414,9 +414,28 @@ namespace Terminal.Gui { var representation = GetRepresentation(val,colStyle); var scheme = (colStyle?.ColorGetter?.Invoke(rowToRender,val)) ?? rowScheme; - Driver.SetAttribute (isSelectedCell ? scheme.HotFocus : scheme.Normal); + var cellColor = isSelectedCell? scheme.HotFocus: scheme.Normal; + + var render = TruncateOrPad (val, representation, current.Width, colStyle); - Driver.AddStr (TruncateOrPad(val,representation, current.Width, colStyle)); + // If the cell is the selected col/row then draw the first rune in inverted colors + // this allows the user to track which cell is the active one during a multi cell + // selection or in full row select mode + if(current.Column.Ordinal == selectedColumn && rowToRender == selectedRow) { + + if (render.Length > 0) { + // invert the color of the current cell for the first character + Driver.SetAttribute (Driver.MakeAttribute (cellColor.Background, cellColor.Foreground)); + Driver.AddRune (render [0]); + + Driver.SetAttribute (cellColor); + Driver.AddStr (render.Substring (1)); + } + } + else { + Driver.SetAttribute (cellColor); + Driver.AddStr (render); + } // Reset color scheme to normal for drawing separators if we drew text with custom scheme if(scheme != rowScheme) {