Sujet : Re: Operate only on the visible lines in a text window
De : sdeacon (at) *nospam* us.socionext.com (Shaun Deacon)
Groupes : comp.lang.tclDate : 10. Jul 2024, 18:38:03
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6mgts$20kdd$1@dont-email.me>
References : 1 2
User-Agent : Mozilla/5.0 (Windows NT 10.0; WOW64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.18.2
Ralf Fassel wrote:
* Shaun Deacon <sdeacon@us.socionext.com>
| The obvious solution to me is to just highlight the currently visible
| lines (or a range of lines spanning the current view - say 1000 or so)
| and when the user scrolls the window, highlight the new set of lines.
>
| Suggestions on the best way to find the indexes for the currently
| visible lines when the widget has been scrolled would be great.
>
| Can someone please point me in the right direction ?
You could try 'text yview' and derive the displayed lines from that:
grid [text .t -yscrollcommand {recalc {.s set}}] -sticky ewns -row 0 -column 0
grid [scrollbar .s -command {recalc {.t yview}} -orient vertical] -sticky ns -row 0 -column 1
grid [label .l] - -sticky ewns
grid rowconfigure . 0 -weight 1
grid columnconfigure . 0 -weight 1
for {set l 1} {$l < 1000} {incr l} {
.t insert end "Line $l\n"
}
proc recalc {cmd args} {
# scroll if required
if {$cmd ne ""} {
{*}$cmd {*}$args
}
# Determine the visible range
lassign [.t yview] start end
# Get line count
set lines [lindex [split [.t index end] "."] 0]
# Get first and last line displayed.
# Here you need to determine what to do with the partially displayed lines
set first [format %.1f [expr {$start*$lines+1}]]
set last [format %.1f [expr {$end*$lines}]]
.l configure -text "visible Lines $first ... $last"
}
bind . <Configure> [list recalc ""]
HTH
R'
Thanks Ralf, this looks promising to me.
Shaun