mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 14:14:17 +00:00
If a file is currently mid-stash don't let the user stash it again
This commit is contained in:
parent
2907abd351
commit
6e36891857
2 changed files with 19 additions and 3 deletions
|
@ -261,6 +261,7 @@ func pagerUpdate(msg tea.Msg, m pagerModel) (pagerModel, tea.Cmd) {
|
|||
// that of a stashed document, but don't re-render since the body is
|
||||
// identical to what's already rendered.
|
||||
m.currentDocument = markdown(msg)
|
||||
m.currentDocument.localPath = ""
|
||||
|
||||
// Show a success message to the user.
|
||||
m.state = pagerStateStatusMessage
|
||||
|
@ -485,7 +486,6 @@ func stashDocument(cc *charm.Client, md markdown) tea.Cmd {
|
|||
// Set the note as the filename without the extension
|
||||
p := md.localPath
|
||||
md.Note = strings.Replace(path.Base(p), path.Ext(p), "", 1)
|
||||
md.localPath = ""
|
||||
|
||||
newMd, err := cc.StashMarkdown(md.Note, md.Body)
|
||||
if err != nil {
|
||||
|
|
20
ui/stash.go
20
ui/stash.go
|
@ -128,6 +128,9 @@ type stashModel struct {
|
|||
loadingFromNetwork bool // are we currently loading something from the network?
|
||||
loaded loadedState // what's loaded? we find out with bitmasking
|
||||
|
||||
// Paths to files being stashed. We treat this like a set.
|
||||
filesStashing map[string]struct{}
|
||||
|
||||
// This is just the index of the current page in view. To get the index
|
||||
// of the selected item as it relates to the full set of documents we've
|
||||
// fetched use the mardownIndex() method of this struct.
|
||||
|
@ -231,6 +234,7 @@ func newStashModel() stashModel {
|
|||
page: 1,
|
||||
paginator: p,
|
||||
loadingFromNetwork: true,
|
||||
filesStashing: make(map[string]struct{}),
|
||||
}
|
||||
|
||||
return m
|
||||
|
@ -304,6 +308,8 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
|||
// Something was stashed. Add it to the stash listing.
|
||||
case stashSuccessMsg:
|
||||
md := markdown(msg)
|
||||
delete(m.filesStashing, md.localPath) // remove from the things-we're-stashing list
|
||||
md.localPath = ""
|
||||
m.addMarkdowns(&md)
|
||||
|
||||
m.showStatusMessage = true
|
||||
|
@ -392,10 +398,20 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
|||
// Stash
|
||||
case "s":
|
||||
md := m.selectedMarkdown()
|
||||
if md != nil && md.markdownType == localMarkdown {
|
||||
cmds = append(cmds, stashDocument(m.cc, *md))
|
||||
if md == nil {
|
||||
break
|
||||
}
|
||||
|
||||
// if we're busy stashing this don't do it again
|
||||
_, exists := m.filesStashing[md.localPath]
|
||||
|
||||
if exists || md.markdownType != localMarkdown || md.localPath == "" {
|
||||
break
|
||||
}
|
||||
|
||||
m.filesStashing[md.localPath] = struct{}{}
|
||||
cmds = append(cmds, stashDocument(m.cc, *md))
|
||||
|
||||
// Prompt for deletion
|
||||
case "x":
|
||||
m.hideStatusMessage()
|
||||
|
|
Loading…
Reference in a new issue