mirror of
https://github.com/godotengine/godot.git
synced 2025-11-01 22:21:18 +00:00
Adds an option to move cursor with right click in TextEdit
Fixes #14832 - Added an option in the editor settings/cursor to make the cursor move with right click. - If the option is activated (true by default), a right click will move the cursor before displaying context menu. - If there is a selection, a right click on it will keep it selected, a right click outside it will unselect it. - The option is available in textEdit via an inspector property (or via GDScript): caret_moving_by_right_click - The option is available in the script editor and the shader editor via the editor settings - The documentation has been updated with the new property, and a few other entries in TextEdit.xml.
This commit is contained in:
parent
06dd10b390
commit
a55870cd81
6 changed files with 136 additions and 32 deletions
|
|
@ -620,14 +620,36 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
|
|||
|
||||
if (mb.is_valid()) {
|
||||
|
||||
if (mb->get_button_index() == BUTTON_RIGHT && !mb->is_pressed()) {
|
||||
if (mb->get_button_index() == BUTTON_RIGHT) {
|
||||
|
||||
int col, row;
|
||||
TextEdit *tx = shader_editor->get_text_edit();
|
||||
tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col);
|
||||
Vector2 mpos = mb->get_global_position() - tx->get_global_position();
|
||||
bool have_selection = (tx->get_selection_text().length() > 0);
|
||||
_make_context_menu(have_selection);
|
||||
tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
|
||||
|
||||
if (tx->is_right_click_moving_caret()) {
|
||||
if (tx->is_selection_active()) {
|
||||
|
||||
int from_line = tx->get_selection_from_line();
|
||||
int to_line = tx->get_selection_to_line();
|
||||
int from_column = tx->get_selection_from_column();
|
||||
int to_column = tx->get_selection_to_column();
|
||||
|
||||
if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) {
|
||||
// Right click is outside the seleted text
|
||||
tx->deselect();
|
||||
}
|
||||
}
|
||||
if (!tx->is_selection_active()) {
|
||||
tx->cursor_set_line(row, true, false);
|
||||
tx->cursor_set_column(col);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mb->is_pressed()) {
|
||||
_make_context_menu(tx->is_selection_active());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue