Skip to content

Commit 0d5b2b7

Browse files
committed
Skip save on open or term command if buffer is shared
1 parent 79fe4ae commit 0d5b2b7

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

internal/action/actions.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,14 +1909,7 @@ func (h *BufPane) ForceQuit() bool {
19091909

19101910
// Quit this will close the current tab or view that is open
19111911
func (h *BufPane) Quit() bool {
1912-
if h.Buf.Modified() {
1913-
for _, b := range buffer.OpenBuffers {
1914-
if b != h.Buf && b.SharedBuffer == h.Buf.SharedBuffer {
1915-
h.ForceQuit()
1916-
return true
1917-
}
1918-
}
1919-
1912+
if h.Buf.Modified() && !h.Buf.Shared() {
19201913
if config.GlobalSettings["autosave"].(float64) > 0 && h.Buf.Path != "" {
19211914
// autosave on means we automatically save when quitting
19221915
h.SaveCB("Quit", func() {

internal/action/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (h *BufPane) OpenCmd(args []string) {
308308
}
309309
h.OpenBuffer(b)
310310
}
311-
if h.Buf.Modified() {
311+
if h.Buf.Modified() && !h.Buf.Shared() {
312312
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
313313
if !canceled && !yes {
314314
open()
@@ -1121,7 +1121,7 @@ func (h *BufPane) TermCmd(args []string) {
11211121

11221122
for i, p := range ps {
11231123
if p.ID() == h.ID() {
1124-
if h.Buf.Modified() {
1124+
if h.Buf.Modified() && !h.Buf.Shared() {
11251125
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
11261126
if !canceled && !yes {
11271127
term(i, false)

internal/buffer/buffer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,16 @@ func (b *Buffer) WordAt(loc Loc) []byte {
620620
return b.Substr(start, end)
621621
}
622622

623+
// Shared returns if there are other buffers with the same file as this buffer
624+
func (b *Buffer) Shared() bool {
625+
for _, buf := range OpenBuffers {
626+
if buf != b && buf.SharedBuffer == b.SharedBuffer {
627+
return true
628+
}
629+
}
630+
return false
631+
}
632+
623633
// Modified returns if this buffer has been modified since
624634
// being opened
625635
func (b *Buffer) Modified() bool {

0 commit comments

Comments
 (0)