Skip to content

Commit af11943

Browse files
committed
[WIP] Proportional font: drawText chunk split
Apply a change by @akiyosi: > This logic treats characters with the same highlight, separated only by > single spaces, as a single text chunk for drawing. However, this > behavior seems to be incompatible with proportional fonts. > Below, I propose a revised and optimized version of the code with that > logic removed. See akiyosi#591 (comment)
1 parent 5ffc78a commit af11943

File tree

1 file changed

+46
-64
lines changed

1 file changed

+46
-64
lines changed

editor/window.go

Lines changed: 46 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,19 +2622,22 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
26222622
for hlkey, colorSlice := range chars {
26232623
var buffer bytes.Buffer
26242624
slice := colorSlice
2625-
26262625
isIndentationWhiteSpace := true
26272626
pos := col
2627+
2628+
horScrollPixels := 0
2629+
verScrollPixels := 0
2630+
if w.s.ws.mouseScroll != "" {
2631+
horScrollPixels = w.scrollPixels[0]
2632+
}
2633+
if w.lastScrollphase != core.Qt__NoScrollPhase {
2634+
verScrollPixels = w.scrollPixels2
2635+
}
2636+
if editor.config.Editor.LineToScroll == 1 {
2637+
verScrollPixels += w.scrollPixels[1]
2638+
}
2639+
26282640
for x := col; x <= col+cols; x++ {
2629-
if w.s.ws.mouseScroll != "" {
2630-
horScrollPixels = w.scrollPixels[0]
2631-
}
2632-
if w.lastScrollphase != core.Qt__NoScrollPhase {
2633-
verScrollPixels = w.scrollPixels2
2634-
}
2635-
if editor.config.Editor.LineToScroll == 1 {
2636-
verScrollPixels += w.scrollPixels[1]
2637-
}
26382641
if line[x].highlight.isSignColumn() {
26392642
horScrollPixels = 0
26402643
}
@@ -2647,62 +2650,46 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
26472650
verScrollPixels = 0
26482651
}
26492652

2650-
isDrawWord := false
2653+
if len(slice) == 0 {
2654+
break
2655+
}
26512656
index := slice[0]
26522657

2653-
if len(slice) != 0 {
2654-
2655-
// e.g. when the contents of the line is;
2656-
// [ 'a', 'b', ' ', 'c', ' ', ' ', 'd', 'e', 'f' ]
2657-
//
2658-
// then, the slice is [ 1,2,4,7,8,9 ]
2659-
// the following process is
2660-
// * If a word is separated by a single space, it is treated as a single word.
2661-
// * If there are more than two continuous spaces, each word separated by a space
2662-
// is treated as an independent word.
2663-
//
2664-
// therefore, the above example will treet that;
2665-
// "ab c" and "def"
2666-
2667-
if x != index {
2668-
if isIndentationWhiteSpace {
2669-
continue
2670-
} else {
2671-
if len(slice) > 1 {
2672-
if x+1 == index {
2673-
if buffer.Len() > 0 {
2674-
pos++
2675-
buffer.WriteString(" ")
2676-
}
2677-
} else {
2678-
isDrawWord = true
2679-
}
2680-
} else {
2681-
isDrawWord = true
2682-
}
2683-
}
2658+
if x != index {
2659+
if isIndentationWhiteSpace {
2660+
continue
26842661
}
2685-
2686-
if x == index {
2687-
pos++
2688-
2689-
char := line[x].char
2690-
if line[x].covered && w.grid == 1 {
2691-
char = " "
2692-
}
2693-
buffer.WriteString(char)
2694-
slice = slice[1:]
2695-
isIndentationWhiteSpace = false
2696-
2662+
// draw collected word
2663+
if buffer.Len() != 0 {
2664+
w.drawTextInPos(
2665+
p,
2666+
int(w.getPixelX(wsfont, y, x-pos))+horScrollPixels,
2667+
wsfontLineHeight+verScrollPixels,
2668+
buffer.String(),
2669+
hlkey,
2670+
true,
2671+
false,
2672+
)
2673+
buffer.Reset()
2674+
pos = 0
26972675
}
2676+
continue
26982677
}
26992678

2700-
if isDrawWord || len(slice) == 0 {
2701-
if len(slice) == 0 {
2702-
x++
2703-
}
2679+
// x == index
2680+
pos++
2681+
char := line[x].char
2682+
if line[x].covered && w.grid == 1 {
2683+
char = " "
2684+
}
2685+
buffer.WriteString(char)
2686+
slice = slice[1:]
2687+
isIndentationWhiteSpace = false
27042688

2689+
if len(slice) == 0 {
2690+
// draw last word
27052691
if buffer.Len() != 0 {
2692+
x++ // prepare for next column
27062693
w.drawTextInPos(
27072694
p,
27082695
int(w.getPixelX(wsfont, y, x-pos))+horScrollPixels,
@@ -2712,15 +2699,10 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
27122699
true,
27132700
false,
27142701
)
2715-
27162702
buffer.Reset()
2717-
isDrawWord = false
27182703
pos = 0
27192704
}
2720-
2721-
if len(slice) == 0 {
2722-
break
2723-
}
2705+
break
27242706
}
27252707
}
27262708
}

0 commit comments

Comments
 (0)