From 49b4faf43a012ba6e0bdae612bab6547f230cedb Mon Sep 17 00:00:00 2001 From: hsandt Date: Mon, 4 Feb 2019 20:23:48 +0100 Subject: [PATCH] [Code Editor] Fixed toggle_inline_comment moving cursor position by 1 even with longer delimiter like "//" --- editor/code_editor.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 123817824bb..0ad7d5adc93 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1132,7 +1132,7 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { } // Adjust selection & cursor position. - int offset = is_commented ? -1 : 1; + int offset = (is_commented ? -1 : 1) * delimiter.length(); int col_from = text_editor->get_selection_from_column() > 0 ? text_editor->get_selection_from_column() + offset : 0; if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1) @@ -1150,14 +1150,15 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { } else { int begin = text_editor->cursor_get_line(); String line_text = text_editor->get_line(begin); + int delimiter_length = delimiter.length(); int col = text_editor->cursor_get_column(); if (line_text.begins_with(delimiter)) { - line_text = line_text.substr(delimiter.length(), line_text.length()); - col -= 1; + line_text = line_text.substr(delimiter_length, line_text.length()); + col -= delimiter_length; } else { line_text = delimiter + line_text; - col += 1; + col += delimiter_length; } text_editor->set_line(begin, line_text);