mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-24 09:04:18 +02:00
Keep loading stuff in the background while viewing a document
This commit is contained in:
parent
70833af87f
commit
091c3be039
2 changed files with 27 additions and 15 deletions
|
|
@ -302,10 +302,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
|||
cmd = loadRemoteMarkdown(m.cc, md.ID, md.markdownType)
|
||||
}
|
||||
|
||||
cmds = append(cmds,
|
||||
cmd,
|
||||
spinner.Tick(m.spinner),
|
||||
)
|
||||
cmds = append(cmds, cmd, spinner.Tick(m.spinner))
|
||||
|
||||
// Set note
|
||||
case "m":
|
||||
|
|
|
|||
37
ui/ui.go
37
ui/ui.go
|
|
@ -185,17 +185,24 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
|
||||
// Special cases for the pager
|
||||
case stateShowDocument:
|
||||
var cmds []tea.Cmd
|
||||
if m.pager.state == pagerStateBrowse {
|
||||
// If the user is just browing a document, exit the pager.
|
||||
m.unloadDocument()
|
||||
if m.pager.viewport.HighPerformanceRendering {
|
||||
cmd = tea.ClearScrollArea
|
||||
cmds = append(cmds, tea.ClearScrollArea)
|
||||
}
|
||||
if !m.stash.loaded.done() || m.stash.loadingFromNetwork {
|
||||
cmds = append(cmds, spinner.Tick(m.stash.spinner))
|
||||
}
|
||||
} else {
|
||||
// Otherwise send keys through to pager for processing
|
||||
m.pager, cmd = pagerUpdate(msg, m.pager)
|
||||
// Otherwise send these key messages through to pager for
|
||||
// processing
|
||||
newPagerModel, cmd := pagerUpdate(msg, m.pager)
|
||||
m.pager = newPagerModel
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
return m, cmd
|
||||
return m, tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
return m, tea.Quit
|
||||
|
|
@ -274,13 +281,6 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
m.pager.cc = msg
|
||||
cmds = append(cmds, loadStash(m.stash), loadNews(m.stash))
|
||||
|
||||
case noteSavedMsg:
|
||||
// A note was saved to a document. This will have be done in the
|
||||
// pager, so we'll need to find the corresponding note in the stash.
|
||||
// So, pass the message to the stash for processing.
|
||||
m.stash, cmd = stashUpdate(msg, m.stash)
|
||||
cmds = append(cmds, cmd)
|
||||
|
||||
case fetchedMarkdownMsg:
|
||||
m.pager.currentDocument = msg
|
||||
cmds = append(cmds, renderWithGlamour(m.pager, msg.Body))
|
||||
|
|
@ -288,6 +288,21 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
case contentRenderedMsg:
|
||||
m.state = stateShowDocument
|
||||
|
||||
case noteSavedMsg:
|
||||
// A note was saved to a document. This will have be done in the
|
||||
// pager, so we'll need to find the corresponding note in the stash.
|
||||
// So, pass the message to the stash for processing.
|
||||
stashModel, cmd := stashUpdate(msg, m.stash)
|
||||
m.stash = stashModel
|
||||
return m, cmd
|
||||
|
||||
case localFileSearchFinished, gotStashMsg, gotNewsMsg:
|
||||
// Also pass these messages to the stash so we can keep it updated
|
||||
// about network activity.
|
||||
stashModel, cmd := stashUpdate(msg, m.stash)
|
||||
m.stash = stashModel
|
||||
return m, cmd
|
||||
|
||||
}
|
||||
|
||||
// Process children
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue