summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorFalseHonesty <thefalsehonesty@gmail.com>2020-05-24 13:32:08 -0400
committerAndreas Kling <kling@serenityos.org>2020-05-25 11:33:39 +0200
commit4ad891a078d7ea8e89d4e97177b2a4967cb49438 (patch)
tree025099139daf73e278c8aa6633300445bc12ec63 /Libraries
parent21b1aba03b257154e0569a8815aada2dde1f61c9 (diff)
downloadserenity-4ad891a078d7ea8e89d4e97177b2a4967cb49438.zip
LibGUI: Add flag to TextDocument's word break locator methods
TextDocument::first_word_break_before was refactored out to be able to be used in multiple places throughout the project. It turns out that its behaviour needs to be slightly different depending on where its called, so it now has a start_at_column_before flag to decide which letter it "thinks" was clicked.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/TextDocument.cpp4
-rw-r--r--Libraries/LibGUI/TextDocument.h2
-rw-r--r--Libraries/LibGUI/TextEditor.cpp6
3 files changed, 6 insertions, 6 deletions
diff --git a/Libraries/LibGUI/TextDocument.cpp b/Libraries/LibGUI/TextDocument.cpp
index 7ccc175593..9cd2060352 100644
--- a/Libraries/LibGUI/TextDocument.cpp
+++ b/Libraries/LibGUI/TextDocument.cpp
@@ -427,7 +427,7 @@ Optional<TextDocumentSpan> TextDocument::first_non_skippable_span_after(const Te
return {};
}
-TextPosition TextDocument::first_word_break_before(const TextPosition& position) const
+TextPosition TextDocument::first_word_break_before(const TextPosition& position, bool start_at_column_before) const
{
if (position.column() == 0) {
if (position.line() == 0) {
@@ -439,7 +439,7 @@ TextPosition TextDocument::first_word_break_before(const TextPosition& position)
auto target = position;
auto line = this->line(target.line());
- auto is_start_alphanumeric = isalnum(line.codepoints()[target.column() - 1]);
+ auto is_start_alphanumeric = isalnum(line.codepoints()[target.column() - (start_at_column_before ? 1 : 0)]);
while (target.column() > 0) {
auto next_codepoint = line.codepoints()[target.column() - 1];
diff --git a/Libraries/LibGUI/TextDocument.h b/Libraries/LibGUI/TextDocument.h
index a6c7ce5c2b..8fa922dd2f 100644
--- a/Libraries/LibGUI/TextDocument.h
+++ b/Libraries/LibGUI/TextDocument.h
@@ -120,7 +120,7 @@ public:
Optional<TextDocumentSpan> first_non_skippable_span_before(const TextPosition&) const;
Optional<TextDocumentSpan> first_non_skippable_span_after(const TextPosition&) const;
- TextPosition first_word_break_before(const TextPosition&) const;
+ TextPosition first_word_break_before(const TextPosition&, bool start_at_column_before) const;
TextPosition first_word_break_after(const TextPosition&) const;
void add_to_undo_stack(NonnullOwnPtr<TextDocumentUndoCommand>);
diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp
index 37404397c6..f857474eee 100644
--- a/Libraries/LibGUI/TextEditor.cpp
+++ b/Libraries/LibGUI/TextEditor.cpp
@@ -211,7 +211,7 @@ void TextEditor::doubleclick_event(MouseEvent& event)
auto end = start;
if (!document().has_spans()) {
- start = document().first_word_break_before(start);
+ start = document().first_word_break_before(start, false);
end = document().first_word_break_after(end);
} else {
for (auto& span : document().spans()) {
@@ -720,10 +720,10 @@ void TextEditor::keydown_event(KeyEvent& event)
new_cursor = span.value().range.start();
} else {
// No remaining spans, just use word break calculation
- new_cursor = document().first_word_break_before(m_cursor);
+ new_cursor = document().first_word_break_before(m_cursor, true);
}
} else {
- new_cursor = document().first_word_break_before(m_cursor);
+ new_cursor = document().first_word_break_before(m_cursor, true);
}
toggle_selection_if_needed_for_event(event);
set_cursor(new_cursor);