1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 08:45:09 +00:00

GTextEditor: Allow GTextDocumentSpans to be "skippable"

Setting the is_skippable flag on a GTextDocumentSpan will now cause the
cursor to skip over that span when moving with Ctrl+Left/Right.
This commit is contained in:
Andreas Kling 2019-11-15 20:36:45 +01:00
parent 27a30fdc2a
commit 57f7009b9e
3 changed files with 56 additions and 26 deletions

View file

@ -298,3 +298,37 @@ Vector<GTextRange> GTextDocument::find_all(const StringView& needle) const
}
return ranges;
}
Optional<GTextDocumentSpan> GTextDocument::first_non_skippable_span_before(const GTextPosition& position) const
{
for (int i = m_spans.size() - 1; i >= 0; --i) {
if (!m_spans[i].range.contains(position))
continue;
while ((i - 1) >= 0 && m_spans[i - 1].is_skippable)
--i;
if (i <= 0)
return {};
return m_spans[i - 1];
}
return {};
}
Optional<GTextDocumentSpan> GTextDocument::first_non_skippable_span_after(const GTextPosition& position) const
{
for (int 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];
}
return {};
}