From 58eca2414aeb626b52c909e4ae445a4cac662e32 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 16 Nov 2020 18:32:14 -0500 Subject: [PATCH] Match documents which were stashed in-session then renamed Note that we've also removed field `displayPath` from struct `markdown` as it turned out to not be necssary in the first place. --- ui/markdown.go | 1 - ui/stash.go | 10 ++++------ ui/ui.go | 16 ++++++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ui/markdown.go b/ui/markdown.go index f8ca91c..9f924bf 100644 --- a/ui/markdown.go +++ b/ui/markdown.go @@ -21,7 +21,6 @@ const ( type markdown struct { markdownType markdownType localPath string // only relevant to local files and converted files that are newly stashed - displayPath string // what we show in the note field charm.Markdown } diff --git a/ui/stash.go b/ui/stash.go index 71fd02c..2325ac6 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -68,6 +68,7 @@ const ( type stashModel struct { cc *charm.Client cfg *Config + cwd string authStatus authStatus state stashState err error @@ -231,13 +232,10 @@ func (m *stashModel) getNotes() []*markdown { for _, t := range m.markdowns { note := "" - switch t.markdownType { - case newsMarkdown: + if t.markdownType == newsMarkdown { note = "News: " + t.Note - case stashedMarkdown: + } else { note = t.Note - default: - note = t.displayPath } targets = append(targets, note) @@ -624,7 +622,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { // If document was stashed during this session, convert it // back to a local file. md.markdownType = localMarkdown - md.Note = m.markdowns[i].displayPath + md.Note = stripAbsolutePath(m.markdowns[i].localPath, m.cwd) } else { // Delete optimistically and remove the stashed item // before we've received a success response. diff --git a/ui/ui.go b/ui/ui.go index fe37f08..b8a83c8 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -317,6 +317,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case initLocalFileSearchMsg: m.localFileFinder = msg.ch m.cwd = msg.cwd + m.stash.cwd = msg.cwd cmds = append(cmds, findNextLocalFile(m)) case foundLocalFileMsg: @@ -379,7 +380,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.state = stateShowDocument case noteSavedMsg: - // A note was saved to a document. This will have be done in the + // A note was saved to a document. This will have been 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) @@ -665,16 +666,19 @@ func localFileToMarkdown(cwd string, res gitcha.SearchResult) *markdown { md := &markdown{ markdownType: localMarkdown, localPath: res.Path, - displayPath: strings.Replace(res.Path, cwd+string(os.PathSeparator), "", -1), // strip absolute path - Markdown: charm.Markdown{}, + Markdown: charm.Markdown{ + Note: stripAbsolutePath(res.Path, cwd), + CreatedAt: res.Info.ModTime(), + }, } - md.Markdown.Note = md.displayPath - md.CreatedAt = res.Info.ModTime() // last modified time - return md } +func stripAbsolutePath(fullPath, cwd string) string { + return strings.Replace(fullPath, cwd+string(os.PathSeparator), "", -1) +} + // Lightweight version of reflow's indent function. func indent(s string, n int) string { if n <= 0 || s == "" {