Tk Source Code

View Ticket
Login
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?