godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Add editor setting to disable 'Lookup Symbol' with CTRL+LMB combo in Script Editor #9362

Open Okxa opened 6 months ago

Okxa commented 6 months ago

Describe the project you are working on

Any project when using inbuilt script editor.

Describe the problem or limitation you are having in your project

In Script Editor pressing CTRL + Left Mouse Button causes editor to lookup the symbol underneath cursor. This can be accidentally triggered and then the editor jumps around or opens the documentation for the symbol.

This interrups my work, as I now have to scroll back down to the location I was at, or close the opened documentation.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add a editor setting which controls if the symbol lookup with CTRL+LMB is enabled.

Symbol Lookup can be still triggered from context menu.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Script Editor has CodeEdit.symbol_lookup_on_click always set to true.

This value should be read from project settings.

code_editor->get_text_editor()->set_symbol_lookup_on_click_enabled(true);

https://github.com/godotengine/godot/blob/fe01776f05b1787b28b4a270d53037a3c25f4ca2/editor/plugins/script_text_editor.cpp#L2372

The property being true makes CTRL+LMB trigger the lookup symbol:

        } else {
            if (mb->get_button_index() == MouseButton::LEFT) {
                if (mb->is_command_or_control_pressed() && !symbol_lookup_word.is_empty()) {
                    Vector2i mpos = mb->get_position();
                    if (is_layout_rtl()) {
                        mpos.x = get_size().x - mpos.x;
                    }

                    Point2i pos = get_line_column_at_pos(mpos, false);
                    int line = pos.y;
                    int col = pos.x;

                    if (line != -1) {
                        emit_signal(SNAME("symbol_lookup"), symbol_lookup_word, line, col);
                    }
                    return;
// and below where the word is parsed from...
        if (symbol_lookup_on_click_enabled) {
            if (mm->is_command_or_control_pressed() && mm->get_button_mask().is_empty()) {
                symbol_lookup_pos = get_line_column_at_pos(mpos);
                symbol_lookup_new_word = get_word_at_pos(mpos);
                if (symbol_lookup_new_word != symbol_lookup_word) {
                    emit_signal(SNAME("symbol_validate"), symbol_lookup_new_word);
                }
            } else if (!mm->is_command_or_control_pressed() || (!mm->get_button_mask().is_empty() && symbol_lookup_pos != get_line_column_at_pos(mpos))) {
                set_symbol_lookup_word_as_valid(false);
            }
        }

https://github.com/godotengine/godot/blob/fe01776f05b1787b28b4a270d53037a3c25f4ca2/scene/gui/code_edit.cpp#L359-L396

Also note that the modifier is hardcoded (to command/control). Ideally this could be changed, but the text editor also has other hardcoded modifier keys (eg. multi-cursor selection being bound to ALT), so for this issues my proposed solution would be enough.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No

Is there a reason why this should be core and not an add-on in the asset library?

Editor Enchantment.

KoBeWi commented 6 months ago

You can go back in history when editor jumps, it works both for doc pages and within the same script. It can be used with either the arrow buttons at the top or Back mouse button (if you have extra buttons). image

Okxa commented 6 months ago

You can go back in history when editor jumps, it works both for doc pages and within the same script.

That seems to leave the doc file open in the script editor list, requiring even more clicks to close it.