summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaas Lalani <maas@lalani.dev>2023-01-19 14:13:41 -0500
committerGitHub <noreply@github.com>2023-01-19 14:13:41 -0500
commit6ba2683628077ce04e085ac24e95ea071692c2eb (patch)
treede6f995815e6e46ff21b09d01cfd5f14f2f505f9
parentdd1593b10dbd0602e7eb1e00774c4da9aa837b23 (diff)
Show edit help when editable (#442)
* fix: only show edit help on pager when editable * fix: only allow `LocalDoc`s to be edited * feat: show e • edit help when document is editable
-rw-r--r--ui/pager.go7
-rw-r--r--ui/stash.go2
-rw-r--r--ui/stashhelp.go11
3 files changed, 16 insertions, 4 deletions
diff --git a/ui/pager.go b/ui/pager.go
index 575adc0..0cebdd9 100644
--- a/ui/pager.go
+++ b/ui/pager.go
@@ -528,10 +528,15 @@ func (m pagerModel) helpView() (s string) {
memoOrStash = "s stash this document"
}
+ editOrBlank := "e edit this document"
+ if m.currentDocument.docType != LocalDoc || m.currentDocument.localPath == "" {
+ editOrBlank = ""
+ }
+
col1 := []string{
"g/home go to top",
"G/end go to bottom",
- "e edit this document",
+ editOrBlank,
memoOrStash,
"esc back to files",
"q quit",
diff --git a/ui/stash.go b/ui/stash.go
index a017911..7b69d1a 100644
--- a/ui/stash.go
+++ b/ui/stash.go
@@ -764,7 +764,7 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd {
// Edit document in EDITOR
case "e":
md := m.selectedMarkdown()
- if md == nil {
+ if md == nil || md.docType != LocalDoc {
break
}
file := m.selectedMarkdown().localPath
diff --git a/ui/stashhelp.go b/ui/stashhelp.go
index 8ab9c22..18f1dcf 100644
--- a/ui/stashhelp.go
+++ b/ui/stashhelp.go
@@ -110,9 +110,11 @@ func (m stashModel) helpView() (string, int) {
var (
isStashed bool
isStashable bool
+ isEditable bool
navHelp []string
filterHelp []string
selectionHelp []string
+ editHelp []string
sectionHelp []string
appHelp []string
)
@@ -121,6 +123,7 @@ func (m stashModel) helpView() (string, int) {
md := m.selectedMarkdown()
isStashed = md != nil && md.docType == StashedDoc
isStashable = md != nil && md.docType == LocalDoc && m.online()
+ isEditable = md != nil && md.docType == LocalDoc && md.localPath != ""
}
if numDocs > 0 && m.showFullHelp {
@@ -152,6 +155,10 @@ func (m stashModel) helpView() (string, int) {
selectionHelp = []string{"s", "stash"}
}
+ if isEditable {
+ editHelp = []string{"e", "edit"}
+ }
+
// If there are errors
if m.err != nil {
appHelp = append(appHelp, "!", "errors")
@@ -164,14 +171,14 @@ func (m stashModel) helpView() (string, int) {
if m.filterState != filtering {
appHelp = append(appHelp, "?", "close help")
}
- return m.renderHelp(navHelp, filterHelp, selectionHelp, sectionHelp, appHelp)
+ return m.renderHelp(navHelp, filterHelp, append(selectionHelp, editHelp...), sectionHelp, appHelp)
}
// Mini help
if m.filterState != filtering {
appHelp = append(appHelp, "?", "more")
}
- return m.renderHelp(navHelp, filterHelp, selectionHelp, sectionHelp, appHelp)
+ return m.renderHelp(navHelp, filterHelp, selectionHelp, editHelp, sectionHelp, appHelp)
}
// renderHelp returns the rendered help view and associated line height for