Tk Source Code

Artifact [4fe9e318]
Login

Artifact 4fe9e3189e7a187123b9964d410124fde493fcd67e5eba44604b3a2b061f096b:

Attachment "5d983ebf48_sample.tcl" to ticket [5d983ebf] added by serhiy.storchaka 2026-09-29 07:56:13.
# Sample script for [5d983ebf48]: Text widget RTL auto-detection makes
# mapping and editing slow.  Compare the times with 9.0.
package require Tk
wm geometry . +0+0

proc ms {script} {
    set t [clock microseconds]
    uplevel 1 $script
    format %.0f [expr {([clock microseconds] - $t) / 1000.0}]
}
set hebrew "שלום עולם"

# 1. Map 900 text widgets with 300 lines of LTR text each.
set text [string repeat "The quick brown fox jumps over the lazy dog.\n" 300]
toplevel .t1
for {set i 0} {$i < 900} {incr i} {
    text .t1.t$i -width 10 -height 1
    .t1.t$i insert end $text
    grid .t1.t$i -row [expr {$i / 30}] -column [expr {$i % 30}]
}
puts "map 900 texts x 300 lines:    [ms update] ms"
destroy .t1

# 2. Map one text with 100000 lines.
toplevel .t2
pack [text .t2.t]
.t2.t insert end [string repeat "A line of plain LTR text.\n" 100000]
puts "map 1 text x 100000 lines:    [ms update] ms"
destroy .t2

# 3. A keystroke in a text with 5000 lines of Hebrew (with the re-tagging).
toplevel .t3
pack [text .t3.t]
.t3.t insert end [string repeat "$hebrew\n" 5000]
update
.t3.t mark set insert 1.0
puts "keystroke in 5000 Hebrew lines: [ms {tk::TextInsert .t3.t x; update}] ms"
destroy .t3

# 4. Two texts changed in the same idle cycle must both be re-tagged.
toplevel .t4
foreach w {.t4.a .t4.b} {
    pack [text $w -height 3]
}
update
foreach w {.t4.a .t4.b} {
    $w mark set insert end
    tk::TextInsert $w "\n$hebrew"
}
update
foreach w {.t4.a .t4.b} {
    puts "$w: Hebrew line right-justified: [llength [$w tag ranges tk_rtl_right]]"
}

# 5. A recreated text with the same path must be scanned when mapped.
destroy .t4.a
text .t4.a -height 3
.t4.a insert end $hebrew
pack .t4.a
update
puts "recreated .t4.a: Hebrew line right-justified: [llength [.t4.a tag ranges tk_rtl_right]]"
exit