Skip to content

Commit bdc21e9

Browse files
committed
Add Drag Tab Feature
1 parent 41b912b commit bdc21e9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

internal/action/tab.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package action
22

33
import (
44
luar "layeh.com/gopher-luar"
5+
"strconv"
56

67
"github.com/micro-editor/tcell/v2"
78
"github.com/zyedidia/micro/v2/internal/buffer"
@@ -17,6 +18,8 @@ import (
1718
type TabList struct {
1819
*display.TabWindow
1920
List []*Tab
21+
// captures whether the mouse is released
22+
release bool
2023
}
2124

2225
// NewTabList creates a TabList from a list of buffers by creating a Tab
@@ -35,6 +38,7 @@ func NewTabList(bufs []*buffer.Buffer) *TabList {
3538
}
3639
tl.TabWindow = display.NewTabWindow(w, 0)
3740
tl.Names = make([]string, len(bufs))
41+
tl.release = true
3842

3943
return tl
4044
}
@@ -114,13 +118,26 @@ func (t *TabList) HandleEvent(event tcell.Event) {
114118
t.Scroll(4)
115119
} else {
116120
ind := t.LocFromVisual(buffer.Loc{mx, my})
117-
if ind != -1 {
121+
if ind == -1 {
122+
ind = len(t.List) + 1
123+
}
124+
125+
if t.release {
126+
t.release = false
118127
t.SetActive(ind)
128+
} else {
129+
MainTab().CurPane().TabMoveCmd([]string{strconv.Itoa(ind + 1)})
119130
}
120131
}
121132
return
122133
}
134+
if !t.release {
135+
return
136+
}
123137
case tcell.ButtonNone:
138+
if !t.release {
139+
t.release = true
140+
}
124141
if t.List[t.Active()].release {
125142
// Mouse release received, while already released
126143
t.ResetMouse()

0 commit comments

Comments
 (0)