mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibGUI: Make Ctrl-Right at the end of a span work
There used to be the silly bug that when the cursor was already at the end of a span (e.g. because the user just pressed Ctrl-Right), then Ctrl-Right had no effect. This bug does not appear with Ctrl-Left because due to the order in which the spans are iterated, the effective result is always correct. This patch also makes it more apparent that the algorithm is unnecessarily inefficient.
This commit is contained in:
parent
3647001c93
commit
a8930997f0
Notes:
sideshowbarker
2024-07-18 02:21:34 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/a8930997f03 Pull-request: https://github.com/SerenityOS/serenity/pull/10476
|
@ -616,15 +616,25 @@ Optional<TextDocumentSpan> TextDocument::first_non_skippable_span_before(const T
|
|||
|
||||
Optional<TextDocumentSpan> TextDocument::first_non_skippable_span_after(const TextPosition& position) const
|
||||
{
|
||||
for (size_t i = 0; i < m_spans.size(); ++i) {
|
||||
if (!m_spans[i].range.contains(position))
|
||||
continue;
|
||||
while ((i + 1) < m_spans.size() && m_spans[i + 1].is_skippable)
|
||||
++i;
|
||||
if (i >= (m_spans.size() - 1))
|
||||
return {};
|
||||
return m_spans[i + 1];
|
||||
size_t i = 0;
|
||||
// Find the first span containing the cursor
|
||||
for (; i < m_spans.size(); ++i) {
|
||||
if (m_spans[i].range.contains(position))
|
||||
break;
|
||||
}
|
||||
// Find the first span *after* the cursor
|
||||
// TODO: For a large number of spans, binary search would be faster.
|
||||
for (; i < m_spans.size(); ++i) {
|
||||
if (!m_spans[i].range.contains(position))
|
||||
break;
|
||||
}
|
||||
// Skip skippable spans
|
||||
for (; i < m_spans.size(); ++i) {
|
||||
if (m_spans[i].is_skippable)
|
||||
break;
|
||||
}
|
||||
if (i < m_spans.size())
|
||||
return m_spans[i + 1];
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue