Skip to content

Commit c1493bd

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

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
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/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/help/options.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,18 +460,19 @@ 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.
465463

466-
default value: `false`
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.
466+
467+
default value: `true`
467468

468469
* `tabmovement`: navigate spaces at the beginning of lines as if they are tabs
469470
(e.g. move over 4 spaces at once). This option only does anything if
470471
`tabstospaces` is on.
471472

472473
default value: `false`
473474

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

476477
default value: `true`
477478

0 commit comments

Comments
 (0)