tk_textCut

tk_textCut window

Cut the selected text in text widget window to the clipboard.

This function is documented with text.


This command is called in response to the receipt of a <<Copy>> event.


The actual proc is defined as:

 proc ::tk_textCut w {
   if {![catch {set data [$w get sel.first sel.last]}]} {
     clipboard clear -displayof $w
     clipboard append -displayof $w $data
     $w delete sel.first sel.last
   }
 }

which doesn't take into account the possibility of having multiple ranges with the sel tag. Here's a more complete version:

 proc ::tk_textCut {w} {
   set list [list]
   array set sel {}
   if { [catch {$w tag ranges sel} ranges] } { return }
   foreach {first last} $ranges {
     lappend list [$w get $first $last]
     set sel($first) $last
   }
   clipboard clear -displayof $w
   clipboard append -displayof $w [join $list \n]
   foreach first [lsort -decreasing [array names sel]] {
     $w delete $first $sel($first)
   }
 }

or even:

 proc ::tk_textCut {w} {
   array set sel {}
   if { [catch {$w tag ranges sel} ranges] } { return }
   foreach {first last} $ranges { set sel($first) $last }
   tk_textCopy $w
   foreach first [lsort -decreasing [array names sel]] {
     $w delete $first $sel($first)
   }
}

See also: