Path: ...!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ralf Fassel Newsgroups: comp.lang.tcl Subject: Re: Operate only on the visible lines in a text window Date: Wed, 10 Jul 2024 10:59:00 +0200 Lines: 41 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain X-Trace: individual.net mq09UKqUObkB+W+AcVDHeQ+pTU0bHv/2q9oM2oT0unyoNUMOk= Cancel-Lock: sha1:wcRvNDxj//ZGawQ1HEBSmLHw70s= sha1:JN9lfNKpFK1bL7w72Lnvv2w9Tdc= sha256:cQI09OLUHpMOD7wPuhIZupCSFQGs1H+hICcGlFJUIAs= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Bytes: 2265 * Shaun Deacon | 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 . [list recalc ""] HTH R'