Tk Source Code

View Ticket
Login
Ticket UUID: 46d7a4d153591683ad4283e3eed018f420c50617
Title: tags not present as intended
Type: Bug Version: revised_text
Submitter: chw Created on: 2017-05-26 21:39:17
Subsystem: -- New Widgets Assigned To: gcramer
Priority: 5 Medium Severity: Severe
Status: Closed Last Modified: 2017-05-27 08:00:51
Resolution: Fixed Closed By: gcramer
    Closed on: 2017-05-27 08:00:51
Description:
The code below is derived from the widget demo and should display hyperlinks on most lines.
There seems to be a pattern of lines not getting a hyperlink tag. Tried on a x86_64 linux build.

--- code ---

text .t -wrap word -width 70 -height 50 \
        -setgrid 1 -highlightthickness 0
pack .t -expand 1 -fill both -padx 1

.t tag configure title -font TkDefaultFont
.t tag configure subtitle -font TkDefaultFont
.t tag configure bold -font TkDefaultFont
.t tag configure demospace -lmargin1 1c -lmargin2 1c
.t tag configure demo -lmargin1 1c -lmargin2 1c \
    -foreground blue -underline 1
.t tag configure visited -lmargin1 1c -lmargin2 1c \
    -foreground #303080 -underline 1
.t tag configure hot -foreground red -underline 1

proc addt {text} {
    set style normal
    set isNL 1
    set demoCount 0
    set new 0
    foreach line [split $text \n] {
        set line [string trim $line]
        if {$line eq ""} {
            continue
        }
        if {[string match @@* $line]} {
            set data [string range $line 2 end]
            set key [lindex $data 0]
            set values [lrange $data 1 end]
            switch -exact -- $key {
                title {
                    .t insert end $values\n title \n normal
                }
                newline {
                    .t insert end \n $style
                    set isNL 1
                }
                subtitle {
                    .t insert end "\n" {} $values subtitle \
                            " \n " demospace
                    set demoCount 0
                }
                demo {
                    set description [lassign $values name]
                    .t insert end "[incr demoCount]. $description" \
                            [list demo demo-$name]
                    if {$new} {
                        .t image create end -image ::img::new -padx 5
                        set new 0
                    }
                    .t insert end " \n " demospace
                }
                new {
                    set new 1
                }
                default {
                    set style $key
                }
            }
            continue
        }
        if {!$isNL} {
            .t insert end " " $style
        }
        set isNL 0
        .t insert end $line $style
    }
}

set addt {
    @@title     Tag test

    Bla bla bla ...
    Bla bla bla ...

    @@subtitle   subtitle
}

for {set i 0} {$i < 1024} {incr i} {
    append addt "    @@demo tag$i\ttag$i\n"
}

addt $addt

--- /code ---
User Comments: gcramer added on 2017-05-27 08:00:51:
Fixed with [6892f446], I had to correct a simple reallocation bug.

Many thanks for testing!