Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copy/select shortcuts when editable==false in LineEdit #99822

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

havi05
Copy link
Contributor

@havi05 havi05 commented Nov 29, 2024

This fixes #99813
I just moved the context_menu, copy and select_all input checks before the editable check in line 651.

@havi05 havi05 requested a review from a team as a code owner November 29, 2024 08:13
@Chaosus Chaosus added this to the 4.4 milestone Nov 29, 2024
accept_event();
return;
}

// Cut / Paste
if (k->is_action("ui_cut", true)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cut should copy when not editable, so it matches with TextEdit behavior.
The cut_text() method can modified for this.

Copy link
Member

@KoBeWi KoBeWi Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the TextEdit's behavior is wrong.

For reference, Cut doing nothing in readonly fields is how browsers behave:
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_readonly

Copy link
Contributor Author

@havi05 havi05 Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text in your example gets copied on Windows / Firefox using Ctrl+x.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's Copy. Ctrl+X does nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant using Ctrl+X

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but it does not on Chrome 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also does not on MS Edge

@havi05 havi05 force-pushed the lineedit-shortcuts branch 2 times, most recently from 21aa684 to a6bdbed Compare November 29, 2024 20:17
@havi05
Copy link
Contributor Author

havi05 commented Nov 29, 2024

What do you think about merging the cut_text and copy_text functions (because they are almost identical) ?
e.g. copy_text(cut = false)

Comment on lines 1411 to 1420
if (editable && selection.enabled && !pass) {
if (selection.enabled && !pass) {
DisplayServer::get_singleton()->clipboard_set(get_selected_text());
selection_delete();
if (editable) {
selection_delete();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. Cutting should always be a complete operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it to use copy_text instead and revert the change of the function.

Copy link
Member

@KoBeWi KoBeWi Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the Cut shortcut just should do nothing if LineEdit is not editable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the behavior of TextEdit be changed to match this one? (In a seperate pull request)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Also we could add tests for these fixes.

Copy link
Member

@KoBeWi KoBeWi Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh this can be discussed further.

I think cut not actually cutting text, but only copying it, is wrong. Cut is an operation that removes text and copies it to clipboard, so it should not be doing one of them. As I noted #99822 (comment), that's how readonly fields behave in browsers, which is a nice reference for how things should work.

That said, TextEdit even has text for this behavior, so maybe it's better to open an issue about it. Currently the Cut operation is disabled in menu, so it's weird that it would do something via shortcut.
image

(I'll unresolve the comment, so this discussion is visible)

scene/gui/line_edit.cpp Outdated Show resolved Hide resolved
scene/gui/line_edit.cpp Outdated Show resolved Hide resolved
@KoBeWi
Copy link
Member

KoBeWi commented Nov 29, 2024

What do you think about merging the cut_text and copy_text functions (because they are almost identical) ?

Makes sense, but not in this pull request.

@KoBeWi
Copy link
Member

KoBeWi commented Nov 29, 2024

Since this is disputable, and currently inconsistent with TextEdit, I think you could change the ui_cut behavior to do copy_text when LineEdit is not editable. This can be further discussed in a dedicated issue.

EDIT:
#99853

@havi05
Copy link
Contributor Author

havi05 commented Nov 29, 2024

I've removed the comment Cut / Paste since the functions are now seperated and the input action explains the if statement. If you think it should be added, just tell me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants