summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2010-06-15 14:30:48 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2010-06-15 14:30:48 (GMT)
commit0b7e8337d47378cf0dc522d2ec715e979968542d (patch)
treed2fcb6dc38cf54c3840d40e3d65427f7e4c96e6d /library
parent32e568d9d802c1041fc2f6505b16ad94e2ed39cb (diff)
downloadtk-0b7e8337d47378cf0dc522d2ec715e979968542d.zip
tk-0b7e8337d47378cf0dc522d2ec715e979968542d.tar.gz
tk-0b7e8337d47378cf0dc522d2ec715e979968542d.tar.bz2
* library/text.tcl (TextCursorInSelection): [Patch 2585265]: Make it
so that pressing delete or backspace when the primary selection does not include the insertion cursor does not cause the deletion of the inserted text.
Diffstat (limited to 'library')
-rw-r--r--library/text.tcl38
1 files changed, 25 insertions, 13 deletions
diff --git a/library/text.tcl b/library/text.tcl
index 74a8d6b..c609665 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.45 2010/01/06 18:37:36 dkf Exp $
+# RCS: @(#) $Id: text.tcl,v 1.46 2010/06/15 14:30:48 dkf Exp $
#
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
@@ -208,7 +208,7 @@ bind Text <Return> {
}
}
bind Text <Delete> {
- if {[%W tag nextrange sel 1.0 end] ne ""} {
+ if {[tk::TextCursorInSelection %W]} {
%W delete sel.first sel.last
} else {
if {[%W compare end != insert+1c]} {
@@ -218,7 +218,7 @@ bind Text <Delete> {
}
}
bind Text <BackSpace> {
- if {[%W tag nextrange sel 1.0 end] ne ""} {
+ if {[tk::TextCursorInSelection %W]} {
%W delete sel.first sel.last
} else {
if {[%W compare insert != 1.0]} {
@@ -866,6 +866,21 @@ proc ::tk::TextResetAnchor {w index} {
}
}
+# ::tk::TextCursorInSelection --
+# Check whether the selection exists and contains the insertion cursor. Note
+# that it assumes that the selection is contiguous.
+#
+# Arguments:
+# w - The text widget whose selection is to be checked
+
+proc ::tk::TextCursorInSelection {w} {
+ expr {
+ [llength [$w tag ranges sel]]
+ && [$w compare sel.first <= insert]
+ && [$w compare sel.last >= insert]
+ }
+}
+
# ::tk::TextInsert --
# Insert a string into a text at the point of the insertion cursor.
# If there is a selection in the text, and it covers the point of the
@@ -880,17 +895,14 @@ proc ::tk::TextInsert {w s} {
return
}
set compound 0
- if {[llength [set range [$w tag ranges sel]]]} {
- if {[$w compare [lindex $range 0] <= insert] \
- && [$w compare [lindex $range end] >= insert]} {
- set oldSeparator [$w cget -autoseparators]
- if {$oldSeparator} {
- $w configure -autoseparators 0
- $w edit separator
- set compound 1
- }
- $w delete [lindex $range 0] [lindex $range end]
+ if {[TextCursorInSelection $w]} {
+ set oldSeparator [$w cget -autoseparators]
+ if {$oldSeparator} {
+ $w configure -autoseparators 0
+ $w edit separator
+ set compound 1
}
+ $w delete sel.first sel.last
}
$w insert insert $s
$w see insert