Attachment "text.patch" to
ticket [542199ff]
added by
mdejong
2002-04-11 05:14:32.
Index: library/text.tcl
===================================================================
RCS file: /cvsroot/tktoolkit/tk/library/text.tcl,v
retrieving revision 1.22
diff -u -r1.22 text.tcl
--- library/text.tcl 7 Mar 2002 11:49:49 -0000 1.22
+++ library/text.tcl 10 Apr 2002 22:13:37 -0000
@@ -521,6 +521,16 @@
set Priv(pressX) $x
$w mark set insert [TextClosestGap $w $x $y]
$w mark set anchor insert
+ # Set the anchor mark's gravity depending on the click position
+ # relative to the gap
+ set bbox [$w bbox [$w index anchor]]
+ if {$x > [lindex $bbox 0]} {
+ set side right
+ } else {
+ set side left
+ }
+ $w mark gravity anchor $side
+
# Allow focus in any case on Windows, because that will let the
# selection be displayed even for state disabled text widgets.
if {[string equal $::tcl_platform(platform) "windows"] \
@@ -563,30 +573,39 @@
}
}
word {
- if {[$w compare $cur < anchor]} {
- set first [TextPrevPos $w "$cur + 1c" tcl_wordBreakBefore]
- if { !$extend } {
- set last [TextNextPos $w "anchor" tcl_wordBreakAfter]
- } else {
- set last anchor
- }
+ # Set initial range based only on the anchor (1 char min width)
+ if {[string equal [$w mark gravity anchor] "right"]} {
+ set lindex "anchor"
+ set rindex "anchor + 1c"
} else {
- set last [TextNextPos $w "$cur - 1c" tcl_wordBreakAfter]
- if { !$extend } {
- set first [TextPrevPos $w anchor tcl_wordBreakBefore]
- } else {
- set first anchor
- }
+ set lindex "anchor - 1c"
+ set rindex "anchor"
+ }
+
+ # Extend range (if necessary) based on the current point
+ if {[$w compare $cur < $lindex]} {
+ set lindex $cur
+ } elseif {[$w compare $cur > $rindex]} {
+ set rindex $cur
}
+
+ # Now find word boundaries
+ set first [tkTextPrevPos $w "$lindex + 1c" tcl_wordBreakBefore]
+ set last [tkTextNextPos $w "$rindex - 1c" tcl_wordBreakAfter]
}
line {
- if {[$w compare $cur < anchor]} {
- set first [$w index "$cur linestart"]
- set last [$w index "anchor - 1c lineend + 1c"]
- } else {
- set first [$w index "anchor linestart"]
- set last [$w index "$cur lineend + 1c"]
+ # Set initial range based only on the anchor
+ set lindex "anchor linestart"
+ set rindex "anchor - 1c lineend"
+
+ # Extend range (if necessary) based on the current point
+ if {[$w compare $cur < $lindex]} {
+ set lindex "$cur linestart"
+ } elseif {[$w compare $cur > $rindex]} {
+ set rindex "$cur -1c lineend"
}
+ set first [$w index $lindex]
+ set last [$w index "$rindex + 1c"]
}
}
if {$Priv(mouseMoved) || [string compare $Priv(selectMode) "char"]} {