@@ -494,7 +494,7 @@ func (w *BufWindow) displayBuffer() {
494494 }
495495 bloc .X = bslice
496496
497- draw := func (r rune , combc []rune , style tcell.Style , highlight bool , showcursor bool ) {
497+ draw := func (r rune , combc []rune , validrune bool , style tcell.Style , highlight bool , showcursor bool ) {
498498 if nColsBeforeStart <= 0 && vloc .Y >= 0 {
499499 if highlight {
500500 if w .Buf .HighlightSearch && w .Buf .SearchMatch (bloc ) {
@@ -571,9 +571,20 @@ func (w *BufWindow) displayBuffer() {
571571 }
572572 }
573573
574- if r == '\t' {
575- indentrunes := []rune (b .Settings ["indentchar" ].(string ))
576- // if empty indentchar settings, use space
574+ if r == '\t' || (r == ' ' && bloc .X < blineLen && validrune ) {
575+ var indentrunes []rune
576+ switch r {
577+ case '\t' :
578+ indentrunes = []rune (b .Settings ["indenttabchar" ].(string ))
579+ case ' ' :
580+ if bloc .X % tabsize == 0 && bloc .X < leadingwsEnd {
581+ indentrunes = []rune (b .Settings ["indentspacechar" ].(string ))
582+ } else {
583+ indentrunes = []rune (b .Settings ["spacechar" ].(string ))
584+ }
585+ }
586+
587+ // if no override for current character, use space
577588 if len (indentrunes ) == 0 {
578589 indentrunes = []rune {' ' }
579590 }
@@ -692,7 +703,7 @@ func (w *BufWindow) displayBuffer() {
692703 // If a word (or just a wide rune) does not fit in the window
693704 if vloc .X + wordwidth > maxWidth && vloc .X > w .gutterOffset {
694705 for vloc .X < maxWidth {
695- draw (' ' , nil , config .DefStyle , false , false )
706+ draw (' ' , nil , false , config .DefStyle , false , false )
696707 }
697708
698709 // We either stop or we wrap to draw the word in the next line
@@ -708,7 +719,7 @@ func (w *BufWindow) displayBuffer() {
708719 }
709720
710721 for _ , r := range word {
711- draw (r .r , r .combc , r .style , true , true )
722+ draw (r .r , r .combc , true , r .style , true , true )
712723
713724 // Draw any extra characters either spaces for tabs or @ for incomplete wide runes
714725 if r .width > 1 {
@@ -718,7 +729,7 @@ func (w *BufWindow) displayBuffer() {
718729 }
719730
720731 for i := 1 ; i < r .width ; i ++ {
721- draw (char , nil , r .style , true , false )
732+ draw (char , nil , false , r .style , true , false )
722733 }
723734 }
724735 bloc .X ++
@@ -764,7 +775,7 @@ func (w *BufWindow) displayBuffer() {
764775
765776 if vloc .X != maxWidth {
766777 // Display newline within a selection
767- draw (' ' , nil , config .DefStyle , true , true )
778+ draw (' ' , nil , false , config .DefStyle , true , true )
768779 }
769780
770781 bloc .X = w .StartCol
0 commit comments