Skip to content

Commit 293f0e6

Browse files
Merge branch 'master' into dev
2 parents 40beb3d + 98ff79d commit 293f0e6

File tree

14 files changed

+130
-116
lines changed

14 files changed

+130
-116
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/mattn/go-runewidth v0.0.16
1010
github.com/micro-editor/json5 v1.0.1-micro
1111
github.com/micro-editor/tcell/v2 v2.0.11
12-
github.com/micro-editor/terminal v0.0.0-20250105114944-ffd0fc59e777
12+
github.com/micro-editor/terminal v0.0.0-20250324214352-e587e959c6b5
1313
github.com/mitchellh/go-homedir v1.1.0
1414
github.com/sergi/go-diff v1.1.0
1515
github.com/stretchr/testify v1.4.0
@@ -29,7 +29,7 @@ require (
2929
github.com/pmezard/go-difflib v1.0.0 // indirect
3030
github.com/rivo/uniseg v0.2.0 // indirect
3131
github.com/zyedidia/poller v1.0.1 // indirect
32-
golang.org/x/sys v0.6.0 // indirect
32+
golang.org/x/sys v0.28.0 // indirect
3333
)
3434

3535
replace github.com/kballard/go-shellquote => github.com/micro-editor/go-shellquote v0.0.0-20250101105543-feb6c39314f5

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ github.com/micro-editor/json5 v1.0.1-micro h1:5Y4MuzhkmW0sQQNPvrIVevIOKi557qsznw
3535
github.com/micro-editor/json5 v1.0.1-micro/go.mod h1:cmlPHZ1JKOXNse0/3zwwKj/GUpzAVkzx4lZDkpHl4q0=
3636
github.com/micro-editor/tcell/v2 v2.0.11 h1:USjdpBSmbocx2yPARbY19KcUSj+ZerScrdmBqGjzoX4=
3737
github.com/micro-editor/tcell/v2 v2.0.11/go.mod h1:kVYk6NOwYJrboL/7IA7cCupk4o2NzyF/0UMLjeEJN/s=
38-
github.com/micro-editor/terminal v0.0.0-20250105114944-ffd0fc59e777 h1:ddEDJwVqnxd8Yxtr6ZlUBBH3Kyf90jLHMJAbmU1bjuA=
39-
github.com/micro-editor/terminal v0.0.0-20250105114944-ffd0fc59e777/go.mod h1:soCc8JsxxfCZd3y08pX67F16Bni5L/xtcAnqEswzs44=
38+
github.com/micro-editor/terminal v0.0.0-20250324214352-e587e959c6b5 h1:czSkYUNmHuWS2lv8VreufENEXZNOCGZcXd744YKf8yM=
39+
github.com/micro-editor/terminal v0.0.0-20250324214352-e587e959c6b5/go.mod h1:OszIG7ockt4osicVHq6gI2QmV4PBDK6H5/Bj8GDGv4Q=
4040
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
4141
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
4242
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -61,8 +61,9 @@ github.com/zyedidia/poller v1.0.1 h1:Tt9S3AxAjXwWGNiC2TUdRJkQDZSzCBNVQ4xXiQ7440s
6161
github.com/zyedidia/poller v1.0.1/go.mod h1:vZXJOHGDcuK08GXhF6IAY0ZFd2WcgOR5DOTp84Uk5eE=
6262
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
6363
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
64-
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
6564
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
65+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
66+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
6667
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6768
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
6869
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=

