mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-18 14:19:11 +02:00
Also exit the pager with left arrow, h and delete/backspace
This commit is contained in:
parent
45163be06f
commit
d941957b92
2 changed files with 21 additions and 15 deletions
|
|
@ -179,9 +179,7 @@ func pagerUpdate(msg tea.Msg, m pagerModel) (pagerModel, tea.Cmd) {
|
|||
}
|
||||
default:
|
||||
switch msg.String() {
|
||||
case "q":
|
||||
fallthrough
|
||||
case "esc":
|
||||
case "q", "esc":
|
||||
if m.state != pagerStateBrowse {
|
||||
m.state = pagerStateBrowse
|
||||
return m, nil
|
||||
|
|
@ -194,7 +192,7 @@ func pagerUpdate(msg tea.Msg, m pagerModel) (pagerModel, tea.Cmd) {
|
|||
|
||||
m.state = pagerStateSetNote
|
||||
if m.textInput.Value() == "" {
|
||||
// Pre-populate with existing value
|
||||
// Pre-populate note with existing value
|
||||
m.textInput.SetValue(m.currentDocument.Note)
|
||||
m.textInput.CursorEnd()
|
||||
}
|
||||
|
|
|
|||
30
ui/ui.go
30
ui/ui.go
|
|
@ -104,11 +104,22 @@ type model struct {
|
|||
localFileFinder chan gitcha.SearchResult
|
||||
}
|
||||
|
||||
func (m *model) unloadDocument() {
|
||||
// unloadDocument unloads a document from the pager. Note that while this
|
||||
// method alters the model we also need to send along any commands returned.
|
||||
func (m *model) unloadDocument() []tea.Cmd {
|
||||
m.state = stateShowStash
|
||||
m.stash.state = stashStateReady
|
||||
m.pager.unload()
|
||||
m.pager.showHelp = false
|
||||
|
||||
var batch []tea.Cmd
|
||||
if m.pager.viewport.HighPerformanceRendering {
|
||||
batch = append(batch, tea.ClearScrollArea)
|
||||
}
|
||||
if !m.stash.loaded.done() || m.stash.loadingFromNetwork {
|
||||
batch = append(batch, spinner.Tick(m.stash.spinner))
|
||||
}
|
||||
return batch
|
||||
}
|
||||
|
||||
// INIT
|
||||
|
|
@ -161,9 +172,7 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "q":
|
||||
fallthrough
|
||||
case "esc":
|
||||
case "q", "esc":
|
||||
var cmd tea.Cmd
|
||||
|
||||
// Send these keys through to stash
|
||||
|
|
@ -181,13 +190,7 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
var batch []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 {
|
||||
batch = append(batch, tea.ClearScrollArea)
|
||||
}
|
||||
if !m.stash.loaded.done() || m.stash.loadingFromNetwork {
|
||||
batch = append(batch, spinner.Tick(m.stash.spinner))
|
||||
}
|
||||
batch = m.unloadDocument()
|
||||
} else {
|
||||
// Otherwise send these key messages through to pager for
|
||||
// processing
|
||||
|
|
@ -200,6 +203,11 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
|||
|
||||
return m, tea.Quit
|
||||
|
||||
case "left", "h", "delete":
|
||||
if m.state == stateShowDocument && m.pager.state == pagerStateBrowse {
|
||||
cmds = append(cmds, m.unloadDocument()...)
|
||||
}
|
||||
|
||||
// Ctrl+C always quits no matter where in the application you are.
|
||||
case "ctrl+c":
|
||||
return m, tea.Quit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue