summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhsandt <hs@fuwar.in>2019-02-04 20:23:48 +0100
committerhsandt <hs@fuwar.in>2019-02-04 20:23:48 +0100
commit49b4faf43a012ba6e0bdae612bab6547f230cedb (patch)
tree64adb0be5c1fcdbd324fb6a8a5de2ddf52ae7ef1
parent5165a90ef6915f20178a4abb1f008f442f1f17c5 (diff)
[Code Editor] Fixed toggle_inline_comment moving cursor position by 1 even with longer delimiter like "//"
-rw-r--r--editor/code_editor.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 123817824b..0ad7d5adc9 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);