mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-08 21:37:58 -05:00
Better Implementation for disabling Visual Mode
This commit is contained in:
@@ -22,11 +22,10 @@ type _range struct {
|
||||
}
|
||||
|
||||
type interactiveView struct {
|
||||
visual bool
|
||||
disableVisual bool
|
||||
vrange *_range
|
||||
baseSel int
|
||||
Table *tview.Table
|
||||
visual bool
|
||||
vrange *_range
|
||||
baseSel int
|
||||
Table *tview.Table
|
||||
}
|
||||
|
||||
func NewInteractiveView() *interactiveView {
|
||||
@@ -45,14 +44,16 @@ func NewInteractiveView() *interactiveView {
|
||||
i.update()
|
||||
return i.Table.GetInnerRect()
|
||||
})
|
||||
view.SetFocusFunc(func() {
|
||||
if i.visual {
|
||||
i.exitVisualMode()
|
||||
i.visual = false
|
||||
}
|
||||
})
|
||||
view.SetInputCapture(i.capture)
|
||||
return i
|
||||
}
|
||||
|
||||
func (i *interactiveView) DisableVisualMode(disable bool) {
|
||||
i.disableVisual = disable
|
||||
}
|
||||
|
||||
func (i *interactiveView) SelectionHandler(selrow int) {
|
||||
if i.visual {
|
||||
i.toggleVisualMode()
|
||||
@@ -186,7 +187,7 @@ func (i *interactiveView) capture(e *tcell.EventKey) *tcell.EventKey {
|
||||
}
|
||||
case 'v':
|
||||
{
|
||||
if !i.disableVisual {
|
||||
if !GetCurrentView().DisableVisualMode() {
|
||||
i.toggleVisualMode()
|
||||
}
|
||||
return nil
|
||||
@@ -206,7 +207,7 @@ func (i *interactiveView) capture(e *tcell.EventKey) *tcell.EventKey {
|
||||
default:
|
||||
{
|
||||
if e.Key() == tcell.KeyEscape {
|
||||
if !i.disableVisual {
|
||||
if !GetCurrentView().DisableVisualMode() {
|
||||
return i.getHandler("exitvisual")(e)
|
||||
}
|
||||
} else if GetCurrentView().ExternalInputCapture() != nil {
|
||||
|
||||
@@ -16,6 +16,7 @@ type View interface {
|
||||
ContextOpener() func(*Root, func(int))
|
||||
ContextKey() rune
|
||||
ContextHandler() func(start, end, sel int)
|
||||
DisableVisualMode() bool
|
||||
ExternalInputCapture() func(e *tcell.EventKey) *tcell.EventKey
|
||||
Name() string
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type AlbumsView struct {
|
||||
*DefaultView
|
||||
savedAlbums *spt.SavedAlbums
|
||||
}
|
||||
|
||||
@@ -51,5 +52,5 @@ func (a *AlbumsView) ExternalInputCapture() func(e *tcell.EventKey) *tcell.Event
|
||||
return e
|
||||
}
|
||||
}
|
||||
func (a *AlbumsView) ContextKey() rune { return 'a' }
|
||||
func (a *AlbumsView) Name() string { return "AlbumsView" }
|
||||
func (a *AlbumsView) DisableVisualMode() bool { return true }
|
||||
func (a *AlbumsView) Name() string { return "AlbumsView" }
|
||||
|
||||
@@ -26,3 +26,5 @@ func (d *DefaultView) ContextOpener() func(m *Root, s func(s int)) {
|
||||
}
|
||||
|
||||
func (d *DefaultView) ContextKey() rune { return 'a' }
|
||||
|
||||
func (d *DefaultView) DisableVisualMode() bool { return false }
|
||||
|
||||
Reference in New Issue
Block a user