Better Implementation for disabling Visual Mode

This commit is contained in:
aditya-K2
2023-04-13 23:08:48 +05:30
parent 8b9e72aafe
commit 2124a413e8
4 changed files with 18 additions and 13 deletions

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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" }

View File

@@ -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 }