summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2004-11-23 17:50:00 (GMT)
committervincentdarley <vincentdarley>2004-11-23 17:50:00 (GMT)
commit662dcb5a115c0b902a120afa741af74a2107aa20 (patch)
tree1b875dd38b4d46bc2655943cab19b951da958b5e
parent11dfca9a22755d69867431f7cf4a876b026ae40f (diff)
downloadtk-662dcb5a115c0b902a120afa741af74a2107aa20.zip
tk-662dcb5a115c0b902a120afa741af74a2107aa20.tar.gz
tk-662dcb5a115c0b902a120afa741af74a2107aa20.tar.bz2
fix to movement up/down in text widget by display lines
-rw-r--r--ChangeLog5
-rw-r--r--library/text.tcl43
2 files changed, 40 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index ec8fc33..c348cc8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-11-23 Vince Darley <vincentdarley@users.sourceforge.net>
+
+ * library/text.tcl: make up/down cursor keys move by display
+ lines, not logical lines [Bug 1011234]
+
2004-11-19 Reinhard Max <max@suse.de>
*** 8.4.8 TAGGED FOR RELEASE ***
diff --git a/library/text.tcl b/library/text.tcl
index e20893b..6a311e7 100644
--- a/library/text.tcl
+++ b/library/text.tcl
@@ -3,7 +3,7 @@
# This file defines the default bindings for Tk text widgets and provides
# procedures that help in implementing the bindings.
#
-# RCS: @(#) $Id: text.tcl,v 1.24.2.3 2004/08/26 18:04:08 hobbs Exp $
+# RCS: @(#) $Id: text.tcl,v 1.24.2.4 2004/11/23 17:50:02 vincentdarley Exp $
#
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
@@ -842,12 +842,19 @@ proc ::tk::TextInsert {w s} {
}
# ::tk::TextUpDownLine --
-# Returns the index of the character one line above or below the
+# Returns the index of the character one display line above or below the
# insertion cursor. There are two tricky things here. First,
# we want to maintain the original column across repeated operations,
# even though some lines that will get passed through don't have
# enough characters to cover the original column. Second, don't
# try to scroll past the beginning or end of the text.
+#
+# This procedue has side effects, in that it will adjust the widget's
+# current display to show the insert position. This is required to
+# allow correct moving by display lines (when wrapped). All callers
+# of this proc always adjust the display anyway, so the side-effects
+# here are not actually observed by the user of the text widget
+# bindings.
#
# Arguments:
# w - The text window in which the cursor is to move.
@@ -856,16 +863,36 @@ proc ::tk::TextInsert {w s} {
proc ::tk::TextUpDownLine {w n} {
variable ::tk::Priv
-
+
+ $w see insert
+ scan [$w bbox insert] {%d %d %*d %d} xpos ypos height
+ set weight [$w cget -height]
+
set i [$w index insert]
- scan $i "%d.%d" line char
if {$Priv(prevPos) ne $i} {
- set Priv(char) $char
- }
- set new [$w index [expr {$line + $n}].$Priv(char)]
- if {[$w compare $new == end] || [$w compare $new == "insert linestart"]} {
+ set Priv(pos) $xpos
+ }
+
+ if {(($n < 0) && ($ypos <= $height)) \
+ || (($n > 0) && (($ypos+$height) >= ($weight*$height)))} {
+ $w yview scroll $n units
+ scan [$w bbox insert] {%*d %d %*d %d} ypos height
+ set weight [$w cget -height]
+ }
+
+ if {(($n < 0) && ($ypos > $height)) \
+ || (($n > 0) && (($ypos+$height) < ($weight*$height))) } {
+ set new [$w index "@$Priv(pos),[expr {$ypos + $n * $height}]"]
+ scan [$w bbox $new] {%d %d %d %*d} newx newy newwidth
+ if {$newy eq $ypos} {
+ set new $i
+ } elseif {$Priv(pos) > [expr {$newx+$newwidth/2}]} {
+ set new [$w index "@[expr {$newx + $newwidth + 1}],$newy"]
+ }
+ } else {
set new $i
}
+
set Priv(prevPos) $new
return $new
}