forked from varia/go-sh-manymanuals
refactor: set viewport function
This commit is contained in:
parent
b5fa63d18f
commit
40f6c0c234
28
gshmm.go
28
gshmm.go
@ -275,6 +275,16 @@ func filterDatasheetNames(m model) []string {
|
||||
return m.datasheetNames
|
||||
}
|
||||
|
||||
// setViewport sets the viewport content.
|
||||
func (m *model) setViewport() {
|
||||
if len(m.filteredDatasheets) == 0 {
|
||||
return
|
||||
}
|
||||
lastDatasheet := m.filteredDatasheets[len(m.filteredDatasheets)-1]
|
||||
viewportText := m.datasheetFromName(lastDatasheet)
|
||||
m.datasheetViewport.SetContent(viewportText)
|
||||
}
|
||||
|
||||
// Update updates the program state.
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var (
|
||||
@ -291,19 +301,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.loadDatasheetSpinner, cmd = m.loadDatasheetSpinner.Update(msg)
|
||||
cmds = append(cmds, cmd)
|
||||
|
||||
// TODO: implement cursor for scrolling up/down filtered
|
||||
// results so we can view the PDF contents as desired
|
||||
// it's currently just the last one (closest to input)
|
||||
if m.input.Focused() && m.datasheetsLoaded {
|
||||
if m.filterMode == filenameFilterMode {
|
||||
m.filteredDatasheets = filterDatasheetNames(m)
|
||||
} else {
|
||||
m.filteredDatasheets = filterDatasheetContents(m)
|
||||
}
|
||||
|
||||
// TODO: implement cursor for scrolling up/down filtered
|
||||
// results so we can view the PDF contents as desired
|
||||
// it's currently just the last one (closest to input)
|
||||
lastDatasheet := m.filteredDatasheets[len(m.filteredDatasheets)-1]
|
||||
viewportText := m.datasheetFromName(lastDatasheet)
|
||||
m.datasheetViewport.SetContent(viewportText)
|
||||
m.setViewport()
|
||||
}
|
||||
|
||||
switch msg := msg.(type) {
|
||||
@ -311,10 +318,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.datasheets = msg.datasheets
|
||||
m.datasheetNames = msg.datasheetNames
|
||||
m.filteredDatasheets = msg.datasheetNames
|
||||
|
||||
selectedDatasheet := msg.datasheets[len(msg.datasheets)-1]
|
||||
m.datasheetViewport.SetContent(selectedDatasheet.contents)
|
||||
|
||||
m.setViewport()
|
||||
m.datasheetsLoaded = true
|
||||
case peerDiscoveredMsg:
|
||||
m.peers = msg.discovered
|
||||
@ -328,6 +332,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, tea.Quit
|
||||
case "tab":
|
||||
m.toggleFilterMode()
|
||||
case "enter":
|
||||
// TODO: fire content search query
|
||||
case "o":
|
||||
selectedDatasheet := m.datasheets[len(m.datasheets)-1]
|
||||
// TODO: handle error
|
||||
|
Loading…
Reference in New Issue
Block a user