mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-30 13:48:50 +08:00
Fix: Focus of tag editor will remain stable
This commit is contained in:
parent
fedaaa58c5
commit
67def0a86d
47
tageditor.go
47
tageditor.go
@ -14,6 +14,11 @@ import (
|
|||||||
"github.com/ztrue/tracerr"
|
"github.com/ztrue/tracerr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type myFlex struct {
|
||||||
|
*tview.Flex
|
||||||
|
FocusedItem tview.Primitive
|
||||||
|
}
|
||||||
|
|
||||||
func tagPopup(node *AudioFile) (err error) {
|
func tagPopup(node *AudioFile) (err error) {
|
||||||
|
|
||||||
popupID := "tag-editor-input-popup"
|
popupID := "tag-editor-input-popup"
|
||||||
@ -316,9 +321,16 @@ func tagPopup(node *AudioFile) (err error) {
|
|||||||
rightFlex.SetDirection(tview.FlexColumn).
|
rightFlex.SetDirection(tview.FlexColumn).
|
||||||
AddItem(lyricTextView, 0, 1, true)
|
AddItem(lyricTextView, 0, 1, true)
|
||||||
|
|
||||||
lyricFlex := tview.NewFlex().SetDirection(tview.FlexColumn).
|
// lyricFlex := tview.NewFlex().SetDirection(tview.FlexColumn).
|
||||||
AddItem(leftGrid, 0, 2, true).
|
// AddItem(leftGrid, 0, 2, true).
|
||||||
AddItem(rightFlex, 0, 3, true)
|
// AddItem(rightFlex, 0, 3, true)
|
||||||
|
|
||||||
|
lyricFlex := &myFlex{
|
||||||
|
tview.NewFlex().SetDirection(tview.FlexColumn).
|
||||||
|
AddItem(leftGrid, 0, 2, true).
|
||||||
|
AddItem(rightFlex, 0, 3, true),
|
||||||
|
nil,
|
||||||
|
}
|
||||||
|
|
||||||
lyricFlex.
|
lyricFlex.
|
||||||
SetTitle(node.name).
|
SetTitle(node.name).
|
||||||
@ -350,13 +362,13 @@ func tagPopup(node *AudioFile) (err error) {
|
|||||||
gomu.pages.RemovePage(popupID)
|
gomu.pages.RemovePage(popupID)
|
||||||
gomu.popups.pop()
|
gomu.popups.pop()
|
||||||
case tcell.KeyTab:
|
case tcell.KeyTab:
|
||||||
cycleFocus(gomu.app, inputs, false)
|
lyricFlex.cycleFocus(gomu.app, inputs, false)
|
||||||
case tcell.KeyBacktab:
|
case tcell.KeyBacktab:
|
||||||
cycleFocus(gomu.app, inputs, true)
|
lyricFlex.cycleFocus(gomu.app, inputs, true)
|
||||||
case tcell.KeyRight:
|
case tcell.KeyRight:
|
||||||
cycleFocus(gomu.app, inputs, false)
|
lyricFlex.cycleFocus(gomu.app, inputs, false)
|
||||||
case tcell.KeyLeft:
|
case tcell.KeyLeft:
|
||||||
cycleFocus(gomu.app, inputs, true)
|
lyricFlex.cycleFocus(gomu.app, inputs, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch e.Rune() {
|
switch e.Rune() {
|
||||||
@ -370,7 +382,7 @@ func tagPopup(node *AudioFile) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func cycleFocus(app *tview.Application, elements []tview.Primitive, reverse bool) {
|
func (f *myFlex) cycleFocus(app *tview.Application, elements []tview.Primitive, reverse bool) {
|
||||||
for i, el := range elements {
|
for i, el := range elements {
|
||||||
if !el.HasFocus() {
|
if !el.HasFocus() {
|
||||||
continue
|
continue
|
||||||
@ -387,10 +399,29 @@ func cycleFocus(app *tview.Application, elements []tview.Primitive, reverse bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.SetFocus(elements[i])
|
app.SetFocus(elements[i])
|
||||||
|
f.FocusedItem = elements[i]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *myFlex) Focus(delegate func(p tview.Primitive)) {
|
||||||
|
// if f.FocusedItem != nil {
|
||||||
|
// delegate(f.FocusedItem)
|
||||||
|
// } else {
|
||||||
|
// f.Focus(f.FocusedItem)
|
||||||
|
// }
|
||||||
|
// for _, item := range f.Focus.items {
|
||||||
|
// if item.Item != nil && item.Focus {
|
||||||
|
// delegate(item.Item)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
if f.FocusedItem != nil {
|
||||||
|
gomu.app.SetFocus(f.FocusedItem)
|
||||||
|
} else {
|
||||||
|
f.Flex.Focus(delegate)
|
||||||
|
}
|
||||||
|
}
|
||||||
func loadTagMap(node *AudioFile) (tag *id3v2.Tag, popupLyricMap map[string]string, options []string, err error) {
|
func loadTagMap(node *AudioFile) (tag *id3v2.Tag, popupLyricMap map[string]string, options []string, err error) {
|
||||||
|
|
||||||
popupLyricMap = make(map[string]string)
|
popupLyricMap = make(map[string]string)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user