summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorVolTer <mew.pur.pur@abv.bg>2022-11-17 02:50:04 +0100
committerVolTer <mew.pur.pur@abv.bg>2022-11-17 02:50:04 +0100
commit135c8cbf98acc9ba5353fa470eafb8f1c02fe0d0 (patch)
treedd3af69665f6e17f0776fa23b4173e67b3d7e6c0 /editor
parent89a33d28f00fec579184fb7193790d40aa09b45b (diff)
Fix text selection persisting on bookmark traversal
Diffstat (limited to 'editor')
-rw-r--r--editor/code_editor.cpp42
1 files changed, 12 insertions, 30 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 510dc345bf..729e2378e4 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -2000,23 +2000,14 @@ void CodeTextEditor::goto_next_bookmark() {
return;
}
- text_editor->remove_secondary_carets();
- int line = text_editor->get_caret_line();
- if (line >= (int)bmarks[bmarks.size() - 1]) {
- text_editor->unfold_line(bmarks[0]);
- text_editor->set_caret_line(bmarks[0]);
- text_editor->center_viewport_to_caret();
- } else {
- for (int i = 0; i < bmarks.size(); i++) {
- int bmark_line = bmarks[i];
- if (bmark_line > line) {
- text_editor->unfold_line(bmark_line);
- text_editor->set_caret_line(bmark_line);
- text_editor->center_viewport_to_caret();
- return;
- }
+ int current_line = text_editor->get_caret_line();
+ int bmark_idx = 0;
+ if (current_line < (int)bmarks[bmarks.size() - 1]) {
+ while (bmark_idx < bmarks.size() && bmarks[bmark_idx] <= current_line) {
+ bmark_idx++;
}
}
+ goto_line_centered(bmarks[bmark_idx]);
}
void CodeTextEditor::goto_prev_bookmark() {
@@ -2025,23 +2016,14 @@ void CodeTextEditor::goto_prev_bookmark() {
return;
}
- text_editor->remove_secondary_carets();
- int line = text_editor->get_caret_line();
- if (line <= (int)bmarks[0]) {
- text_editor->unfold_line(bmarks[bmarks.size() - 1]);
- text_editor->set_caret_line(bmarks[bmarks.size() - 1]);
- text_editor->center_viewport_to_caret();
- } else {
- for (int i = bmarks.size() - 1; i >= 0; i--) {
- int bmark_line = bmarks[i];
- if (bmark_line < line) {
- text_editor->unfold_line(bmark_line);
- text_editor->set_caret_line(bmark_line);
- text_editor->center_viewport_to_caret();
- return;
- }
+ int current_line = text_editor->get_caret_line();
+ int bmark_idx = bmarks.size() - 1;
+ if (current_line > (int)bmarks[0]) {
+ while (bmark_idx >= 0 && bmarks[bmark_idx] >= current_line) {
+ bmark_idx--;
}
}
+ goto_line_centered(bmarks[bmark_idx]);
}
void CodeTextEditor::remove_all_bookmarks() {