Skip to content

Commit e4a92a1

Browse files
authored
Add tabalways option to always show tab bar (micro-editor#4120)
1 parent 596ffb5 commit e4a92a1

5 files changed

Lines changed: 27 additions & 9 deletions

File tree

data/micro.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@
322322
"type": "boolean",
323323
"default": true
324324
},
325+
"tabalways": {
326+
"description": "Whether to always show the tab bar, even when only one tab is open\nhttps://github.com/micro-editor/micro/blob/master/runtime/help/options.md#options",
327+
"type": "boolean",
328+
"default": false
329+
},
325330
"tabmovement": {
326331
"description": "Whether to navigate spaces at the beginning of lines as if they are tabs\nhttps://github.com/micro-editor/micro/blob/master/runtime/help/options.md#options",
327332
"type": "boolean",

internal/action/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ func doSetGlobalOptionNative(option string, nativeValue any) error {
587587
for _, b := range buffer.OpenBuffers {
588588
b.UpdateRules()
589589
}
590-
} else if option == "infobar" || option == "keymenu" {
590+
} else if option == "infobar" || option == "keymenu" || option == "tabalways" {
591591
Tabs.Resize()
592592
} else if option == "mouse" {
593593
if !nativeValue.(bool) {

internal/action/tab.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NewTabList(bufs []*buffer.Buffer) *TabList {
2626
iOffset := config.GetInfoBarOffset()
2727
tl := new(TabList)
2828
tl.List = make([]*Tab, len(bufs))
29-
if len(bufs) > 1 {
29+
if tabBarVisible(len(bufs)) {
3030
for i, b := range bufs {
3131
tl.List[i] = NewTabFromBuffer(0, 1, w, h-1-iOffset, b)
3232
}
@@ -75,15 +75,22 @@ func (t *TabList) RemoveTab(id uint64) {
7575
}
7676
}
7777

78+
// tabBarVisible reports whether the tab bar should be drawn. It is normally
79+
// only shown when more than one tab is open, but the tabalways option forces
80+
// it to always be visible
81+
func tabBarVisible(numTabs int) bool {
82+
return numTabs > 1 || config.GetGlobalOption("tabalways").(bool)
83+
}
84+
7885
// Resize resizes all elements within the tab list
79-
// One thing to note is that when there is only 1 tab
80-
// the tab bar should not be drawn so resizing must take
86+
// One thing to note is that when the tab bar is hidden (only 1 tab open and
87+
// tabalways off) the panes occupy the full height, so resizing must take
8188
// that into account
8289
func (t *TabList) Resize() {
8390
w, h := screen.Screen.Size()
8491
iOffset := config.GetInfoBarOffset()
8592
InfoBar.Resize(w, h-1)
86-
if len(t.List) > 1 {
93+
if tabBarVisible(len(t.List)) {
8794
for _, p := range t.List {
8895
p.Y = 1
8996
p.Node.Resize(w, h-1-iOffset)
@@ -107,7 +114,7 @@ func (t *TabList) HandleEvent(event tcell.Event) {
107114
mx, my := e.Position()
108115
switch e.Buttons() {
109116
case tcell.Button1:
110-
if my == t.Y && len(t.List) > 1 {
117+
if my == t.Y && tabBarVisible(len(t.List)) {
111118
if mx == 0 {
112119
t.Scroll(-4)
113120
} else if mx == t.Width-1 {
@@ -127,12 +134,12 @@ func (t *TabList) HandleEvent(event tcell.Event) {
127134
return
128135
}
129136
case tcell.WheelUp:
130-
if my == t.Y && len(t.List) > 1 {
137+
if my == t.Y && tabBarVisible(len(t.List)) {
131138
t.Scroll(4)
132139
return
133140
}
134141
case tcell.WheelDown:
135-
if my == t.Y && len(t.List) > 1 {
142+
if my == t.Y && tabBarVisible(len(t.List)) {
136143
t.Scroll(-4)
137144
return
138145
}
@@ -144,7 +151,7 @@ func (t *TabList) HandleEvent(event tcell.Event) {
144151
// Display updates the names and then displays the tab bar
145152
func (t *TabList) Display() {
146153
t.UpdateNames()
147-
if len(t.List) > 1 {
154+
if tabBarVisible(len(t.List)) {
148155
t.TabWindow.Display()
149156
}
150157
}

internal/config/settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ var DefaultGlobalOnlySettings = map[string]any{
129129
"savehistory": true,
130130
"scrollbarchar": "|",
131131
"sucmd": "sudo",
132+
"tabalways": false,
132133
"tabhighlight": false,
133134
"tabreverse": true,
134135
"xterm": false,

runtime/help/options.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ Here are the available options:
462462

463463
default value: `true`
464464

465+
* `tabalways`: always shows the tab bar, even when only one tab is open.
466+
467+
default value: `false`
468+
465469
* `tabhighlight`: inverts the tab characters' (filename, save indicator, etc)
466470
colors with respect to the tab bar.
467471

@@ -628,6 +632,7 @@ so that you can see what the formatting should look like.
628632
"statusline": true,
629633
"sucmd": "sudo",
630634
"syntax": true,
635+
"tabalways": false,
631636
"tabhighlight": true,
632637
"tabmovement": false,
633638
"tabreverse": false,

0 commit comments

Comments
 (0)