Skip to content

Commit c111d84

Browse files
Fixing tabhighlight and tabreverse options not applying properly
1 parent e4a92a1 commit c111d84

7 files changed

Lines changed: 41 additions & 30 deletions

File tree

internal/config/colorscheme.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ func StringToStyle(str string) tcell.Style {
208208
return style
209209
}
210210

211+
func ReverseColor(s tcell.Style) tcell.Style {
212+
_, _, attr := s.Decompose()
213+
attr = attr ^ tcell.AttrReverse
214+
if attr&tcell.AttrReverse == tcell.AttrReverse {
215+
return s.Reverse(true)
216+
} else {
217+
return s.Reverse(false)
218+
}
219+
}
220+
211221
// StringToColor returns a tcell color from a string representation of a color
212222
// We accept either bright... or light... to mean the brighter version of a color
213223
func StringToColor(str string) (tcell.Color, bool) {

internal/config/settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ var DefaultGlobalOnlySettings = map[string]any{
131131
"sucmd": "sudo",
132132
"tabalways": false,
133133
"tabhighlight": false,
134-
"tabreverse": true,
134+
"tabreverse": false,
135135
"xterm": false,
136136
}
137137

internal/display/tabwindow.go

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/micro-editor/micro/v2/internal/config"
77
"github.com/micro-editor/micro/v2/internal/screen"
88
"github.com/micro-editor/micro/v2/internal/util"
9-
"github.com/micro-editor/tcell/v2"
109
)
1110

1211
type TabWindow struct {
@@ -97,25 +96,23 @@ func (w *TabWindow) Display() {
9796

9897
globalTabReverse := config.GetGlobalOption("tabreverse").(bool)
9998
globalTabHighlight := config.GetGlobalOption("tabhighlight").(bool)
99+
tabBarStyle := config.DefStyle
100100

101-
// xor of reverse and tab highlight to get tab character (as in filename and surrounding characters) reverse state
102-
tabCharHighlight := (globalTabReverse || globalTabHighlight) && !(globalTabReverse && globalTabHighlight)
103-
104-
reverseStyles := func(reverse bool) (tcell.Style, tcell.Style) {
105-
tabBarStyle := config.DefStyle.Reverse(reverse)
106-
if style, ok := config.Colorscheme["tabbar"]; ok {
107-
tabBarStyle = style
108-
}
109-
tabBarActiveStyle := tabBarStyle
110-
if style, ok := config.Colorscheme["tabbar.active"]; ok {
111-
tabBarActiveStyle = style
112-
}
113-
return tabBarStyle, tabBarActiveStyle
101+
if style, ok := config.Colorscheme["tabbar"]; ok {
102+
tabBarStyle = style
103+
}
104+
if globalTabReverse {
105+
tabBarStyle = config.ReverseColor(tabBarStyle)
106+
}
107+
tabBarActiveStyle := tabBarStyle
108+
if globalTabHighlight {
109+
tabBarActiveStyle = config.ReverseColor(tabBarStyle)
110+
}
111+
if style, ok := config.Colorscheme["tabbar.active"]; ok {
112+
tabBarActiveStyle = style
114113
}
115114

116-
draw := func(r rune, n int, active bool, reversed bool) {
117-
tabBarStyle, tabBarActiveStyle := reverseStyles(reversed)
118-
115+
draw := func(r rune, n int, active bool, tab bool) {
119116
style := tabBarStyle
120117
if active {
121118
style = tabBarActiveStyle
@@ -128,11 +125,11 @@ func (w *TabWindow) Display() {
128125
c = ' '
129126
}
130127
if x == w.Width-1 && !done {
131-
screen.SetContent(w.Width-1, w.Y, '>', nil, tabBarStyle)
128+
screen.SetContent(w.Width-1, w.Y, '>', nil, style)
132129
x++
133130
break
134131
} else if x == 0 && w.hscroll > 0 {
135-
screen.SetContent(0, w.Y, '<', nil, tabBarStyle)
132+
screen.SetContent(0, w.Y, '<', nil, style)
136133
} else if x >= 0 && x < w.Width {
137134
screen.SetContent(x, w.Y, c, nil, style)
138135
}
@@ -143,25 +140,25 @@ func (w *TabWindow) Display() {
143140

144141
for i, n := range w.Names {
145142
if i == w.active {
146-
draw('[', 1, true, tabCharHighlight)
143+
draw('[', 1, true, true)
147144
} else {
148-
draw(' ', 1, false, tabCharHighlight)
145+
draw(' ', 1, false, true)
149146
}
150147

151148
for _, c := range n {
152-
draw(c, 1, i == w.active, tabCharHighlight)
149+
draw(c, 1, i == w.active, true)
153150
}
154151

155152
if i == len(w.Names)-1 {
156153
done = true
157154
}
158155

159156
if i == w.active {
160-
draw(']', 1, true, tabCharHighlight)
161-
draw(' ', 2, true, globalTabReverse)
157+
draw(']', 1, true, true)
158+
draw(' ', 2, true, false)
162159
} else {
163-
draw(' ', 1, false, tabCharHighlight)
164-
draw(' ', 2, false, globalTabReverse)
160+
draw(' ', 1, false, true)
161+
draw(' ', 2, false, false)
165162
}
166163

167164
if x >= w.Width {

runtime/colorschemes/gotham.micro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ color-link cursor-line "#091F2E"
2525
color-link color-column "#11151C"
2626
color-link symbol "#99D1CE,#0C1014"
2727
color-link match-brace "#0C1014,#D26937"
28+
color-link tabbar "#0C1014,#99D1CE"
2829
color-link tab-error "#D75F5F"
2930
color-link trailingws "#D75F5F"

runtime/colorschemes/monokai-dark.micro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ color-link cursor-line "#323232"
2525
color-link color-column "#323232"
2626
color-link match-brace "#1D0000,#AE81FF"
2727
color-link tab-error "#D75F5F"
28+
color-link tabbar "#1D0000,#D5D8D6"
2829
color-link trailingws "#D75F5F"

runtime/colorschemes/sunny-day.micro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ color-link cursor-line "229"
2626
color-link current-line-number "246"
2727
color-link match-brace "230,22"
2828
color-link tab-error "210"
29+
color-link tabbar "230,0"
2930
color-link trailingws "210"

runtime/help/options.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ Here are the available options:
468468

469469
* `tabhighlight`: inverts the tab characters' (filename, save indicator, etc)
470470
colors with respect to the tab bar.
471+
Has no effect if `tabbar.active` is present in the current colorscheme.
471472

472473
default value: `false`
473474

@@ -477,9 +478,9 @@ Here are the available options:
477478

478479
default value: `false`
479480

480-
* `tabreverse`: reverses the tab bar colors when active.
481+
* `tabreverse`: reverses the tab bar colors.
481482

482-
default value: `true`
483+
default value: `false`
483484

484485
* `tabsize`: the size in spaces that a tab character should be displayed with.
485486

@@ -633,7 +634,7 @@ so that you can see what the formatting should look like.
633634
"sucmd": "sudo",
634635
"syntax": true,
635636
"tabalways": false,
636-
"tabhighlight": true,
637+
"tabhighlight": false,
637638
"tabmovement": false,
638639
"tabreverse": false,
639640
"tabsize": 4,

0 commit comments

Comments
 (0)