mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 06:04:18 +00:00
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.
This commit is contained in:
parent
d98e3c11ba
commit
58eca2414a
3 changed files with 14 additions and 13 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
10
ui/stash.go
10
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.
|
||||
|
|
16
ui/ui.go
16
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 == "" {
|
||||
|
|
Loading…
Reference in a new issue