Skip to content

Commit 4c81246

Browse files
Fixing tabhighlight and tabreverse options not applying properly
1 parent 467eb88 commit 4c81246

File tree

7 files changed

+43
-32
lines changed

7 files changed

+43
-32
lines changed

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
@@ -130,7 +130,7 @@ var DefaultGlobalOnlySettings = map[string]any{
130130
"scrollbarchar": "|",
131131
"sucmd": "sudo",
132132
"tabhighlight": false,
133-
"tabreverse": true,
133+
"tabreverse": false,
134134
"xterm": false,
135135
}
136136

internal/display/tabwindow.go

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package display
22

33
import (
44
runewidth "github.com/mattn/go-runewidth"
5-
"github.com/micro-editor/tcell/v2"
65
"github.com/zyedidia/micro/v2/internal/buffer"
76
"github.com/zyedidia/micro/v2/internal/config"
87
"github.com/zyedidia/micro/v2/internal/screen"
@@ -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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,9 @@ Here are the available options:
460460

461461
default value: `true`
462462

463-
* `tabhighlight`: inverts the tab characters' (filename, save indicator, etc)
464-
colors with respect to the tab bar.
463+
464+
* `tabhighlight`: highlighting the current active tab by using the inverted tab bar color.
465+
Has no effect if `tabbar.active` is present in the current colorscheme.
465466

466467
default value: `false`
467468

@@ -471,9 +472,9 @@ Here are the available options:
471472

472473
default value: `false`
473474

474-
* `tabreverse`: reverses the tab bar colors when active.
475+
* `tabreverse`: reverses the tab bar colors.
475476

476-
default value: `true`
477+
default value: `false`
477478

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

@@ -626,7 +627,7 @@ so that you can see what the formatting should look like.
626627
"statusline": true,
627628
"sucmd": "sudo",
628629
"syntax": true,
629-
"tabhighlight": true,
630+
"tabhighlight": false,
630631
"tabmovement": false,
631632
"tabreverse": false,
632633
"tabsize": 4,

0 commit comments

Comments
 (0)