diff options
-rw-r--r-- | generic/tkTextDisp.c | 18 | ||||
-rw-r--r-- | tests/text.test | 2 | ||||
-rw-r--r-- | tests/textDisp.test | 76 |
3 files changed, 57 insertions, 39 deletions
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index f28ec6a..2171cd0 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -7542,6 +7542,9 @@ TkTextCharLayoutProc( * (b) at least one pixel of the character is visible, we have not * already exceeded the character limit, and the next character is a * white space character. + * In the specific case of 'word' wrapping mode however, include all space + * characters following the characters that fit in the space we've got, + * even if no pixel of them is visible. */ p = segPtr->body.chars + byteOffset; @@ -7604,6 +7607,21 @@ TkTextCharLayoutProc( nextX = maxX; bytesThatFit++; } + if (wrapMode == TEXT_WRAPMODE_WORD) { + while (p[bytesThatFit] == ' ') { + /* + * Space characters that would go at the beginning of the + * next line are allocated to the current line. This gives + * the effect of trimming white spaces that would otherwise + * be seen at the beginning of wrapped lines. + * Note that testing for '\t' is useless here because the + * chunk always includes at most one trailing \t, see + * LayoutDLine. + */ + + bytesThatFit++; + } + } if (p[bytesThatFit] == '\n') { /* * A newline character takes up no space, so if the previous diff --git a/tests/text.test b/tests/text.test index f640817..3e5b4b6 100644 --- a/tests/text.test +++ b/tests/text.test @@ -3828,7 +3828,7 @@ test text-19.16 {DeleteChars procedure, updates affecting topIndex} -setup { wm geometry .top +0+0 update } -body { - .top.t insert end "abc def\n01 2345 678 9101112\nLine 3\nLine 4\nLine 5\n6\n7\n8\n" + .top.t insert end "abc def\n01 2a345 678 9101112\nLine 3\nLine 4\nLine 5\n6\n7\n8\n" .top.t yview 2.4 .top.t delete 2.5 set x [.top.t index @0,0] diff --git a/tests/textDisp.test b/tests/textDisp.test index 99401c2..d3de2d8 100644 --- a/tests/textDisp.test +++ b/tests/textDisp.test @@ -253,8 +253,8 @@ test textDisp-2.5 {LayoutDLine, word wrap} {textfonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "This isx some sample text for testing." - list [.t bbox 1.13] [.t bbox 1.14] [.t bbox 1.19] -} [list [list 96 5 49 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 40 [expr {$fixedDiff + 18}] 7 $fixedHeight]] + list [.t bbox 1.13] [.t bbox 1.19] [.t bbox 1.20] [.t bbox 1.21] +} [list [list 96 5 $fixedWidth $fixedHeight] [list 138 5 $fixedWidth $fixedHeight] [list 145 5 0 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] $fixedWidth $fixedHeight]] test textDisp-2.6 {LayoutDLine, word wrap} { .t configure -wrap word .t delete 1.0 end @@ -353,16 +353,16 @@ test textDisp-2.16 {LayoutDLine, justification} {textfonts} { .t tag configure x -justify center .t tag add x 1.1 1.20 .t tag add x 1.21 1.end - list [.t bbox 1.0] [.t bbox 1.20] [.t bbox 1.36] [.t bbox 2.0] -} [list [list 5 5 7 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 43 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]] + list [.t bbox 1.0] [.t bbox 1.20] [.t bbox 1.41] [.t bbox 2.0] +} [list [list 5 5 7 $fixedHeight] [list 5 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 61 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]] test textDisp-2.17 {LayoutDLine, justification} {textfonts} { .t configure -wrap word .t delete 1.0 end - .t insert 1.0 "Lots of long words, enough to force word wrap\nThen\nmore lines" + .t insert 1.0 "Lots of very long words, enough to force word wrap\nThen\nmore lines" .t tag configure x -justify center - .t tag add x 1.20 - list [.t bbox 1.0] [.t bbox 1.20] [.t bbox 1.36] [.t bbox 2.0] -} [list [list 5 5 7 $fixedHeight] [list 19 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 5 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]] + .t tag add x 1.18 + list [.t bbox 1.0] [.t bbox 1.18] [.t bbox 1.35] [.t bbox 2.0] +} [list [list 5 5 7 $fixedHeight] [list 15 [expr {$fixedDiff + 18}] 7 $fixedHeight] [list 5 [expr {2*$fixedDiff + 31}] 7 $fixedHeight] [list 5 [expr {3*$fixedDiff + 44}] 7 $fixedHeight]] test textDisp-2.18 {LayoutDLine, justification} {textfonts} { .t configure -wrap none .t delete 1.0 end @@ -2337,7 +2337,7 @@ test textDisp-17.10 {TkTextScanCmd procedure, word wrapping} {textfonts} { set x [.t index @0,0] .t scan dragto 0 [expr {70 + $fixedDiff}] list $x [.t index @0,0] -} {9.15 8.31} +} {9.0 8.0} .t configure -xscrollcommand scroll -yscrollcommand {} test textDisp-18.1 {GetXView procedure} { .t configure -wrap none @@ -2563,7 +2563,7 @@ test textDisp-19.10.1 {Widget manipulation causes height miscount} { .t insert end "\nLine $i" } .t insert end "\nThis last line wraps around four " - .t insert end "times with a bit left on the last line." + .t insert end "times with a little bit left on the last line." .t yview insert update .t count -update -ypixels 1.0 end @@ -2577,7 +2577,7 @@ test textDisp-19.11 {GetYView procedure} { .t insert end "\nLine $i" } .t insert end "\nThis last line wraps around four " - .t insert end "times with a bit left on the last line." + .t insert end "times with a little bit left on the last line." .t yview insert update .t count -update -ypixels 1.0 end @@ -2599,7 +2599,7 @@ test textDisp-19.11.5.1 {TextWidgetCmd procedure, "count -displaylines"} { .t count -displaylines 16.0 16.5 } {0} test textDisp-19.11.6 {TextWidgetCmd procedure, "count -displaylines"} { - .t count -displaylines 16.0 16.20 + .t count -displaylines 16.0 16.24 } {1} test textDisp-19.11.7 {TextWidgetCmd procedure, "count -displaylines"} { .t count -displaylines 16.0 16.40 @@ -2652,14 +2652,14 @@ test textDisp-19.11.17 {TextWidgetCmd procedure, "index +displaylines"} { [.t index "12.0 +2d lines"] [.t index "11.0 +2d lines"] \ [.t index "13.0 +2d lines"] [.t index "13.1 +3d lines"] \ [.t index "13.0 +4d lines"] -} {15.5 16.0 15.0 16.0 16.15 16.33} +} {15.5 16.0 15.0 16.0 16.21 16.39} test textDisp-19.11.18 {TextWidgetCmd procedure, "index +displaylines"} { .t tag remove elide 1.0 end .t tag add elide "12.0" "14.0" list [.t index "15.5 -2d lines"] \ [.t index "16.0 -2d lines"] [.t index "15.0 -2d lines"] \ - [.t index "16.0 -3d lines"] [.t index "16.17 -4d lines"] \ - [.t index "16.36 -5d lines"] + [.t index "16.0 -3d lines"] [.t index "16.23 -4d lines"] \ + [.t index "16.42 -5d lines"] } {11.5 14.0 11.0 11.0 11.2 11.3} test textDisp-19.11.19 {TextWidgetCmd procedure, "count -displaylines"} { .t tag remove elide 1.0 end @@ -2673,14 +2673,14 @@ test textDisp-19.11.20 {TextWidgetCmd procedure, "index +displaylines"} { [.t index "12.0 +2d lines"] [.t index "11.0 +2d lines"] \ [.t index "13.0 +2d lines"] [.t index "13.0 +3d lines"] \ [.t index "13.0 +4d lines"] -} {16.38 16.50 16.33 16.50 16.67 17.0} +} {16.44 16.57 16.39 16.57 16.74 17.0} test textDisp-19.11.21 {TextWidgetCmd procedure, "index +displaylines"} { .t tag remove elide 1.0 end .t tag add elide "12.0" "16.0 +1displaylines" - list [.t index "16.38 -2d lines"] \ - [.t index "16.50 -3d lines"] [.t index "16.33 -2d lines"] \ - [.t index "16.53 -4d lines"] [.t index "16.69 -4d lines"] \ - [.t index "17.1 -5d lines"] + list [.t index "16.44 -2d lines"] \ + [.t index "16.57 -3d lines"] [.t index "16.39 -2d lines"] \ + [.t index "16.60 -4d lines"] [.t index "16.76 -4d lines"] \ + [.t index "17.0 -5d lines"] } {11.5 11.0 11.0 10.3 11.2 11.0} test textDisp-19.11.22 {TextWidgetCmd procedure, "index +displaylines"} { .t tag remove elide 1.0 end @@ -2688,7 +2688,7 @@ test textDisp-19.11.22 {TextWidgetCmd procedure, "index +displaylines"} { [.t index "end -3d lines"] [.t index "1.0 -2d lines"] \ [.t index "1.0 +4d lines"] [.t index "1.0 +50d lines"] \ [.t index "end -50d lines"] -} {17.0 16.33 1.0 5.0 17.0 1.0} +} {17.0 16.39 1.0 5.0 17.0 1.0} test textDisp-19.11.23 {TextWidgetCmd procedure, "index +displaylines"} { .t tag remove elide 1.0 end .t tag add elide "12.3" "16.0 +1displaylines" @@ -2697,7 +2697,7 @@ test textDisp-19.11.23 {TextWidgetCmd procedure, "index +displaylines"} { [.t index "12.0 +2d lines"] [.t index "11.0 +2d lines"] \ [.t index "13.0 +2d lines"] [.t index "13.0 +3d lines"] \ [.t index "13.0 +4d lines"] -} {16.17 16.33 16.28 16.46 16.28 16.49 16.65 16.72} +} {16.23 16.44 16.39 16.57 16.39 16.60 16.77 16.79} .t tag remove elide 1.0 end test textDisp-19.11.24 {TextWidgetCmd procedure, "index +/-displaylines"} { list [.t index "11.5 + -1 display lines"] \ @@ -2746,7 +2746,7 @@ test textDisp-19.14 {GetYView procedure} { .t insert end "\nLine $i" } .t insert end "\nThis last line wraps around four " - .t insert end "times with a bit left on the last line." + .t insert end "times with a little bit left on the last line." # Need to update so everything is calculated. update ; .t count -update -ypixels 1.0 end update ; after 10 ; update @@ -2766,7 +2766,7 @@ test textDisp-19.15 {GetYView procedure} { .t insert end "\nLine $i" } .t insert end "\nThis last line wraps around four " - .t insert end "times with a bit left on the last line." + .t insert end "times with a bit little left on the last line." update .t configure -yscrollcommand scrollError proc bgerror args { @@ -2794,7 +2794,7 @@ test textDisp-19.16 {count -ypixels} { .t insert end "\nLine $i" } .t insert end "\nThis last line wraps around four " - .t insert end "times with a bit left on the last line." + .t insert end "times with a little bit left on the last line." # Need to update so everything is calculated. update ; .t count -update -ypixels 1.0 end ; update set res {} @@ -2879,18 +2879,18 @@ test textDisp-20.1 {FindDLine} {textfonts} { test textDisp-20.2 {FindDLine} {textfonts} { .t yview 100.0 .t yview -pickplace 53.0 - list [.t dlineinfo 50.0] [.t dlineinfo 50.14] [.t dlineinfo 50.15] -} [list [list 3 [expr {-1 - $fixedDiff/2}] 105 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {-1 - $fixedDiff/2}] 105 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {12 + $fixedDiff/2}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]]] + list [.t dlineinfo 50.0] [.t dlineinfo 50.14] [.t dlineinfo 50.21] +} [list [list 3 [expr {-1 - $fixedDiff/2}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {-1 - $fixedDiff/2}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {12 + $fixedDiff/2}] 133 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]]] test textDisp-20.3 {FindDLine} {textfonts} { .t yview 100.0 .t yview 49.0 - list [.t dlineinfo 50.0] [.t dlineinfo 50.20] [.t dlineinfo 57.0] -} [list [list 3 [expr {$fixedDiff + 16}] 105 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {2*$fixedDiff + 29}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}] + list [.t dlineinfo 50.0] [.t dlineinfo 50.24] [.t dlineinfo 57.0] +} [list [list 3 [expr {$fixedDiff + 16}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {2*$fixedDiff + 29}] 133 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}] test textDisp-20.4 {FindDLine} {textfonts} { .t yview 100.0 .t yview 42.0 - list [.t dlineinfo 50.0] [.t dlineinfo 50.20] [.t dlineinfo 50.40] -} [list [list 3 [expr {8*$fixedDiff + 107}] 105 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {9*$fixedDiff + 120}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}] + list [.t dlineinfo 50.0] [.t dlineinfo 50.24] [.t dlineinfo 50.40] +} [list [list 3 [expr {8*$fixedDiff + 107}] 140 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {9*$fixedDiff + 120}] 133 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}] .t config -wrap none test textDisp-20.5 {FindDLine} {textfonts} { .t yview 100.0 @@ -2903,7 +2903,7 @@ test textDisp-21.1 {TkTextPixelIndex} {textfonts} { .t yview 48.0 list [.t index @-10,-10] [.t index @6,6] [.t index @22,6] \ [.t index @102,6] [.t index @38,[expr {$fixedHeight * 4 + 3}]] [.t index @44,67] -} {48.0 48.0 48.2 48.7 50.40 50.40} +} {48.0 48.0 48.2 48.7 50.45 50.45} .t insert end \n test textDisp-21.2 {TkTextPixelIndex} {textfonts} { .t yview 195.0 @@ -2959,7 +2959,7 @@ test textDisp-22.1 {TkTextCharBbox} {textfonts} { .t yview 48.0 list [.t bbox 47.2] [.t bbox 48.0] [.t bbox 50.5] [.t bbox 50.40] \ [.t bbox 58.0] -} [list {} [list 3 3 7 $fixedHeight] [list 38 [expr {3+2*$fixedHeight}] 7 $fixedHeight] [list 38 [expr {3+4*$fixedHeight}] 7 $fixedHeight] {}] +} [list {} [list 3 3 7 $fixedHeight] [list 38 [expr {3+2*$fixedHeight}] 7 $fixedHeight] [list 3 [expr {3+4*$fixedHeight}] 7 $fixedHeight] {}] test textDisp-22.2 {TkTextCharBbox} {textfonts} { .t config -wrap none .t yview 48.0 @@ -3083,13 +3083,13 @@ test textDisp-23.1 {TkTextDLineInfo} {textfonts} { .t yview 48.0 list [.t dlineinfo 47.3] [.t dlineinfo 48.0] [.t dlineinfo 50.40] \ [.t dlineinfo 56.0] -} [list {} [list 3 3 49 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {4*$fixedDiff + 55}] 126 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}] +} [list {} [list 3 3 49 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] [list 3 [expr {4*$fixedDiff + 55}] 91 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] {}] test textDisp-23.2 {TkTextDLineInfo} {textfonts} { .t config -bd 4 -wrap word update .t yview 48.0 .t dlineinfo 50.40 -} [list 7 [expr {4*$fixedDiff + 59}] 126 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] +} [list 7 [expr {4*$fixedDiff + 59}] 91 [expr {$fixedDiff + 13}] [expr {$fixedDiff + 10}]] .t config -bd 0 test textDisp-23.3 {TkTextDLineInfo} {textfonts} { .t config -wrap none @@ -3284,11 +3284,11 @@ test textDisp-24.17 {TkTextCharLayoutProc, -wrap word} {textfonts} { test textDisp-24.18 {TkTextCharLayoutProc, -wrap word} {textfonts} { .t configure -wrap word .t delete 1.0 end - .t insert 1.0 "xThis is a line that wraps around" + .t insert 1.0 "xxThis is a line that wraps around" wm geom . {} update - list [.t bbox 1.14] [.t bbox 1.15] [.t bbox 1.16] -} [list [list 101 3 7 $fixedHeight] [list 108 3 35 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]] + list [.t bbox 1.15] [.t bbox 1.16] [.t bbox 1.17] +} [list [list 108 3 7 $fixedHeight] [list 115 3 28 $fixedHeight] [list 3 [expr {$fixedDiff + 16}] 7 $fixedHeight]] test textDisp-24.19 {TkTextCharLayoutProc, -wrap word} {textfonts} { .t configure -wrap word .t delete 1.0 end |