Merge pull request #14420 from MattUV/fold-shortcut
Modify shortcuts and menus to fold/unfold code
This commit is contained in:
commit
faa1d23cb7
|
@ -1015,14 +1015,9 @@ void ScriptTextEditor::_edit_option(int p_op) {
|
|||
tx->end_complex_operation();
|
||||
tx->update();
|
||||
} break;
|
||||
case EDIT_FOLD_LINE: {
|
||||
case EDIT_TOGGLE_FOLD_LINE: {
|
||||
|
||||
tx->fold_line(tx->cursor_get_line());
|
||||
tx->update();
|
||||
} break;
|
||||
case EDIT_UNFOLD_LINE: {
|
||||
|
||||
tx->unfold_line(tx->cursor_get_line());
|
||||
tx->toggle_fold_line(tx->cursor_get_line());
|
||||
tx->update();
|
||||
} break;
|
||||
case EDIT_FOLD_ALL_LINES: {
|
||||
|
@ -1517,13 +1512,9 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p
|
|||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
|
||||
}
|
||||
if (p_can_fold) {
|
||||
// can fold
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_line"), EDIT_FOLD_LINE);
|
||||
} else if (p_is_folded) {
|
||||
// can unfold
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_line"), EDIT_UNFOLD_LINE);
|
||||
}
|
||||
if (p_can_fold || p_is_folded)
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
|
||||
|
||||
if (p_color) {
|
||||
context_menu->add_separator();
|
||||
context_menu->add_item(TTR("Pick Color"), EDIT_PICK_COLOR);
|
||||
|
@ -1587,9 +1578,8 @@ ScriptTextEditor::ScriptTextEditor() {
|
|||
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/toggle_comment"), EDIT_TOGGLE_COMMENT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_line"), EDIT_FOLD_LINE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_line"), EDIT_UNFOLD_LINE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
#ifdef OSX_ENABLED
|
||||
|
@ -1668,8 +1658,7 @@ void ScriptTextEditor::register_editor() {
|
|||
ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), 0);
|
||||
ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD | KEY_K);
|
||||
ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_B);
|
||||
ED_SHORTCUT("script_text_editor/fold_line", TTR("Fold Line"), KEY_MASK_ALT | KEY_LEFT);
|
||||
ED_SHORTCUT("script_text_editor/unfold_line", TTR("Unfold Line"), KEY_MASK_ALT | KEY_RIGHT);
|
||||
ED_SHORTCUT("script_text_editor/toggle_fold_line", TTR("Fold/Unfold Line"), KEY_MASK_ALT | KEY_F);
|
||||
ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), 0);
|
||||
ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0);
|
||||
#ifdef OSX_ENABLED
|
||||
|
|
|
@ -91,8 +91,7 @@ class ScriptTextEditor : public ScriptEditorBase {
|
|||
EDIT_TO_UPPERCASE,
|
||||
EDIT_TO_LOWERCASE,
|
||||
EDIT_CAPITALIZE,
|
||||
EDIT_FOLD_LINE,
|
||||
EDIT_UNFOLD_LINE,
|
||||
EDIT_TOGGLE_FOLD_LINE,
|
||||
EDIT_FOLD_ALL_LINES,
|
||||
EDIT_UNFOLD_ALL_LINES,
|
||||
SEARCH_FIND,
|
||||
|
|
|
@ -4646,6 +4646,16 @@ void TextEdit::unfold_line(int p_line) {
|
|||
update();
|
||||
}
|
||||
|
||||
void TextEdit::toggle_fold_line(int p_line) {
|
||||
|
||||
ERR_FAIL_INDEX(p_line, text.size());
|
||||
|
||||
if (!is_folded(p_line))
|
||||
fold_line(p_line);
|
||||
else
|
||||
unfold_line(p_line);
|
||||
}
|
||||
|
||||
int TextEdit::get_line_count() const {
|
||||
|
||||
return text.size();
|
||||
|
@ -5461,6 +5471,7 @@ void TextEdit::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("unhide_all_lines"), &TextEdit::unhide_all_lines);
|
||||
ClassDB::bind_method(D_METHOD("fold_line", "line"), &TextEdit::fold_line);
|
||||
ClassDB::bind_method(D_METHOD("unfold_line", "line"), &TextEdit::unfold_line);
|
||||
ClassDB::bind_method(D_METHOD("toggle_fold_line", "line"), &TextEdit::toggle_fold_line);
|
||||
ClassDB::bind_method(D_METHOD("can_fold", "line"), &TextEdit::can_fold);
|
||||
ClassDB::bind_method(D_METHOD("is_folded", "line"), &TextEdit::is_folded);
|
||||
|
||||
|
|
|
@ -436,6 +436,7 @@ public:
|
|||
bool is_folded(int p_line) const;
|
||||
void fold_line(int p_line);
|
||||
void unfold_line(int p_line);
|
||||
void toggle_fold_line(int p_line);
|
||||
|
||||
String get_text();
|
||||
String get_line(int line) const;
|
||||
|
|
Loading…
Reference in New Issue