Of course I am doing something wrong, but I don't know what.
Can somebody please point it out?
proc p.paste {argWidget} {
if {[catch "set ::selection [selection get]"] == 0} {
event generate $argWidget <<Clear>>
}
set ::t1::currindex [$::t1::text index insert]
event generate $argWidget <<Paste>>
set clipcontent [selection get -selection CLIPBOARD -type UTF8_STRING]
set cliplinecount [llength [split $clipcontent "\n"]]
$::t1::text see "$::t1::currindex + $cliplinecount l"
}
What it is supposed to do:
Detect whether there is selected text, in which case issue the
event generate $argWidget <<Clear>>
command to do just that.
Then it issues the
event generate $argWidget <<Paste>>
command to paste
text from the clipboard where the selected text used to be.
What it really does:
It detects whether there is selected text, in which case issue the
event generate $argWidget <<Clear>>
command to do just that.
That command fails. The selected text is not deleted. It is, instead
placed after the newly pasted text with different formatting.
The new text is inserted by
event generate $argWidget <<Paste>>
--It's hard to answer what's happening without more information. What type of widget is $argWidget? How is p.paste being executed? What bindings do you have on <<Clear>> and <<Paste>> on the widget?
Luc
It's hard to answer what's happening without more information. What type
of widget is $argWidget? How is p.paste being executed? What bindings do
you have on <<Clear>> and <<Paste>> on the widget?
A minimal, but fully "working", code sample will help to answer your questions.
**************************
On Sat, 11 Mar 2023 13:09:23 -0800 (PST), Mike Griffiths wrote:
It's hard to answer what's happening without more information. What type of widget is $argWidget? How is p.paste being executed? What bindings do you have on <<Clear>> and <<Paste>> on the widget?
A minimal, but fully "working", code sample will help to answer your questions.Here is the code:
package require Tk
wm withdraw .
eval destroy [winfo children .]
set ::w [toplevel .editor -background #c0c0c0]
namespace eval ::t1 {}
set ::t1::text $::w.text
text $::t1::text
$::t1::text configure -wrap word -font "Monospace 14" -padx 4 -pady 2 $::t1::text configure -background #ffffff -foreground #000000
$::t1::text configure -takefocus 1 -exportselection 1 -state normal -undo 1 pack $::t1::text -fill both -expand 1
######## SHIFT + INSERT TO PASTE
bind $::t1::text <Shift_L><Insert> {p.paste %W; break}
bind $::w <Alt_L><q> {exit 0}
wm protocol $::w WM_DELETE_WINDOW {exit 0}
proc p.paste {argWidget} {
catch {set ::selection [selection get]} catcherror
if {![info exists catcherror]} {
event generate $argWidget <<Clear>>
}
set ::t1::currindex [$::t1::text index insert]
event generate $argWidget <<Paste>>
set clipcontent [selection get -selection CLIPBOARD -type UTF8_STRING]
set cliplinecount [llength [split $clipcontent "\n"]]
$::t1::text see "$::t1::currindex + $cliplinecount l"
}
focus $::t1::text
--
Luc
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (3 / 13) |
| Uptime: | 143:09:57 |
| Calls: | 12,089 |
| Calls today: | 2 |
| Files: | 14,998 |
| Messages: | 6,517,457 |