Merge pull request #111547 from sockeye-d/script-editor-join-lines
Add script editor `join_lines` keybind
This commit is contained in:
commit
28c37846d8
9 changed files with 64 additions and 0 deletions
|
|
@ -391,6 +391,13 @@
|
|||
Returns [code]true[/code] if the given line is folded. See [method fold_line].
|
||||
</description>
|
||||
</method>
|
||||
<method name="join_lines">
|
||||
<return type="void" />
|
||||
<param index="0" name="line_ending" type="String" default="" "" />
|
||||
<description>
|
||||
Joins all selected lines or lines containing a caret with their next line. Whitespace in between will be removed. If the next line has content, the [param line_ending] will be inserted in between.
|
||||
</description>
|
||||
</method>
|
||||
<method name="move_lines_down">
|
||||
<return type="void" />
|
||||
<description>
|
||||
|
|
|
|||
|
|
@ -912,6 +912,11 @@ void CodeTextEditor::input(const Ref<InputEvent> &event) {
|
|||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (ED_IS_SHORTCUT("script_text_editor/join_lines", key_event)) {
|
||||
text_editor->join_lines();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (ED_IS_SHORTCUT("script_text_editor/duplicate_selection", key_event)) {
|
||||
text_editor->duplicate_selection();
|
||||
accept_event();
|
||||
|
|
|
|||
|
|
@ -201,6 +201,7 @@ TextEditorBase::EditMenus::EditMenus() {
|
|||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent"), EDIT_INDENT);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unindent"), EDIT_UNINDENT);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
|
||||
edit_menu_line->add_shortcut(ED_GET_SHORTCUT("script_text_editor/join_lines"), EDIT_JOIN_LINES);
|
||||
edit_menu_line->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_edit_option));
|
||||
edit_menu->get_popup()->add_submenu_node_item(TTRC("Line"), edit_menu_line);
|
||||
}
|
||||
|
|
@ -413,6 +414,9 @@ bool TextEditorBase::_edit_option(int p_op) {
|
|||
case EDIT_DELETE_LINE: {
|
||||
tx->delete_lines();
|
||||
} break;
|
||||
case EDIT_JOIN_LINES: {
|
||||
tx->join_lines();
|
||||
} break;
|
||||
case EDIT_DUPLICATE_SELECTION: {
|
||||
tx->duplicate_selection();
|
||||
} break;
|
||||
|
|
|
|||
|
|
@ -120,6 +120,8 @@ protected:
|
|||
BOOKMARK_GOTO_PREV,
|
||||
BOOKMARK_REMOVE_ALL,
|
||||
|
||||
EDIT_JOIN_LINES,
|
||||
|
||||
BASE_ENUM_COUNT,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2586,6 +2586,7 @@ void ScriptTextEditor::register_editor() {
|
|||
ED_SHORTCUT("script_text_editor/move_up", TTRC("Move Up"), KeyModifierMask::ALT | Key::UP);
|
||||
ED_SHORTCUT("script_text_editor/move_down", TTRC("Move Down"), KeyModifierMask::ALT | Key::DOWN);
|
||||
ED_SHORTCUT("script_text_editor/delete_line", TTRC("Delete Line"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::K);
|
||||
ED_SHORTCUT("script_text_editor/join_lines", TTRC("Join Lines"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::J);
|
||||
|
||||
// Leave these at zero, same can be accomplished with tab/shift-tab, including selection.
|
||||
// The next/previous in history shortcut in this case makes a lot more sense.
|
||||
|
|
|
|||
|
|
@ -781,6 +781,9 @@ void TextShaderEditor::_menu_option(int p_option) {
|
|||
case EDIT_EMOJI_AND_SYMBOL: {
|
||||
code_editor->get_text_editor()->show_emoji_and_symbol_picker();
|
||||
} break;
|
||||
case EDIT_JOIN_LINES: {
|
||||
code_editor->get_text_editor()->join_lines();
|
||||
} break;
|
||||
}
|
||||
if (p_option != SEARCH_FIND && p_option != SEARCH_REPLACE && p_option != SEARCH_GOTO_LINE) {
|
||||
callable_mp((Control *)code_editor->get_text_editor(), &Control::grab_focus).call_deferred(false);
|
||||
|
|
@ -1230,6 +1233,7 @@ TextShaderEditor::TextShaderEditor() {
|
|||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent"), EDIT_INDENT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unindent"), EDIT_UNINDENT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/join_lines"), EDIT_JOIN_LINES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/duplicate_selection"), EDIT_DUPLICATE_SELECTION);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/duplicate_lines"), EDIT_DUPLICATE_LINES);
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ class TextShaderEditor : public ShaderEditor {
|
|||
BOOKMARK_REMOVE_ALL,
|
||||
HELP_DOCS,
|
||||
EDIT_EMOJI_AND_SYMBOL,
|
||||
EDIT_JOIN_LINES,
|
||||
};
|
||||
|
||||
HBoxContainer *menu_bar_hbox = nullptr;
|
||||
|
|
|
|||
|
|
@ -2701,6 +2701,44 @@ void CodeEdit::delete_lines() {
|
|||
end_complex_operation();
|
||||
}
|
||||
|
||||
void CodeEdit::join_lines(const String &p_line_ending) {
|
||||
ERR_FAIL_COND_MSG(p_line_ending.contains_char('\n'), "Cannot join lines with a newline.");
|
||||
|
||||
begin_complex_operation();
|
||||
begin_multicaret_edit();
|
||||
|
||||
Vector<Point2i> line_ranges = get_line_ranges_from_carets();
|
||||
int line_offset = 0;
|
||||
for (const Point2i &line_range : line_ranges) {
|
||||
for (int32_t line_index = line_range.x; line_index <= line_range.y; line_index++) {
|
||||
int32_t real_line = line_index + line_offset;
|
||||
if (real_line + 1 >= get_line_count()) {
|
||||
break;
|
||||
}
|
||||
unfold_line(real_line);
|
||||
String line = get_line(real_line);
|
||||
int line_length = line.length();
|
||||
int next_line_leading_whitespace_length = get_first_non_whitespace_column(real_line + 1);
|
||||
int next_line_length = get_line(real_line + 1).length();
|
||||
int corrected_line_length = line_length - 1;
|
||||
for (; corrected_line_length >= 0; corrected_line_length--) {
|
||||
if (!is_whitespace(line[corrected_line_length])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
corrected_line_length++;
|
||||
remove_text(real_line, corrected_line_length, real_line + 1, next_line_leading_whitespace_length);
|
||||
if (next_line_leading_whitespace_length != next_line_length && corrected_line_length != 0) {
|
||||
insert_text(p_line_ending, real_line, corrected_line_length);
|
||||
}
|
||||
line_offset--;
|
||||
}
|
||||
}
|
||||
|
||||
end_multicaret_edit();
|
||||
end_complex_operation();
|
||||
}
|
||||
|
||||
void CodeEdit::duplicate_selection() {
|
||||
begin_complex_operation();
|
||||
begin_multicaret_edit();
|
||||
|
|
@ -2973,6 +3011,7 @@ void CodeEdit::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("move_lines_up"), &CodeEdit::move_lines_up);
|
||||
ClassDB::bind_method(D_METHOD("move_lines_down"), &CodeEdit::move_lines_down);
|
||||
ClassDB::bind_method(D_METHOD("delete_lines"), &CodeEdit::delete_lines);
|
||||
ClassDB::bind_method(D_METHOD("join_lines", "line_ending"), &CodeEdit::join_lines, DEFVAL(" "));
|
||||
ClassDB::bind_method(D_METHOD("duplicate_selection"), &CodeEdit::duplicate_selection);
|
||||
ClassDB::bind_method(D_METHOD("duplicate_lines"), &CodeEdit::duplicate_lines);
|
||||
|
||||
|
|
|
|||
|
|
@ -523,6 +523,7 @@ public:
|
|||
void move_lines_up();
|
||||
void move_lines_down();
|
||||
void delete_lines();
|
||||
void join_lines(const String &p_line_ending = " ");
|
||||
void duplicate_selection();
|
||||
void duplicate_lines();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue