Tk Source Code

View Ticket
Login
2020-09-21
21:28 • Ticket [d91e05bf] text widget will not process a <<copy>> when disabled. status still Closed with 5 other changes artifact: 21bbc4d6 user: bll
20:28 • Closed ticket [d91e05bf]. artifact: 544a1696 user: fvogel
20:26
Fix [d91e05bf20]: text widget will not process a <<copy>> when disabled (macOS and Linux) check-in: 33b84f3f user: fvogel tags: trunk
20:26
Fix [d91e05bf20]: text widget will not process a <<copy>> when disabled (macOS and Linux) check-in: 2b8cf15b user: fvogel tags: core-8-6-branch
2020-09-20
18:13 • Ticket [d91e05bf] text widget will not process a <<copy>> when disabled. status still Open with 3 other changes artifact: cdcebfa8 user: bll
16:25 • Ticket [d91e05bf]: 4 changes artifact: 813fa55a user: fvogel
16:06
Fix [d91e05bf20]: text widget will not process a <<copy>> when disabled closed check-in: 3ccd19e0 user: fvogel tags: bug-d91e05bf20
2020-09-09
21:05 • Ticket [d91e05bf] text widget will not process a <<copy>> when disabled. status still Open with 3 other changes artifact: a92baaa3 user: bll
19:40 • Ticket [d91e05bf]: 4 changes artifact: 369eef41 user: marc_culler
19:28 • Ticket [d91e05bf]: 3 changes artifact: 580ff472 user: fvogel
03:42 • Ticket [d91e05bf]: 3 changes artifact: d280556d user: bll
2020-09-08
21:00 • Ticket [d91e05bf]: 4 changes artifact: d4a6daaa user: marc_culler
20:39 • Ticket [d91e05bf]: 3 changes artifact: 3201f09d user: fvogel
20:35 • Ticket [d91e05bf]: 3 changes artifact: bcf06e34 user: fvogel
20:33 • Ticket [d91e05bf]: 3 changes artifact: 38974469 user: fvogel
19:58 • Ticket [d91e05bf]: 3 changes artifact: bad03960 user: fvogel
19:51 • Ticket [d91e05bf]: 3 changes artifact: 77c9b6b7 user: bll
19:47 • Ticket [d91e05bf]: 3 changes artifact: cbc48f20 user: bll
19:46 • Ticket [d91e05bf]: 4 changes artifact: 5c2a426e user: marc_culler
19:39 • New ticket [d91e05bf]. artifact: 4628fa10 user: bll

Ticket UUID: d91e05bf20c806c5157fef4f9230397c4f9b4725
Title: text widget will not process a <<copy>> when disabled.
Type: Bug Version: 8.6.10
Submitter: bll Created on: 2020-09-08 19:39:47
Subsystem: 18. [text] Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-09-21 21:28:41
Resolution: Fixed Closed By: bll
    Closed on: 2020-09-21 21:28:41
Description:
Linux:

When the text widget is set to disabled mode (to prevent deliberate or 
inadverdent user changes), the text in the widget can be selected, but
Control-C does not work to copy the text.
User Comments: bll added on 2020-09-21 21:28:41:
Ok.  At some point, we'll need to verify that selection and copy/paste
work in readonly mode for the revised text widget.  And disable it for
a disabled text widget.

fvogel added on 2020-09-21 20:28:36:

I think you're right, this change should be safe. I have merged it into core-8-6-branch and trunk.

Note that regarding normal/disabled/readonly states, the revised text widget has the feature.


bll added on 2020-09-20 18:13:20:
I think in the ideal case, a 'readonly' mode would be implemented like 
everyone always wants:
- readonly: Allows text selection and copy/paste.
  Allows programmatic modification of text widget contents,
  but not modification by the user.
- disabled: No text selection, no copy/paste,
  no modification of text widget contents.

It appears all of the text modification operations are disallowed.
I just tested 'paste' on Linux.  So I think it should be ok.

fvogel added on 2020-09-20 16:25:26:

Proposed fix committed in branch bug-d91e05bf20.

I need to think a bit whether this has side effects or not. Inputs and tests welcome.


bll added on 2020-09-09 21:05:07:
On Mac OS, without the focus, the text can't even be selected.
With focus, text can be selected and copied (Using Alt-C with VNC).

marc_culler (claiming to be Marc Culler) added on 2020-09-09 19:40:30:
Hi François, you are right.  I cannot select text.  I don't know what I
did wrong when I was testing, but now it behaves as you say.  And Brad's
fix below makes it work.  Sorry!

fvogel added on 2020-09-09 19:28:52:
@marc: I can't reproduce your observations on macOS, are you really sure? On my side I can't select text from a disabled text widget on the mac. What you're seeing is not compatible with the lines I have identified in library/text.tcl to be the culmprit ones, and where Brad confirmed the fix works for him on Linux (Linux and mac behaviors should be identical here).

@brad: could you perhaps try on macOS as well, to confirm?

bll added on 2020-09-09 03:42:17:
This fixes it for me.

--- library/text.tcl    2019-12-23 08:50:25.869958737 -0800
+++ library/text.tcl    2020-09-08 20:34:18.743237117 -0700
@@ -558,12 +558,7 @@
     } else {
        $w mark gravity $anchorname left
     }
-    # Allow focus in any case on Windows, because that will let the
-    # selection be displayed even for state disabled text widgets.
-    if {[tk windowingsystem] eq "win32" \
-           || [$w cget -state] eq "normal"} {
-       focus $w
-    }
+    focus $w
     if {[$w cget -autoseparators]} {
        $w edit separator
     }

marc_culler (claiming to be Marc Culler) added on 2020-09-08 21:00:45:
I don't see any issue with core-8-6-branch on macOS.  I am able to select
and copy text from the disabled text widget and paste into another application.
I am not able to edit the text widget while it is disabled.

fvogel added on 2020-09-08 20:39:29:

And here is the culprit (apparently intentional) code.


fvogel added on 2020-09-08 20:35:22:
The -force flag is even superfluous.

fvogel added on 2020-09-08 20:33:44:
Reproduced on Linux.

If you focus -force the text widget then it works.

Seems the widget does not accept the focus when in disabled state. In turn, since it's out of focus the <<Copy>> virtual event is not generated for the widget.

fvogel added on 2020-09-08 19:58:55:

Works for me on Windows:

pack req Tk
pack [text .t]
.t insert end "Sample text."
.t conf -state disabled

Select some text in the widget, Ctrl-C, and paste in some other application.


bll added on 2020-09-08 19:51:48:
Nope.
Shift-Control-C, Control-Shift-C do not work (disabled state).
Control-Insert/Shift-Insert do not work (disabled state).

When the text widget is in a normal state, Control-C does work.
Control-Insert does work.

I guess the appropriate keys should be also be tested on Mac OS and Windows
with a disabled text widget.

marc_culler (claiming to be Marc Culler) added on 2020-09-08 19:46:49:
What about shift-control-c?