Tk Source Code

View Ticket
Login
Ticket UUID: 1082213
Title: word wrapping should trim excess spaces
Type: Bug Version: obsolete: 8.5a2
Submitter: vincentdarley Created on: 2004-12-09 15:49:18
Subsystem: 18. [text] Assigned To: fvogel
Priority: 6 Severity: Minor
Status: Closed Last Modified: 2016-10-09 18:30:30
Resolution: Fixed Closed By: fvogel
    Closed on: 2016-10-09 18:30:30
Description:
pack [text .t -width 12 -height 5 -wrap word -font fixed]
.t insert end "this is not       what is       normally
called       word wrapping"

Would under most norms of word-wrapping produce lines
all left aligned.  However the text widget instead
wraps in the middle of a group of spaces and therefore
starts some lines with empty spaces.

See e.g. 

http://groups-beta.google.com/group/comp.lang.tcl/browse_thread/thread/a00b6e2a2c07086a
User Comments: fvogel added on 2016-10-09 18:30:30:
Merged to core-8-6-branch and trunk.

fvogel added on 2016-09-30 14:35:42: (text/x-fossil-wiki)
Note: this ticket is a duplicate of [1754051fff].

fvogel added on 2016-09-30 14:29:28: (text/x-fossil-wiki)
All tests changed to become again successful. See branch [bug-1082213fff].

Note that this did not just consist in copy/pasting the new results obtained with the fix to this bug. Instead, each failing test was reviewed and got changed (and/or its expected results) in order to maintain relevance of the test and keep testing what was meant to be tested.

I'm wondering whether this fix can go in 8.6.x or if it should be limited to 8.7. Rendering of word wrapped test is changed.

fvogel added on 2016-09-28 15:57:22: (text/x-fossil-wiki)
Fix proposed in [69686423dc].

Obviously, now a lots of tests in textDisp.test are in need of a change in their expected results. Will do.

fvogel added on 2016-09-28 15:57:06: (text/html)
Another test case from the original thread on c.l.t:

<verbatim>
# Here is a demo.  Adjust the window width, and look at the positioning
# of the second line when wrapping.  The label (upper) remians flush-left
# on both lines, but the second line of the text (.text) is indented
# depending on how many spaces are left.

pack req Tk

font create MonoFont   -family fixed -size -12 -weight bold

label .htitles -anchor w -justify left -padx 2 -pady 2 -relief sunken \
                -textvariable data -font MonoFont

text .text -height 10 -highlightthickness 0 \
                -padx 2 -pady 2 -takefocus 0 -width 1 \
                -wrap word -font MonoFont

bind .htitles <Configure> { set_wrap } 


set data [format {%15d %15d %15d %15d} 123 456 789 0]

.text insert end $data
 
proc set_wrap { } {
    set ww [expr { [winfo width .htitles] - 8 }]
    if { $ww > 10 } { # watch for initialization when there's no width yet
        .htitles configure -wraplength $ww
    }
}

grid .htitles -sticky ew
grid .text -sticky nsew

grid columnconfigure . 0 -weight 1
grid rowconfigure . 1 -weight 1

</verbatim>