Skip to content

Commit 22a70a1

Browse files
Simplifying draw to be less nested
1 parent a6e3c2a commit 22a70a1

File tree

1 file changed

+53
-48
lines changed

1 file changed

+53
-48
lines changed

internal/display/bufwindow.go

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -575,75 +575,80 @@ func (w *BufWindow) displayBuffer() {
575575
}
576576

577577
draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool, bgoverridable bool) {
578-
if nColsBeforeStart <= 0 && vloc.Y >= 0 {
579-
if highlight {
580-
if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) {
581-
style = config.DefStyle.Reverse(true)
582-
if s, ok := config.Colorscheme["hlsearch"]; ok {
583-
style = s
584-
}
585-
}
578+
defer func() {
579+
if nColsBeforeStart <= 0 {
580+
vloc.X++
581+
}
582+
nColsBeforeStart--
583+
}()
586584

587-
_, origBg, _ := style.Decompose()
588-
_, defBg, _ := config.DefStyle.Decompose()
585+
if nColsBeforeStart > 0 || vloc.Y < 0 {
586+
return
587+
}
589588

590-
// syntax or hlsearch highlighting with non-default background takes precedence
591-
// over cursor-line and color-column
592-
if bgoverridable {
593-
bgoverridable = origBg == defBg
589+
if highlight {
590+
if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) {
591+
style = config.DefStyle.Reverse(true)
592+
if s, ok := config.Colorscheme["hlsearch"]; ok {
593+
style = s
594594
}
595+
}
595596

596-
for _, c := range cursors {
597-
if c.HasSelection() &&
598-
(bloc.GreaterEqual(c.CurSelection[0]) && bloc.LessThan(c.CurSelection[1]) ||
599-
bloc.LessThan(c.CurSelection[0]) && bloc.GreaterEqual(c.CurSelection[1])) {
600-
// The current character is selected
601-
style = config.DefStyle.Reverse(true)
597+
_, origBg, _ := style.Decompose()
598+
_, defBg, _ := config.DefStyle.Decompose()
602599

603-
if s, ok := config.Colorscheme["selection"]; ok {
604-
style = s
605-
}
606-
}
600+
// syntax or hlsearch highlighting with non-default background takes precedence
601+
// over cursor-line and color-column
602+
if bgoverridable {
603+
bgoverridable = origBg == defBg
604+
}
607605

608-
if b.Settings["cursorline"].(bool) && w.active && bgoverridable &&
609-
!c.HasSelection() && c.Y == bloc.Y {
610-
if s, ok := config.Colorscheme["cursor-line"]; ok {
611-
fg, _, _ := s.Decompose()
612-
style = style.Background(fg)
613-
}
614-
}
615-
}
606+
for _, c := range cursors {
607+
if c.HasSelection() &&
608+
(bloc.GreaterEqual(c.CurSelection[0]) && bloc.LessThan(c.CurSelection[1]) ||
609+
bloc.LessThan(c.CurSelection[0]) && bloc.GreaterEqual(c.CurSelection[1])) {
610+
// The current character is selected
611+
style = config.DefStyle.Reverse(true)
616612

617-
for _, m := range b.Messages {
618-
if bloc.GreaterEqual(m.Start) && bloc.LessThan(m.End) ||
619-
bloc.LessThan(m.End) && bloc.GreaterEqual(m.Start) {
620-
style = style.Underline(true)
621-
break
613+
if s, ok := config.Colorscheme["selection"]; ok {
614+
style = s
622615
}
623616
}
624617

625-
if s, ok := config.Colorscheme["color-column"]; ok {
626-
if colorcolumn != 0 && vloc.X-w.gutterOffset+w.StartCol == colorcolumn && bgoverridable {
618+
if b.Settings["cursorline"].(bool) && w.active && bgoverridable &&
619+
!c.HasSelection() && c.Y == bloc.Y {
620+
if s, ok := config.Colorscheme["cursor-line"]; ok {
627621
fg, _, _ := s.Decompose()
628622
style = style.Background(fg)
629623
}
630624
}
631625
}
632626

633-
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, r, combc, style)
627+
for _, m := range b.Messages {
628+
if bloc.GreaterEqual(m.Start) && bloc.LessThan(m.End) ||
629+
bloc.LessThan(m.End) && bloc.GreaterEqual(m.Start) {
630+
style = style.Underline(true)
631+
break
632+
}
633+
}
634634

635-
if showcursor {
636-
for _, c := range cursors {
637-
if c.X == bloc.X && c.Y == bloc.Y && !c.HasSelection() {
638-
w.showCursor(w.X+vloc.X, w.Y+vloc.Y, c.Num == 0)
639-
}
635+
if s, ok := config.Colorscheme["color-column"]; ok {
636+
if colorcolumn != 0 && vloc.X-w.gutterOffset+w.StartCol == colorcolumn && bgoverridable {
637+
fg, _, _ := s.Decompose()
638+
style = style.Background(fg)
640639
}
641640
}
642641
}
643-
if nColsBeforeStart <= 0 {
644-
vloc.X++
642+
643+
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, r, combc, style)
644+
645+
if showcursor {
646+
for _, c := range cursors {
647+
if c.X == bloc.X && c.Y == bloc.Y && !c.HasSelection() {
648+
w.showCursor(w.X+vloc.X, w.Y+vloc.Y, c.Num == 0)
649+
}
650+
}
645651
}
646-
nColsBeforeStart--
647652
}
648653

649654
wrap := func() {

0 commit comments

Comments
 (0)