summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--ChangeLog61
-rw-r--r--library/text.tcl38
2 files changed, 59 insertions, 40 deletions
diff --git a/ChangeLog b/ChangeLog
index 34f19a8..8888b7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,30 +1,37 @@
+2010-06-15 Donal K. Fellows <dkf@users.sf.net>
+
+ * 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.
+
2010-06-15 Jan Nijtmans <nijtmans@users.sf.net>
- * generic/tkCanvArc.c Eliminate many unnecessary
- * generic/tkCanvas.c (ClientData) type casts.
- * generic/tkCanvBmap.c
- * generic/tkCanvImg.c
- * generic/tkCanvLine.c
- * generic/tkCanvPoly.c
- * generic/tkCanvTest.c
- * generic/tkCanvWind.c
- * generic/tkRectOval.c
- * generic/tkScrollbar.c
- * generic/tkStyle.c
- * generic/tkTest.c
- * unix/tkUnixEmbed.c
- * unix/tkUnixEvent.c
- * unix/tkUnixScale.c
- * unix/tkUnixScrlbr.c
- * unix/tkUnixSelect.c
- * unix/tkUnixWm.c
- * carbon/tkMacOSXDialog.c: Terminate TkEnsemble definition with NULL
- * macosx/tkMacOSXDialog.c
+ * generic/tkCanvArc.c: Eliminate many unnecessary (ClientData) type
+ * generic/tkCanvas.c: casts.
+ * generic/tkCanvBmap.c:
+ * generic/tkCanvImg.c:
+ * generic/tkCanvLine.c:
+ * generic/tkCanvPoly.c:
+ * generic/tkCanvTest.c:
+ * generic/tkCanvWind.c:
+ * generic/tkRectOval.c:
+ * generic/tkScrollbar.c:
+ * generic/tkStyle.c:
+ * generic/tkTest.c:
+ * unix/tkUnixEmbed.c:
+ * unix/tkUnixEvent.c:
+ * unix/tkUnixScale.c:
+ * unix/tkUnixScrlbr.c:
+ * unix/tkUnixSelect.c:
+ * unix/tkUnixWm.c:
+ * carbon/tkMacOSXDialog.c: Terminate TkEnsemble definition with NULL
+ * macosx/tkMacOSXDialog.c:
2010-05-31 Joe English <jenglish@users.sourceforge.net>
- * generic/tkBind.c(Tk_CreateBinding): Silently ignore empty
- scripts (Fixes [Bug 3006842]).
+ * generic/tkBind.c (Tk_CreateBinding): [Bug 3006842]: Silently ignore
+ empty scripts.
2010-05-27 Joe English <jenglish@users.sourceforge.net>
@@ -35,11 +42,11 @@
2010-05-26 Jan Nijtmans <nijtmans@users.sf.net>
- * tests/wm.test: Fix 3 tests on Ubuntu 10.4, two of them timing dependent,
- one wm-dependent.
- * generic/tkText.c Fix some gcc strict-aliasing warnings (discovered
- * unix/tkUnixFont.c with "-Wstrict-aliasing=2"
- * unix/tkUnixSelect.c
+ * tests/wm.test: Fix 3 tests on Ubuntu 10.4, two of them timing
+ dependent, one wm-dependent.
+ * generic/tkText.c: Fix some gcc strict-aliasing warnings,
+ * unix/tkUnixFont.c: discovered with "-Wstrict-aliasing=2"
+ * unix/tkUnixSelect.c:
2010-05-20 Donal K. Fellows <dkf@users.sf.net>
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