feat: add search with preview
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"playback/internal/ui"
|
||||
"playback/internal/ui/header"
|
||||
"playback/internal/ui/legend"
|
||||
"playback/internal/ui/search"
|
||||
"playback/internal/ui/transcript"
|
||||
"playback/internal/ui/waveform"
|
||||
)
|
||||
@@ -37,6 +38,7 @@ type Model struct {
|
||||
legend legend.Model
|
||||
waveform waveform.Model
|
||||
transcript transcript.Model
|
||||
search search.Model
|
||||
|
||||
// State
|
||||
showHelp bool
|
||||
@@ -61,6 +63,7 @@ func New(audioPath, transcriptPath string) Model {
|
||||
legend: legend.New(),
|
||||
waveform: waveform.New(),
|
||||
transcript: transcript.New(),
|
||||
search: search.New(),
|
||||
}
|
||||
|
||||
return m
|
||||
@@ -138,6 +141,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.updateLayout()
|
||||
|
||||
case tea.KeyMsg:
|
||||
// Search overlay takes priority
|
||||
if m.search.IsOpen() {
|
||||
cmd := m.search.Update(msg)
|
||||
cmds = append(cmds, cmd)
|
||||
return m, tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
// All shortcuts are now global
|
||||
switch {
|
||||
case key.Matches(msg, m.keys.Quit):
|
||||
@@ -168,6 +178,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case key.Matches(msg, m.keys.SeekBackwardBig):
|
||||
m.player.SeekRelative(-m.config.BigSeekStep)
|
||||
|
||||
case key.Matches(msg, m.keys.Search):
|
||||
cmd := m.search.Open(m.transcript.AllCues())
|
||||
cmds = append(cmds, cmd)
|
||||
|
||||
// Transcript navigation and other keys forward to transcript
|
||||
default:
|
||||
cmd := m.transcript.Update(msg)
|
||||
@@ -211,6 +225,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
case transcript.SeekToCueMsg:
|
||||
m.player.Seek(msg.Position)
|
||||
|
||||
case search.SeekToSearchResultMsg:
|
||||
m.player.Seek(msg.Position)
|
||||
}
|
||||
|
||||
return m, tea.Batch(cmds...)
|
||||
@@ -247,6 +264,7 @@ func (m *Model) updateLayout() {
|
||||
m.legend.SetWidth(m.width)
|
||||
m.waveform.SetSize(m.width, waveformHeight)
|
||||
m.transcript.SetSize(m.width, transcriptHeight)
|
||||
m.search.SetSize(m.width, m.height)
|
||||
}
|
||||
|
||||
func (m Model) launchEditor() tea.Cmd {
|
||||
@@ -285,6 +303,10 @@ func (m Model) View() string {
|
||||
return m.renderHelp()
|
||||
}
|
||||
|
||||
if m.search.IsOpen() {
|
||||
return m.search.View()
|
||||
}
|
||||
|
||||
// Header
|
||||
headerView := m.header.View(m.player.Position(), m.player.Duration(), m.player.IsPlaying())
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ type KeyMap struct {
|
||||
|
||||
// Editing
|
||||
EnterEdit key.Binding
|
||||
|
||||
// Search
|
||||
Search key.Binding
|
||||
}
|
||||
|
||||
// DefaultKeyMap returns the default keybindings
|
||||
@@ -84,6 +87,10 @@ func DefaultKeyMap() KeyMap {
|
||||
key.WithKeys("i"),
|
||||
key.WithHelp("i", "edit transcript"),
|
||||
),
|
||||
Search: key.NewBinding(
|
||||
key.WithKeys("s"),
|
||||
key.WithHelp("s", "search cues"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,5 +116,8 @@ Navigation (Global):
|
||||
G Go to last cue
|
||||
|
||||
Editing:
|
||||
i Edit in $EDITOR at cue`
|
||||
i Edit in $EDITOR at cue
|
||||
|
||||
Navigation:
|
||||
s Search cues`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user