diff options
Diffstat (limited to 'editor/code_editor.cpp')
-rw-r--r-- | editor/code_editor.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 876fef078b..64467bc254 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -368,6 +368,9 @@ void FindReplaceBar::_update_results_count() { int col_pos = 0; + bool searched_start_is_symbol = is_symbol(searched[0]); + bool searched_end_is_symbol = is_symbol(searched[searched.length() - 1]); + while (true) { col_pos = is_case_sensitive() ? line_text.find(searched, col_pos) : line_text.findn(searched, col_pos); @@ -376,11 +379,11 @@ void FindReplaceBar::_update_results_count() { } if (is_whole_words()) { - if (col_pos > 0 && !is_symbol(line_text[col_pos - 1])) { + if (!searched_start_is_symbol && col_pos > 0 && !is_symbol(line_text[col_pos - 1])) { col_pos += searched.length(); continue; } - if (col_pos + searched.length() < line_text.length() && !is_symbol(line_text[col_pos + searched.length()])) { + if (!searched_end_is_symbol && col_pos + searched.length() < line_text.length() && !is_symbol(line_text[col_pos + searched.length()])) { col_pos += searched.length(); continue; } @@ -805,6 +808,11 @@ void CodeTextEditor::input(const Ref<InputEvent> &event) { accept_event(); return; } + if (ED_IS_SHORTCUT("script_text_editor/duplicate_lines", key_event)) { + text_editor->duplicate_lines(); + accept_event(); + return; + } } void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) { @@ -1487,14 +1495,22 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { } // Check first if there's any uncommented lines in selection. bool is_commented = true; + bool is_all_empty = true; for (int line = from; line <= to; line++) { // `+ delimiter.length()` here because comment delimiter is not actually `in comment` so we check first character after it int delimiter_idx = text_editor->is_in_comment(line, text_editor->get_first_non_whitespace_column(line) + delimiter.length()); - if (delimiter_idx == -1 || text_editor->get_delimiter_start_key(delimiter_idx) != delimiter) { + // Empty lines should not be counted. + bool is_empty = text_editor->get_line(line).strip_edges().is_empty(); + is_all_empty = is_all_empty && is_empty; + if (!is_empty && (delimiter_idx == -1 || text_editor->get_delimiter_start_key(delimiter_idx) != delimiter)) { is_commented = false; break; } } + + // Special case for commenting empty lines, treat it/them as uncommented lines. + is_commented = is_commented && !is_all_empty; + // Caret positions need to be saved since they could be moved at the eol. Vector<int> caret_cols; Vector<int> selection_to_cols; @@ -1510,10 +1526,11 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { // Comment/uncomment. for (int line = from; line <= to; line++) { String line_text = text_editor->get_line(line); - if (line_text.strip_edges().is_empty()) { + if (is_all_empty) { text_editor->set_line(line, delimiter); continue; } + if (is_commented) { text_editor->set_line(line, line_text.replace_first(delimiter, "")); } else { |