Tk Source Code

Artifact [9de128df]
Login

Artifact 9de128dff8b61563d9405839a623f0fc91db5c3f:

Attachment "text.tcl-patch" to ticket [1669632f] added by kjnash 2007-02-27 09:58:31.
--- text.tcl-CVS-1.41	2007-01-15 19:46:44.000000000 +0000
+++ text.tcl	2007-02-27 01:56:17.000000000 +0000
@@ -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.41 2006/09/10 17:06:32 das Exp $
+# RCS: @(#) $Id: text.tcl,v X.XX XXXX/XX/XX XX:XX:XX XXX Exp $
 #
 # Copyright (c) 1992-1994 The Regents of the University of California.
 # Copyright (c) 1994-1997 Sun Microsystems, Inc.
@@ -86,7 +86,16 @@
 }
 bind Text <Control-1> {
     %W mark set insert @%x,%y
+# an operation that moves the insert mark without making it
+# one end of the selection must insert an autoseparator
+    if {[%W cget -autoseparators]} {
+	%W edit separator
+    }
 }
+# stops an accidental double click triggering <Double-Button-1>
+bind Text <Double-Control-1> { # nothing }
+# stops an accidental movement triggering <B1-Motion>
+bind Text <Control-B1-Motion> { # nothing }
 bind Text <Left> {
     tk::TextSetCursor %W insert-1displayindices
 }
@@ -242,6 +251,11 @@
 }
 bind Text <Control-backslash> {
     %W tag remove sel 1.0 end
+# an operation that clears the selection must insert an autoseparator,
+# because the selection operation may have moved the insert mark
+    if {[%W cget -autoseparators]} {
+	%W edit separator
+    }
 }
 bind Text <<Cut>> {
     tk_textCut %W
@@ -253,7 +267,15 @@
     tk_textPaste %W
 }
 bind Text <<Clear>> {
+# make <<Clear>> an atomic operation on the Undo stack,
+# i.e. separate it from other delete operations on either side
+    if {[%W cget -autoseparators]} {
+	%W edit separator
+    }
     catch {%W delete sel.first sel.last}
+    if {[%W cget -autoseparators]} {
+	%W edit separator
+    }
 }
 bind Text <<PasteSelection>> {
     if {$tk_strictMotif || ![info exists tk::Priv(mouseMoved)]
@@ -341,7 +363,16 @@
 }
 
 bind Text <<Undo>> {
+    # An Undo operation may remove the separator at the top of the Undo stack.
+    # Then the item at the top of the stack gets merged with the subsequent changes.
+    # Place separators before and after Undo to prevent this.
+    if {[%W cget -autoseparators]} {
+	%W edit separator
+    }
     catch { %W edit undo }
+    if {[%W cget -autoseparators]} {
+	%W edit separator
+    }
 }
 
 bind Text <<Redo>> {
@@ -1031,9 +1062,18 @@
 
 proc ::tk_textCut w {
     if {![catch {set data [$w get sel.first sel.last]}]} {
+# make <<Cut>> an atomic operation on the Undo stack,
+# i.e. separate it from other delete operations on either side
+	set oldSeparator [$w cget -autoseparators]
+	if {$oldSeparator} {
+	    $w edit separator
+	}
 	clipboard clear -displayof $w
 	clipboard append -displayof $w $data
 	$w delete sel.first sel.last
+	if {$oldSeparator} {
+	    $w edit separator
+	}
     }
 }