From 2f8cebe516255710e45736609ba0534cffa1d0e2 Mon Sep 17 00:00:00 2001 From: patthoyts Date: Mon, 4 Jan 2010 14:30:49 +0000 Subject: Fix the console <> binding to actually remove text --- ChangeLog | 1 + library/console.tcl | 65 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 21810a4..94946a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2010-01-04 Pat Thoyts + * library/console.tcl: [Bug 580361] Fix console <> binding. * library/console.tcl: Fix keyboard access to console menu. * library/demos/filebox.tcl: Make prettier using ttk. * library/demos/fontchoose.tcl: Fix display of demo code. diff --git a/library/console.tcl b/library/console.tcl index 7c248a2..d9c788b 100644 --- a/library/console.tcl +++ b/library/console.tcl @@ -4,7 +4,7 @@ # can be used by non-unix systems that do not have built-in support # for shells. # -# RCS: @(#) $Id: console.tcl,v 1.44 2010/01/04 13:53:17 patthoyts Exp $ +# RCS: @(#) $Id: console.tcl,v 1.45 2010/01/04 14:30:50 patthoyts Exp $ # # Copyright (c) 1995-1997 Sun Microsystems, Inc. # Copyright (c) 1998-2000 Ajuba Solutions. @@ -347,6 +347,39 @@ proc ::tk::ConsolePrompt {{partial normal}} { $w see end } +# Copy selected text from the console +proc ::tk::console::Copy {w} { + if {![catch {set data [$w get sel.first sel.last]}]} { + clipboard clear -displayof $w + clipboard append -displayof $w $data + } +} +# Copies selected text. If the selection is within the current active edit +# region then it will be cut, if not it is only copied. +proc ::tk::console::Cut {w} { + if {![catch {set data [$w get sel.first sel.last]}]} { + clipboard clear -displayof $w + clipboard append -displayof $w $data + if {[$w compare sel.first >= output]} { + $w delete sel.first sel.last + } + } +} +# Paste text from the clipboard +proc ::tk::console::Paste {w} { + catch { + set clip [::tk::GetSelection $w CLIPBOARD] + set list [split $clip \n\r] + tk::ConsoleInsert $w [lindex $list 0] + foreach x [lrange $list 1 end] { + $w mark set insert {end - 1c} + tk::ConsoleInsert $w "\n" + tk::ConsoleInvoke + tk::ConsoleInsert $w $x + } + } +} + # ::tk::ConsoleBind -- # This procedure first ensures that the default bindings for the Text # class have been defined. Then certain bindings are overridden for @@ -550,32 +583,10 @@ proc ::tk::ConsoleBind {w} { exit } } - bind Console <> { - # Same as the copy event - if {![catch {set data [%W get sel.first sel.last]}]} { - clipboard clear -displayof %W - clipboard append -displayof %W $data - } - } - bind Console <> { - if {![catch {set data [%W get sel.first sel.last]}]} { - clipboard clear -displayof %W - clipboard append -displayof %W $data - } - } - bind Console <> { - catch { - set clip [::tk::GetSelection %W CLIPBOARD] - set list [split $clip \n\r] - tk::ConsoleInsert %W [lindex $list 0] - foreach x [lrange $list 1 end] { - %W mark set insert {end - 1c} - tk::ConsoleInsert %W "\n" - tk::ConsoleInvoke - tk::ConsoleInsert %W $x - } - } - } + bind Console <> { ::tk::console::Cut %W } + bind Console <> { ::tk::console::Copy %W } + bind Console <> { ::tk::console::Paste %W } + bind Console <> { set size [font configure TkConsoleFont -size] if {$size < 0} {set sign -1} else {set sign 1} -- cgit v0.12