mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-09 13:58:05 -05:00
Remove Redundancy and fix scrolling
fix:
Earlier when 'g' / 'G' was pressed and after that the opposite key
(in g's case 'G' and vice versa) the i.vrange was 0, n (where n is
row count) instead it should have been baseSel, n
i.e
earlier it was:
top (vrange.Start is here)
|
|
|
|
baseSel
|
|
|
bottom (vrange.End is here)
'|' mean selected.
now it is:
top
_
_
_
_
baseSel (vrange.Start is here)
|
|
|
bottom (vrange.End is here)
'_' means not selected.
(The course of action here is first press 'g' and then pressed 'G')
This commit is contained in:
27
iview.go
27
iview.go
@@ -9,20 +9,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
berr = errors.New("Couldn't Get Base Selection in Interactive View")
|
||||
defaultfg = tcell.ColorGreen
|
||||
defaultbg = tcell.ColorDefault
|
||||
selfg = tcell.ColorGreen
|
||||
seldefault = tcell.StyleDefault.
|
||||
berr = errors.New("Couldn't Get Base Selection in Interactive View")
|
||||
defaultfg = tcell.ColorGreen
|
||||
defaultbg = tcell.ColorDefault
|
||||
invertsel = tcell.StyleDefault.
|
||||
Foreground(defaultbg).
|
||||
Background(defaultfg)
|
||||
defaultstyle = tcell.StyleDefault.
|
||||
Foreground(defaultfg).
|
||||
Background(defaultbg)
|
||||
selStyle = tcell.StyleDefault.
|
||||
Foreground(selfg).
|
||||
Background(tcell.ColorDefault).
|
||||
Bold(true)
|
||||
)
|
||||
|
||||
type _range struct {
|
||||
@@ -57,14 +52,14 @@ func (i *InteractiveView) exitVisualMode() {
|
||||
i.View.Select(i.vrange.End, -1)
|
||||
}
|
||||
i.baseSel = -1
|
||||
i.View.SetSelectedStyle(seldefault)
|
||||
i.View.SetSelectedStyle(invertsel)
|
||||
}
|
||||
|
||||
func (i *InteractiveView) enterVisualMode() {
|
||||
row, _ := i.View.GetSelection()
|
||||
i.baseSel = row
|
||||
i.vrange.Start, i.vrange.End = row, row
|
||||
i.View.SetSelectedStyle(selStyle)
|
||||
i.View.SetSelectedStyle(defaultstyle)
|
||||
}
|
||||
|
||||
func (i *InteractiveView) toggleVisualMode() {
|
||||
@@ -134,6 +129,7 @@ func (i *InteractiveView) GetHandler(s string) func(e *tcell.EventKey) *tcell.Ev
|
||||
"top": func(e *tcell.EventKey) *tcell.EventKey {
|
||||
if i.visual {
|
||||
i.vrange.Start = 0
|
||||
i.vrange.End = i.baseSel
|
||||
i.View.ScrollToBeginning()
|
||||
return nil
|
||||
}
|
||||
@@ -141,6 +137,7 @@ func (i *InteractiveView) GetHandler(s string) func(e *tcell.EventKey) *tcell.Ev
|
||||
},
|
||||
"bottom": func(e *tcell.EventKey) *tcell.EventKey {
|
||||
if i.visual {
|
||||
i.vrange.Start = i.baseSel
|
||||
i.vrange.End = i.View.GetRowCount() - 1
|
||||
i.View.ScrollToEnd()
|
||||
return nil
|
||||
@@ -195,18 +192,16 @@ func GetCell(text string, st tcell.Style) *tview.TableCell {
|
||||
}
|
||||
|
||||
func (i *InteractiveView) Update() {
|
||||
s := strings.Split("orem ipsum dolor sit amet, consectetur adipiscing elit. Nunc nec leo a tellus gravida convallis. Curabitur tempus purus nisi. Proin non enim convallis augue porta aliquet. Aliquam sed sem eget mauris faucibus ultricies. Ut at tortor elit. Pellentesque tincidunt leo dolor, sed pulvinar mauris mattis quis. Integer ut magna in nulla eleifend gravida non id est. Etiam vehicula dui nec orci porttitor condimentum ac nec lectus. Nam imperdiet sit amet ipsum at sollicitudin. Fusce ac odio condimentum, aliquam neque et, pretium tellus. Ut suscipit libero sed leo accumsan sagittis. Maecenas leo lacus, maximus id lacinia non, imperdiet non dolor. Sed consectetur ipsum et turpis tristique, accumsan volutpat diam placerat. Etiam quis arcu dignissim, mollis nunc at, ultrices mi. Fusce vitae magna ligula. Donec sit amet placerat dui. Nulla tempus vestibulum felis, volutpat congue ipsum. Suspendisse rutrum orci eget diam pretium cursus id efficitur tortor. Donec lobortis odio ac massa tempus, eu pretium massa iaculis. Suspendisse tempor nisl a ullamcorper faucibus. Curabitur sollicitudin, erat et feugiat consectetur, nunc enim gravida dolor, a rutrum magna ante vitae felis. Nullam ligula risus, varius nec laoreet ut, malesuada a mi. Ut et eleifend leo. Etiam ac mi dui. Curabitur commodo felis non congue pharetra. Ut eu odio felis. Nullam eu mollis arcu. Nulla ut massa lorem. Vivamus pellentesque id ex sit amet pharetra. Aliquam at urna in nisl bibendum hendrerit. Donec suscipit tortor eu magna suscipit, vitae consequat metus imperdiet. Cras dui elit, luctus vel feugiat vitae, faucibus in enim. Aliquam neque ex, lacinia id nisi nec, euismod porta dolor. Morbi imperdiet sapien at nisl suscipit tempor. In hac habitasse platea dictumst. Etiam lobortis blandit nunc et sodales. Aliquam feugiat enim auctor, posuere tellus quis, fermentum massa. Quisque nec gravida leo. Aenean molestie mi sed felis porta luctus. Nulla pulvinar est in ultricies consectetur.", " ")
|
||||
s := strings.Split("orem ipsum dolor sit amet, consectetur adipiscing elit. Nunc nec leo a tellus gravida convallis. Curabitur tempus purus nisi. Proin non enim convallis augue porta aliquet.", " ")
|
||||
i.View.Clear()
|
||||
for j := range s {
|
||||
b := ""
|
||||
st := defaultstyle
|
||||
if i.visual && (j >= i.vrange.Start && j <= i.vrange.End) {
|
||||
b = "[blue::]█[::]"
|
||||
st = selStyle
|
||||
}
|
||||
i.View.SetCell(j, 0,
|
||||
GetCell(b, st))
|
||||
GetCell(b, defaultstyle))
|
||||
i.View.SetCell(j, 1,
|
||||
GetCell(s[j], st))
|
||||
GetCell(s[j], defaultstyle))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user