Tk Library Source Code

Artifact [eb75d2c321]
Login

Artifact eb75d2c32189720794d93d6e4f44d6ff6bfc3fea:

Attachment "ctext-scroll-85.patch" to ticket [3285751fff] added by zoro2 2011-04-13 18:59:48.
diff -u ctext-orig/ctext.tcl ctext/ctext.tcl
--- ctext-orig/ctext.tcl	2009-01-22 04:00:46.000000000 +0100
+++ ctext/ctext.tcl	2011-04-13 08:46:19.741210900 +0200
@@ -1040,10 +1040,51 @@
 		}
 		set lastLine $line
 	}
+	if {[llength $lineList] > 0} {
+		linemapUpdateOffset $win $lineList
+	}
 	set endrow [lindex [split [$win._t index end-1c] .] 0]
 	$win.l configure -width [string length $endrow]
 }
 
+# starting with Tk 8.5 text widget allows smooth scrolling; this code calculates
+# offset for the line numbering text widget and scrolls by specified amount of pixels
+if {![catch {package require Tk 8.5}]} {
+	proc ctext::linemapUpdateOffset {win lineList} {
+		# reset view for line numbering widget
+		$win.l yview 0.0
+
+		# find first line that is visible and calculate
+		# corresponding line in line nubmers widget
+		set lline 1
+		foreach line $lineList {
+			set tystart [lindex [$win.t bbox $line.0] 1]
+			if {$tystart != ""} {
+				break
+			}
+			incr lline
+		}
+
+		# return in case line numbers text widget is not up to date
+		if {[catch {
+			set lystart [lindex [$win.l bbox $lline.0] 1]
+		}]} {
+			return
+		}
+		# return in case bbox for any of the lines returned empty value
+		if {($tystart == "") || ($lystart == "")} {
+			return
+		}
+
+		# calculate offset and scroll by specified number of pixels
+		set offset [expr {$lystart - $tystart}]
+		$win.l yview scroll $offset pixels
+	}
+}  else  {
+	proc ctext::linemapUpdateOffset {win lineList} {
+	}
+}
+
 proc ctext::modified {win value} {
 	ctext::getAr $win config ar
 	set ar(modified) $value