mirror of
https://github.com/charmbracelet/glow
synced 2025-03-04 06:47:15 +00:00
parent
400228cff6
commit
597e56bad4
3 changed files with 11 additions and 9 deletions
|
@ -7,11 +7,11 @@ import (
|
|||
|
||||
type editorFinishedMsg struct{ err error }
|
||||
|
||||
func openEditor(path string) tea.Cmd {
|
||||
func openEditor(path string, lineno int) tea.Cmd {
|
||||
cb := func(err error) tea.Msg {
|
||||
return editorFinishedMsg{err}
|
||||
}
|
||||
cmd, err := editor.Cmd("Glow", path)
|
||||
cmd, err := editor.Cmd("Glow", path, editor.OpenAtLine(uint(lineno)))
|
||||
if err != nil {
|
||||
return func() tea.Msg { return cb(err) }
|
||||
}
|
||||
|
|
14
ui/pager.go
14
ui/pager.go
|
@ -196,7 +196,14 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
|||
}
|
||||
|
||||
case "e":
|
||||
return m, openEditor(m.currentDocument.localPath)
|
||||
l := int(math.Round(float64(m.viewport.TotalLineCount()) * m.viewport.ScrollPercent()))
|
||||
if m.viewport.AtTop() {
|
||||
l = 0
|
||||
}
|
||||
if m.viewport.AtBottom() {
|
||||
l = m.viewport.TotalLineCount()
|
||||
}
|
||||
return m, openEditor(m.currentDocument.localPath, l)
|
||||
|
||||
case "c":
|
||||
// Copy using OSC 52
|
||||
|
@ -222,9 +229,6 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
|||
cmds = append(cmds, viewport.Sync(m.viewport))
|
||||
}
|
||||
|
||||
case editMardownMsg:
|
||||
return m, openEditor(msg.md.localPath)
|
||||
|
||||
// We've finished editing the document, potentially making changes. Let's
|
||||
// retrieve the latest version of the document so that we display
|
||||
// up-to-date contents.
|
||||
|
@ -445,5 +449,3 @@ func glamourRender(m pagerModel, markdown string) (string, error) {
|
|||
|
||||
return content.String(), nil
|
||||
}
|
||||
|
||||
type editMardownMsg struct{ md *markdown }
|
||||
|
|
|
@ -519,7 +519,7 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd {
|
|||
// Edit document in EDITOR
|
||||
case "e":
|
||||
md := m.selectedMarkdown()
|
||||
return openEditor(md.localPath)
|
||||
return openEditor(md.localPath, 0)
|
||||
|
||||
// Open document
|
||||
case keyEnter:
|
||||
|
|
Loading…
Add table
Reference in a new issue