@@ -571,75 +571,80 @@ func (w *BufWindow) displayBuffer() {
571571 }
572572
573573 draw := func (r rune , combc []rune , style tcell.Style , highlight bool , showcursor bool , preservebg bool ) {
574- if nColsBeforeStart <= 0 && vloc .Y >= 0 {
575- if highlight {
576- if w .Buf .HighlightSearch && w .Buf .SearchMatch (bloc ) {
577- style = config .DefStyle .Reverse (true )
578- if s , ok := config .Colorscheme ["hlsearch" ]; ok {
579- style = s
580- }
581- }
574+ defer func () {
575+ if nColsBeforeStart <= 0 {
576+ vloc .X ++
577+ }
578+ nColsBeforeStart --
579+ }()
582580
583- _ , origBg , _ := style .Decompose ()
584- _ , defBg , _ := config .DefStyle .Decompose ()
581+ if nColsBeforeStart > 0 || vloc .Y < 0 {
582+ return
583+ }
585584
586- // syntax or hlsearch highlighting with non-default background takes precedence
587- // over cursor-line and color-column
588- if ! preservebg && origBg != defBg {
589- preservebg = true
585+ if highlight {
586+ if w .Buf .HighlightSearch && w .Buf .SearchMatch (bloc ) {
587+ style = config .DefStyle .Reverse (true )
588+ if s , ok := config .Colorscheme ["hlsearch" ]; ok {
589+ style = s
590590 }
591+ }
591592
592- for _ , c := range cursors {
593- if c .HasSelection () &&
594- (bloc .GreaterEqual (c .CurSelection [0 ]) && bloc .LessThan (c .CurSelection [1 ]) ||
595- bloc .LessThan (c .CurSelection [0 ]) && bloc .GreaterEqual (c .CurSelection [1 ])) {
596- // The current character is selected
597- style = config .DefStyle .Reverse (true )
593+ _ , origBg , _ := style .Decompose ()
594+ _ , defBg , _ := config .DefStyle .Decompose ()
598595
599- if s , ok := config .Colorscheme ["selection" ]; ok {
600- style = s
601- }
602- }
596+ // syntax or hlsearch highlighting with non-default background takes precedence
597+ // over cursor-line and color-column
598+ if ! preservebg && origBg != defBg {
599+ preservebg = true
600+ }
603601
604- if b .Settings ["cursorline" ].(bool ) && w .active && ! preservebg &&
605- ! c .HasSelection () && c .Y == bloc .Y {
606- if s , ok := config .Colorscheme ["cursor-line" ]; ok {
607- fg , _ , _ := s .Decompose ()
608- style = style .Background (fg )
609- }
610- }
611- }
602+ for _ , c := range cursors {
603+ if c .HasSelection () &&
604+ (bloc .GreaterEqual (c .CurSelection [0 ]) && bloc .LessThan (c .CurSelection [1 ]) ||
605+ bloc .LessThan (c .CurSelection [0 ]) && bloc .GreaterEqual (c .CurSelection [1 ])) {
606+ // The current character is selected
607+ style = config .DefStyle .Reverse (true )
612608
613- for _ , m := range b .Messages {
614- if bloc .GreaterEqual (m .Start ) && bloc .LessThan (m .End ) ||
615- bloc .LessThan (m .End ) && bloc .GreaterEqual (m .Start ) {
616- style = style .Underline (true )
617- break
609+ if s , ok := config .Colorscheme ["selection" ]; ok {
610+ style = s
618611 }
619612 }
620613
621- if s , ok := config .Colorscheme ["color-column" ]; ok {
622- if colorcolumn != 0 && vloc .X - w .gutterOffset + w .StartCol == colorcolumn && ! preservebg {
614+ if b .Settings ["cursorline" ].(bool ) && w .active && ! preservebg &&
615+ ! c .HasSelection () && c .Y == bloc .Y {
616+ if s , ok := config .Colorscheme ["cursor-line" ]; ok {
623617 fg , _ , _ := s .Decompose ()
624618 style = style .Background (fg )
625619 }
626620 }
627621 }
628622
629- screen .SetContent (w .X + vloc .X , w .Y + vloc .Y , r , combc , style )
623+ for _ , m := range b .Messages {
624+ if bloc .GreaterEqual (m .Start ) && bloc .LessThan (m .End ) ||
625+ bloc .LessThan (m .End ) && bloc .GreaterEqual (m .Start ) {
626+ style = style .Underline (true )
627+ break
628+ }
629+ }
630630
631- if showcursor {
632- for _ , c := range cursors {
633- if c .X == bloc .X && c .Y == bloc .Y && ! c .HasSelection () {
634- w .showCursor (w .X + vloc .X , w .Y + vloc .Y , c .Num == 0 )
635- }
631+ if s , ok := config .Colorscheme ["color-column" ]; ok {
632+ if colorcolumn != 0 && vloc .X - w .gutterOffset + w .StartCol == colorcolumn && ! preservebg {
633+ fg , _ , _ := s .Decompose ()
634+ style = style .Background (fg )
636635 }
637636 }
638637 }
639- if nColsBeforeStart <= 0 {
640- vloc .X ++
638+
639+ screen .SetContent (w .X + vloc .X , w .Y + vloc .Y , r , combc , style )
640+
641+ if showcursor {
642+ for _ , c := range cursors {
643+ if c .X == bloc .X && c .Y == bloc .Y && ! c .HasSelection () {
644+ w .showCursor (w .X + vloc .X , w .Y + vloc .Y , c .Num == 0 )
645+ }
646+ }
641647 }
642- nColsBeforeStart --
643648 }
644649
645650 wrap := func () {
0 commit comments