Editor: ensure valid blocknumbers for overlay prefiltering

Change-Id: Ifc5f173fe12f3dca77fbcb6c4b8bfe6aa0bad7ea
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2023-06-15 10:26:36 +02:00
parent 039898058c
commit 61de872f0f
2 changed files with 10 additions and 4 deletions

View File

@@ -25,14 +25,17 @@ RefactorOverlay::RefactorOverlay(TextEditor::TextEditorWidget *editor) :
void RefactorOverlay::paint(QPainter *painter, const QRect &clip)
{
const auto firstBlock = m_editor->blockForVerticalOffset(clip.top());
const int firstBlockNumber = firstBlock.isValid() ? firstBlock.blockNumber() : 0;
const auto lastBlock = m_editor->blockForVerticalOffset(clip.bottom());
const int lastBlockNumber = lastBlock.isValid() ? lastBlock.blockNumber()
: m_editor->blockCount() - 1;
m_maxWidth = 0;
for (const RefactorMarker &marker : std::as_const(m_markers)) {
const int markerBlockNumber = marker.cursor.block().blockNumber();
if (markerBlockNumber < firstBlock.blockNumber())
if (markerBlockNumber < firstBlockNumber)
continue;
if (markerBlockNumber > lastBlock.blockNumber())
if (markerBlockNumber > lastBlockNumber)
continue;
paintMarker(marker, painter, clip);
}

View File

@@ -334,11 +334,14 @@ void TextEditorOverlay::paint(QPainter *painter, const QRect &clip)
Q_UNUSED(clip)
const auto firstBlock = m_editor->blockForVerticalOffset(clip.top());
const int firstBlockNumber = firstBlock.isValid() ? firstBlock.blockNumber() : 0;
const auto lastBlock = m_editor->blockForVerticalOffset(clip.bottom());
const int lastBlockNumber = lastBlock.isValid() ? lastBlock.blockNumber()
: m_editor->blockCount() - 1;
auto overlapsClip = [&](const OverlaySelection &selection) {
return selection.m_cursor_end.blockNumber() >= firstBlock.blockNumber()
&& selection.m_cursor_begin.blockNumber() <= lastBlock.blockNumber();
return selection.m_cursor_end.blockNumber() >= firstBlockNumber
&& selection.m_cursor_begin.blockNumber() <= lastBlockNumber;
};
for (int i = m_selections.size() - 1; i >= 0; --i) {