Skip to content

Commit 159be22

Browse files
Simplifying draw to be less nested
1 parent 2cf9004 commit 159be22

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
@@ -576,75 +576,80 @@ func (w *BufWindow) displayBuffer() {
576576
}
577577

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

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

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

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

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

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

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

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

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

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

650655
wrap := func() {

0 commit comments

Comments
 (0)