internal/action/actions.go

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,28 @@ func (h *BufPane) MousePress(e *tcell.EventMouse) bool {
7373
h.Cursor.Loc = mouseLoc
7474
}
7575
if time.Since(h.lastClickTime)/time.Millisecond < config.DoubleClickThreshold && (mouseLoc.X == h.lastLoc.X && mouseLoc.Y == h.lastLoc.Y) {
76-
if h.doubleClick {
76+
if h.DoubleClick {
7777
// Triple click
7878
h.lastClickTime = time.Now()
7979

80-
h.tripleClick = true
81-
h.doubleClick = false
80+
h.TripleClick = true
81+
h.DoubleClick = false
8282

8383
h.Cursor.SelectLine()
8484
h.Cursor.CopySelection(clipboard.PrimaryReg)
8585
} else {
8686
// Double click
8787
h.lastClickTime = time.Now()
8888

89-
h.doubleClick = true
90-
h.tripleClick = false
89+
h.DoubleClick = true
90+
h.TripleClick = false
9191

9292
h.Cursor.SelectWord()
9393
h.Cursor.CopySelection(clipboard.PrimaryReg)
9494
}
9595
} else {
96-
h.doubleClick = false
97-
h.tripleClick = false
96+
h.DoubleClick = false
97+
h.TripleClick = false
9898
h.lastClickTime = time.Now()
9999

100100
h.Cursor.OrigSelection[0] = h.Cursor.Loc
@@ -116,9 +116,9 @@ func (h *BufPane) MouseDrag(e *tcell.EventMouse) bool {
116116
}
117117
h.Cursor.Loc = h.LocFromVisual(buffer.Loc{mx, my})
118118

119-
if h.tripleClick {
119+
if h.TripleClick {
120120
h.Cursor.AddLineToSelection()
121-
} else if h.doubleClick {
121+
} else if h.DoubleClick {
122122
h.Cursor.AddWordToSelection()
123123
} else {
124124
h.Cursor.SelectTo(h.Cursor.Loc)
@@ -135,7 +135,7 @@ func (h *BufPane) MouseRelease(e *tcell.EventMouse) bool {
135135
// that doesn't support mouse motion events. But when the mouse click is
136136
// within the scroll margin, that would cause a scroll and selection
137137
// even for a simple mouse click, which is not good.
138-
// if !h.doubleClick && !h.tripleClick {
138+
// if !h.DoubleClick && !h.TripleClick {
139139
// mx, my := e.Position()
140140
// h.Cursor.Loc = h.LocFromVisual(buffer.Loc{mx, my})
141141
// h.Cursor.SetSelectionEnd(h.Cursor.Loc)
@@ -153,7 +153,7 @@ func (h *BufPane) ScrollUpAction() bool {
153153
return true
154154
}
155155

156-
// ScrollDownAction scrolls the view up
156+
// ScrollDownAction scrolls the view down
157157
func (h *BufPane) ScrollDownAction() bool {
158158
h.ScrollDown(util.IntOpt(h.Buf.Settings["scrollspeed"]))
159159
return true
@@ -1925,30 +1925,29 @@ func (h *BufPane) ForceQuit() bool {
19251925
return true
19261926
}
19271927

1928-
// Quit this will close the current tab or view that is open
1929-
func (h *BufPane) Quit() bool {
1930-
if h.Buf.Modified() {
1931-
for _, b := range buffer.OpenBuffers {
1932-
if b != h.Buf && b.SharedBuffer == h.Buf.SharedBuffer {
1933-
h.ForceQuit()
1934-
return true
1935-
}
1928+
// closePrompt displays a prompt to save the buffer before closing it to proceed
1929+
// with a different action or command
1930+
func (h *BufPane) closePrompt(action string, callback func()) {
1931+
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
1932+
if !canceled && !yes {
1933+
callback()
1934+
} else if !canceled && yes {
1935+
h.SaveCB(action, callback)
19361936
}
1937+
})
1938+
}
19371939

1940+
// Quit this will close the current tab or view that is open
1941+
func (h *BufPane) Quit() bool {
1942+
if h.Buf.Modified() && !h.Buf.Shared() {
19381943
if config.GlobalSettings["autosave"].(float64) > 0 && h.Buf.Path != "" {
19391944
// autosave on means we automatically save when quitting
19401945
h.SaveCB("Quit", func() {
19411946
h.ForceQuit()
19421947
})
19431948
} else {
1944-
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
1945-
if !canceled && !yes {
1946-
h.ForceQuit()
1947-
} else if !canceled && yes {
1948-
h.SaveCB("Quit", func() {
1949-
h.ForceQuit()
1950-
})
1951-
}
1949+
h.closePrompt("Quit", func() {
1950+
h.ForceQuit()
19521951
})
19531952
}
19541953
} else {

internal/action/bufpane.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ type BufPane struct {
236236
// Was the last mouse event actually a double click?
237237
// Useful for detecting triple clicks -- if a double click is detected
238238
// but the last mouse event was actually a double click, it's a triple click
239-
doubleClick bool
239+
DoubleClick bool
240240
// Same here, just to keep track for mouse move events
241-
tripleClick bool
241+
TripleClick bool
242242

243243
// Should the current multiple cursor selection search based on word or
244244
// based on selection (false for selection, true for word)

internal/action/command.go

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,8 @@ func (h *BufPane) OpenCmd(args []string) {
332332
}
333333
h.OpenBuffer(b)
334334
}
335-
if h.Buf.Modified() {
336-
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
337-
if !canceled && !yes {
338-
open()
339-
} else if !canceled && yes {
340-
h.Save()
341-
open()
342-
}
343-
})
335+
if h.Buf.Modified() && !h.Buf.Shared() {
336+
h.closePrompt("Save", open)
344337
} else {
345338
open()
346339
}
@@ -1107,10 +1100,42 @@ func (h *BufPane) ReplaceAllCmd(args []string) {
11071100
h.ReplaceCmd(append(args, "-a"))
11081101
}
11091102

1103+
func (h *BufPane) openTerm(args []string, newtab bool) {
1104+
t := new(shell.Terminal)
1105+
err := t.Start(args, false, true, nil, nil)
1106+
if err != nil {
1107+
InfoBar.Error(err)
1108+
return
1109+
}
1110+
1111+
pane := 0
1112+
id := h.ID()
1113+
if newtab {
1114+
h.AddTab()
1115+
id = MainTab().Panes[pane].ID()
1116+
} else {
1117+
for i, p := range MainTab().Panes {
1118+
if p.IsActive() {
1119+
pane = i
1120+
id = p.ID()
1121+
p.Close()
1122+
break
1123+
}
1124+
}
1125+
}
1126+
1127+
v := h.GetView()
1128+
tp, err := NewTermPane(v.X, v.Y, v.Width, v.Height, t, id, MainTab())
1129+
if err != nil {
1130+
InfoBar.Error(err)
1131+
return
1132+
}
1133+
MainTab().Panes[pane] = tp
1134+
MainTab().SetActive(pane)
1135+
}
1136+
11101137
// TermCmd opens a terminal in the current view
11111138
func (h *BufPane) TermCmd(args []string) {
1112-
ps := h.tab.Panes
1113-
11141139
if !TermEmuSupported {
11151140
InfoBar.Error("Terminal emulator not supported on this system")
11161141
return
@@ -1125,56 +1150,19 @@ func (h *BufPane) TermCmd(args []string) {
11251150
args = []string{sh}
11261151
}
11271152

1128-
term := func(i int, newtab bool) {
1129-
t := new(shell.Terminal)
1130-
err := t.Start(args, false, true, nil, nil)
1131-
if err != nil {
1132-
InfoBar.Error(err)
1133-
return
1134-
}
1135-
1136-
id := h.ID()
1137-
if newtab {
1138-
h.AddTab()
1139-
i = 0
1140-
id = MainTab().Panes[0].ID()
1141-
} else {
1142-
MainTab().Panes[i].Close()
1143-
}
1144-
1145-
v := h.GetView()
1146-
tp, err := NewTermPane(v.X, v.Y, v.Width, v.Height, t, id, MainTab())
1147-
if err != nil {
1148-
InfoBar.Error(err)
1149-
return
1150-
}
1151-
MainTab().Panes[i] = tp
1152-
MainTab().SetActive(i)
1153-
}
1154-
11551153
// If there is only one open file we make a new tab instead of overwriting it
11561154
newtab := len(MainTab().Panes) == 1 && len(Tabs.List) == 1
1157-
11581155
if newtab {
1159-
term(0, true)
1156+
h.openTerm(args, true)
11601157
return
11611158
}
11621159

1163-
for i, p := range ps {
1164-
if p.ID() == h.ID() {
1165-
if h.Buf.Modified() {
1166-
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
1167-
if !canceled && !yes {
1168-
term(i, false)
1169-
} else if !canceled && yes {
1170-
h.Save()
1171-
term(i, false)
1172-
}
1173-
})
1174-
} else {
1175-
term(i, false)
1176-
}
1177-
}
1160+
if h.Buf.Modified() && !h.Buf.Shared() {
1161+
h.closePrompt("Save", func() {
1162+
h.openTerm(args, false)
1163+
})
1164+
} else {
1165+
h.openTerm(args, false)
11781166
}
11791167
}
11801168

internal/action/terminal_supported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux || darwin || dragonfly || openbsd_amd64 || freebsd
1+
//go:build linux || darwin || dragonfly || solaris || openbsd || netbsd || freebsd
22

33
package action
44

internal/action/terminal_unsupported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !linux && !darwin && !freebsd && !dragonfly && !openbsd_amd64
1+
//go:build plan9 || nacl || windows
22

33
package action
44

internal/buffer/buffer.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"io"
1010
"io/fs"
1111
"os"
12-
"path"
1312
"path/filepath"
1413
"strconv"
1514
"strings"
@@ -480,7 +479,7 @@ func (b *Buffer) GetName() string {
480479
name = b.Path
481480
}
482481
if b.Settings["basename"].(bool) {
483-
return path.Base(name)
482+
return filepath.Base(name)
484483
}
485484
return name
486485
}
@@ -621,6 +620,16 @@ func (b *Buffer) WordAt(loc Loc) []byte {
621620
return b.Substr(start, end)
622621
}
623622

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+
624633
// Modified returns if this buffer has been modified since
625634
// being opened
626635
func (b *Buffer) Modified() bool {

internal/config/rtfiles.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"log"
66
"os"
7-
"path"
87
"path/filepath"
98
"regexp"
109
"strings"
@@ -84,8 +83,8 @@ func (rf realFile) Data() ([]byte, error) {
8483
}
8584

8685
func (af assetFile) Name() string {
87-
fn := path.Base(string(af))
88-
return fn[:len(fn)-len(path.Ext(fn))]
86+
fn := filepath.Base(string(af))
87+
return fn[:len(fn)-len(filepath.Ext(fn))]
8988
}
9089

9190
func (af assetFile) Data() ([]byte, error) {
@@ -125,8 +124,8 @@ func AddRuntimeFilesFromAssets(fileType RTFiletype, directory, pattern string) {
125124

126125
assetLoop:
127126
for _, f := range files {
128-
if ok, _ := path.Match(pattern, f); ok {
129-
af := assetFile(path.Join(directory, f))
127+
if ok, _ := filepath.Match(pattern, f); ok {
128+
af := assetFile(filepath.Join(directory, f))
130129
for _, rf := range realFiles[fileType] {
131130
if af.Name() == rf.Name() {
132131
continue assetLoop
@@ -167,7 +166,7 @@ func InitRuntimeFiles(user bool) {
167166
if user {
168167
AddRuntimeFilesFromDirectory(fileType, filepath.Join(ConfigDir, dir), pattern)
169168
}
170-
AddRuntimeFilesFromAssets(fileType, path.Join("runtime", dir), pattern)
169+
AddRuntimeFilesFromAssets(fileType, filepath.Join("runtime", dir), pattern)
171170
}
172171

173172
initRuntimeVars()
@@ -300,7 +299,7 @@ func PluginAddRuntimeFile(plugin string, filetype RTFiletype, filePath string) e
300299
if _, err := os.Stat(fullpath); err == nil {
301300
AddRealRuntimeFile(filetype, realFile(fullpath))
302301
} else {
303-
fullpath = path.Join("runtime", "plugins", pldir, filePath)
302+
fullpath = filepath.Join("runtime", "plugins", pldir, filePath)
304303
AddRuntimeFile(filetype, assetFile(fullpath))
305304
}
306305
return nil
@@ -317,7 +316,7 @@ func PluginAddRuntimeFilesFromDirectory(plugin string, filetype RTFiletype, dire
317316
if _, err := os.Stat(fullpath); err == nil {
318317
AddRuntimeFilesFromDirectory(filetype, fullpath, pattern)
319318
} else {
320-
fullpath = path.Join("runtime", "plugins", pldir, directory)
319+
fullpath = filepath.Join("runtime", "plugins", pldir, directory)
321320
AddRuntimeFilesFromAssets(filetype, fullpath, pattern)
322321
}
323322
return nil

0 commit comments

Comments
 (0)