Package: tk-html3 / 3.0~fossil20110109-4

fix_empty_offset.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Origin: http://groups.google.com/group/tkhtml3/browse_thread/thread/9a624679a76e73cf
Description: The problem is that the get_selection method doesn't account for 
 when the "html text offset" command returns the empty string (it does, and 
 the C source says it can).
--- a/hv/hv3.tcl
+++ b/hv/hv3.tcl
@@ -786,11 +786,11 @@
     $me motion $N $x $y
   }

   # get_selection OFFSET MAXCHARS
   #
-  #     This command is invoked whenever the current selection is selected
+  #     This command is invoked whenever the current selection is requested
   #     while it is owned by the html widget. The text of the selected
   #     region is returned.
   #
   proc get_selection {me offset maxChars} {
     upvar $me O
@@ -801,10 +801,13 @@
     set n2 $O(myToNode)
     set i2 $O(myToIdx)

     set stridx_a [$O(myHv3) html text offset $O(myFromNode) $O(myFromIdx)]
     set stridx_b [$O(myHv3) html text offset $O(myToNode) $O(myToIdx)]
+    if {$stridx_a eq "" || $stridx_b eq ""} {
+      return ""
+    }
     if {$stridx_a > $stridx_b} {
       foreach {stridx_a stridx_b} [list $stridx_b $stridx_a] {}
     }

     if {$O(myMode) eq "word"} {