Skip to content

Make find-and-replace bar accept Ctrl/Cmd + Alt modifier to Replace All#88846

Open
MajorMcDoom wants to merge 2 commits intogodotengine:masterfrom
MajorMcDoom:find-replace-all-shortcut
Open

Make find-and-replace bar accept Ctrl/Cmd + Alt modifier to Replace All#88846
MajorMcDoom wants to merge 2 commits intogodotengine:masterfrom
MajorMcDoom:find-replace-all-shortcut

Conversation

@MajorMcDoom
Copy link
Copy Markdown
Contributor

Currently there is no easy way to replace all without using the mouse, or using tab to cycle focus to the Replace All button.
Since we are already using the Shift modifier for searching/replacing backwards, I think it's acceptable to use Ctrl/Cmd modifier to Replace All. There is definitely existing software that uses this shortcut, though I cannot think of which off the top of my head.

@MajorMcDoom MajorMcDoom requested a review from a team as a code owner February 26, 2024 02:51
@AThousandShips AThousandShips added this to the 4.x milestone Feb 26, 2024
@Mickeon
Copy link
Copy Markdown
Member

Mickeon commented Feb 26, 2024

The fact that it's hardcoded and provides no way of knowing about it is a bit... "bad" in my opinion. "Replace All" is mapped to CTRL + ALT + ENTER in VSC, requiring the Find & Replace popup to be open of course.

@MajorMcDoom
Copy link
Copy Markdown
Contributor Author

MajorMcDoom commented Feb 26, 2024

The fact that it's hardcoded and provides no way of knowing about it is a bit... "bad" in my opinion. "Replace All" is mapped to CTRL + ALT + ENTER in VSC, requiring the Find & Replace popup to be open of course.

There are quite a few instances of this in Godot, unfortunately.
This particular one can be seen as a modifier on a submission, so I don't think it's really bad that it can't be remapped. That said, you're right that it should at least be discoverable. I didn't even know about the Shift+Enter interactions until I read the code.

I'm not sure what the best approach would be here though. I don't know if Godot has some standards for showing instructions.

@Mickeon
Copy link
Copy Markdown
Member

Mickeon commented Feb 26, 2024

The least that could be done is a tooltip on the LineEdit itself, perhaps. That's the most "consistent" standard when it comes to showing additional inputs.

I do agree that modifiers on a submission often feel natural and may be discoverable by trial & error, but yeah. Just... yeah... The editor isn't known for being consistent.

@Calinou
Copy link
Copy Markdown
Member

Calinou commented Feb 26, 2024

I'd prefer to use Ctrl + Alt + Enter as a dedicated shortcut. Requiring two modifiers to be held makes it a lot harder to accidentally input it.

@MajorMcDoom MajorMcDoom changed the title Make find-and-replace bar accept Ctrl/Cmd modifier to Replace All Make find-and-replace bar accept Ctrl/Cmd + Alt modifier to Replace All Feb 27, 2024
@MajorMcDoom MajorMcDoom force-pushed the find-replace-all-shortcut branch 2 times, most recently from 920ce52 to be3bb26 Compare February 27, 2024 07:14
@MajorMcDoom
Copy link
Copy Markdown
Contributor Author

MajorMcDoom commented Feb 27, 2024

Okay, I've changed it to Cmd/Ctrl+Alt+Enter, and I've also added a tooltip indicating such to the Replace All button.
No spaces, to be consistent with how input events are displayed in Godot.

@MajorMcDoom MajorMcDoom force-pushed the find-replace-all-shortcut branch from be3bb26 to 6f0f2aa Compare February 27, 2024 07:16
Comment thread editor/code_editor.cpp

void FindReplaceBar::_replace_text_submitted(const String &p_text) {
if (selection_only->is_pressed() && text_editor->has_selection(0)) {
if ((Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL) && Input::get_singleton()->is_key_pressed(Key::ALT)) || (selection_only->is_pressed() && text_editor->has_selection(0))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The feature makes sense, but this isn't the right way to add shortcuts.

BaseButton has an API for this already, which should be usable here, a priori (didn't test).
This lets you register a shortcut, with a property name so it can be customized by the user, and it gets added to a tooltip automatically with the proper localization. If the shortcut is pressed, the button is pressed and triggers its callback.

In the constructor:

replace_all->set_shortcut(ED_SHORTCUT("script_editor/replace_all_occurrences", TTR("Replace All Occurrences"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT | Key::ENTER);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for this! As a button on its own with a shortcut, I'd do this with no hesitation, but I do have to raise the question of what to do with the rest of the interactions that don't have associated buttons?

e.g. Shift-Enter to search / replace backwards?

And also, the plain Enter isn't a mapping for a search / replace shortcut either - it's just a submission from a TextEdit.

Is this asymmetry okay?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The actions which don't have an associated button should rely on ui_ input actions in the InputMap, and possibly add new ones if they're not covered already.

But there are indeed still a bunch of places where we hardcode specific keys instead of relying on action, I don't know if it's an oversight (UI actions for stuff like TextEdit were added recently), or if there's a good reason for it.

CC @KoBeWi

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

More like CC @Paulb23

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For the time being, should I add this shortcut as described by @akien-mga, without any further modifications to the other interactions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes I would say so.

Copy link
Copy Markdown
Contributor Author

@MajorMcDoom MajorMcDoom Feb 28, 2024

Choose a reason for hiding this comment

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

Unfortunately the shortcut only works when none of the text fields have focus. When one of them has focus (which it almost always does when this shortcut is to be used), the text submission shortcut takes priority. Any idea how to get around that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this solution is okay as it's only checking modifiers, from the LineEdit's text_submitted signal. Which should already be using the ui_text_submit shortcut.

Given it's not currently handled like a shortcut / input event as above, we'd have to do some restructuring to support this like we do in CodeTextEditor::input, and bypass the LineEdit signal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So for this PR, what's the best course of action? Leave it as a modifier check? Or restructuring?

@fire fire requested a review from a team February 27, 2024 17:33
@Mickeon Mickeon requested a review from Paulb23 May 31, 2025 15:36
@Repiteo Repiteo requested a review from a team as a code owner February 17, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants