Fix the multiselect highlight issue

This commit is contained in:
Sameer Rahmani 2022-11-25 17:29:31 +00:00
parent c0b97850ae
commit fe2ec158be
2 changed files with 10 additions and 6 deletions

View File

@ -89,12 +89,15 @@ func RenderHelp(s *State, inputs Items) {
func RenderMain(s *State, inputs Items) { func RenderMain(s *State, inputs Items) {
y := 2 y := 2
status := fmt.Sprintf("[Line: %d][? For help]: %s", s.Current+1, s.UserInput) //status := fmt.Sprintf("[Line: %d][? For help]: %s", s.Current+1, s.UserInput)
status := fmt.Sprintf("L: %d, U: %d, S: %d [Line: %d][? For help]: %s", s.LowerBound, s.UpperBound, s.SelectionStartLine, s.Current+1, s.UserInput)
drawText(*s.Screen, 0, 0, xmax-1, 1, helpStyle, status) drawText(*s.Screen, 0, 0, xmax-1, 1, helpStyle, status)
drawText(*s.Screen, len(status), 0, xmax-1, 1, cursorStyle, "⎥") drawText(*s.Screen, len(status), 0, xmax-1, 1, cursorStyle, "⎥")
for i, item := range (*inputs)[s.LowerBound:s.UpperBound] { for i, item := range (*inputs)[s.LowerBound:s.UpperBound] {
style := tcell.StyleDefault style := tcell.StyleDefault
arrowStyle := normalArrow arrowStyle := normalArrow
index := s.LowerBound + i
var txt string var txt string
@ -110,14 +113,14 @@ func RenderMain(s *State, inputs Items) {
} }
if s.InSelectionMode { if s.InSelectionMode {
if (s.SelectionStartLine < s.LowerBound && i <= s.Current) || (s.SelectionStartLine > s.UpperBound && i >= s.Current) { if (s.SelectionStartLine < s.LowerBound && index <= s.Current) || (s.SelectionStartLine > s.UpperBound && index >= s.Current) {
style = selectionStyle style = selectionStyle
arrowStyle = selectionArrow arrowStyle = selectionArrow
} else { } else {
low := min(s.SelectionStartLine, s.Current) low := min(s.SelectionStartLine, s.Current)
high := max(s.SelectionStartLine, s.Current) high := max(s.SelectionStartLine, s.Current)
if i >= low && i <= high { if index >= low && index <= high {
style = selectionStyle style = selectionStyle
arrowStyle = selectionArrow arrowStyle = selectionArrow
} }
@ -191,6 +194,8 @@ func HandleMain(state *State, ev tcell.EventKey, input Items) {
} else if ev.Key() == tcell.KeyCtrlH { } else if ev.Key() == tcell.KeyCtrlH {
state.CurrentScene = 1 state.CurrentScene = 1
} else if ev.Key() == tcell.KeyBackspace {
state.UserInput = string(state.UserInput[:len(state.UserInput)-2])
} else { } else {
state.UserInput = state.UserInput + string(ev.Rune()) state.UserInput = state.UserInput + string(ev.Rune())
} }

View File

@ -23,9 +23,8 @@ import (
) )
type Item struct { type Item struct {
Text string Text string
Selected bool Selected bool
Highlight bool
} }
type Items = *[]*Item type Items = *[]*Item