diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2010-08-12 07:59:14 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2010-08-12 07:59:14 (GMT) |
commit | 0068c1b934fc15e422075268a35e85477ff813b0 (patch) | |
tree | f480e4992e54b29513d64cf2d7670459561d632b /library | |
parent | 068f042f5e3805593b4d2fe44e9887a70bcefb06 (diff) | |
download | tk-0068c1b934fc15e422075268a35e85477ff813b0.zip tk-0068c1b934fc15e422075268a35e85477ff813b0.tar.gz tk-0068c1b934fc15e422075268a35e85477ff813b0.tar.bz2 |
* library/text.tcl (TextCursorInSelection): [Patch 2585265]: Backport
of factoring-out of decision logic for whether to delete the selected
text.
Diffstat (limited to 'library')
-rw-r--r-- | library/text.tcl | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/library/text.tcl b/library/text.tcl index fc98743..acdaa8e 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.41.4.2 2009/10/25 13:50:48 dkf Exp $ +# RCS: @(#) $Id: text.tcl,v 1.41.4.3 2010/08/12 07:59:15 dkf Exp $ # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. @@ -208,24 +208,20 @@ 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]} { - %W delete insert - } - %W see insert + } elseif {[%W compare end != insert+1c]} { + %W delete insert } + %W see insert } 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]} { - %W delete insert-1c - } - %W see insert + } elseif {[%W compare insert != 1.0]} { + %W delete insert-1c } + %W see insert } bind Text <Control-space> { @@ -849,6 +845,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 @@ -863,21 +874,17 @@ 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 compound [$w cget -autoseparators] + if {$compound} { + $w configure -autoseparators 0 + $w edit separator } + $w delete sel.first sel.last } $w insert insert $s $w see insert - if {$compound && $oldSeparator} { + if {$compound} { $w edit separator $w configure -autoseparators 1 } |