147 lines
5.8 KiB
Diff
147 lines
5.8 KiB
Diff
From cd5433133464671beea1607ed7d79f43cb4cf1b8 Mon Sep 17 00:00:00 2001
|
|
From: Pino Toscano <pino@kde.org>
|
|
Date: Sun, 24 May 2026 06:36:07 +0200
|
|
Subject: [PATCH 1/2] refactor: rename getLineRange(int) to
|
|
getLineRangeForLine()
|
|
|
|
To help distinguish the two getLineRange() functions, rename the "int"
|
|
variant to getLineRangeForLine(), to indicate its input is a line
|
|
number.
|
|
---
|
|
src/gui/autotests/textitemtest.cpp | 4 ++--
|
|
src/gui/item/text.cpp | 4 ++--
|
|
src/gui/item/text.hpp | 2 +-
|
|
3 files changed, 5 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/src/gui/autotests/textitemtest.cpp b/src/gui/autotests/textitemtest.cpp
|
|
index 143496e3..350e7016 100644
|
|
--- a/src/gui/autotests/textitemtest.cpp
|
|
+++ b/src/gui/autotests/textitemtest.cpp
|
|
@@ -145,11 +145,11 @@ void TextItemTest::shouldTestLineRange()
|
|
TextItem i;
|
|
i.insertText(u"Line 1\nLine 2\nLine 3"_s);
|
|
|
|
- auto range1 = i.getLineRange(1);
|
|
+ auto range1 = i.getLineRangeForLine(1);
|
|
QCOMPARE(range1.first, 0);
|
|
QCOMPARE(range1.second, 6);
|
|
|
|
- auto range2 = i.getLineRange(2);
|
|
+ auto range2 = i.getLineRangeForLine(2);
|
|
QCOMPARE(range2.first, 7);
|
|
QCOMPARE(range2.second, 13);
|
|
}
|
|
diff --git a/src/gui/item/text.cpp b/src/gui/item/text.cpp
|
|
index 1a894b1b..441e1968 100644
|
|
--- a/src/gui/item/text.cpp
|
|
+++ b/src/gui/item/text.cpp
|
|
@@ -205,7 +205,7 @@ qsizetype TextItem::getIndexFromX(double xPos, int lineNumber) const
|
|
{
|
|
const QFontMetricsF metrics{getFont()};
|
|
|
|
- auto [start, end] = getLineRange(lineNumber);
|
|
+ auto [start, end] = getLineRangeForLine(lineNumber);
|
|
const QString line{m_text.mid(start, end - start + 1)};
|
|
|
|
const double distanceFromLeft{std::max(xPos - m_boundingBox.x(), 0.0)};
|
|
@@ -390,7 +390,7 @@ QPen TextItem::getPen() const
|
|
return pen;
|
|
}
|
|
|
|
-std::pair<qsizetype, qsizetype> TextItem::getLineRange(int lineNumber) const
|
|
+std::pair<qsizetype, qsizetype> TextItem::getLineRangeForLine(int lineNumber) const
|
|
{
|
|
const qsizetype len{m_text.length()};
|
|
|
|
diff --git a/src/gui/item/text.hpp b/src/gui/item/text.hpp
|
|
index 813a2cdf..34234c8c 100644
|
|
--- a/src/gui/item/text.hpp
|
|
+++ b/src/gui/item/text.hpp
|
|
@@ -55,7 +55,7 @@ public:
|
|
|
|
[[nodiscard]] bool hasSelection() const;
|
|
|
|
- [[nodiscard]] std::pair<qsizetype, qsizetype> getLineRange(int lineNumber) const;
|
|
+ [[nodiscard]] std::pair<qsizetype, qsizetype> getLineRangeForLine(int lineNumber) const;
|
|
[[nodiscard]] std::pair<qsizetype, qsizetype> getLineRange(qsizetype position) const;
|
|
|
|
[[nodiscard]] qsizetype getPrevBreak(qsizetype pos) const;
|
|
--
|
|
GitLab
|
|
|
|
|
|
From d400876774a4c2481bebf425a830e0a4642fd3ee Mon Sep 17 00:00:00 2001
|
|
From: Pino Toscano <pino@kde.org>
|
|
Date: Sun, 24 May 2026 06:38:02 +0200
|
|
Subject: [PATCH 2/2] refactor: rename getLineRange(qsizetype) to
|
|
getLineRangeForPosition()
|
|
|
|
To help distinguish the two getLineRange() functions, rename the
|
|
"qsizetype" variant to getLineRangeForPosition(), to indicate its input
|
|
is a position in the text stream.
|
|
---
|
|
src/gui/item/text.cpp | 4 ++--
|
|
src/gui/item/text.hpp | 2 +-
|
|
src/widgets/tools/texttool.cpp | 4 ++--
|
|
3 files changed, 5 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/src/gui/item/text.cpp b/src/gui/item/text.cpp
|
|
index 441e1968..5b06112c 100644
|
|
--- a/src/gui/item/text.cpp
|
|
+++ b/src/gui/item/text.cpp
|
|
@@ -62,7 +62,7 @@ void TextItem::draw(QPainter &painter, const QPointF &offset)
|
|
// Drawing the caret
|
|
// PERF: There is no need to scan the entire text just to place the caret
|
|
// This can be a lot more efficient, so feel free to open a PR
|
|
- auto [start, end] = getLineRange(cur);
|
|
+ auto [start, end] = getLineRangeForPosition(cur);
|
|
const QString &curLine{m_text.mid(start, cur - start)};
|
|
|
|
int lineCount{0};
|
|
@@ -414,7 +414,7 @@ std::pair<qsizetype, qsizetype> TextItem::getLineRangeForLine(int lineNumber) co
|
|
return std::make_pair(startIndex, endIndex);
|
|
}
|
|
|
|
-std::pair<qsizetype, qsizetype> TextItem::getLineRange(qsizetype position) const
|
|
+std::pair<qsizetype, qsizetype> TextItem::getLineRangeForPosition(qsizetype position) const
|
|
{
|
|
qsizetype start{m_text.lastIndexOf(u'\n', position - 1)};
|
|
if (start == -1 || position == 0) {
|
|
diff --git a/src/gui/item/text.hpp b/src/gui/item/text.hpp
|
|
index 34234c8c..0d1cf6d7 100644
|
|
--- a/src/gui/item/text.hpp
|
|
+++ b/src/gui/item/text.hpp
|
|
@@ -56,7 +56,7 @@ public:
|
|
[[nodiscard]] bool hasSelection() const;
|
|
|
|
[[nodiscard]] std::pair<qsizetype, qsizetype> getLineRangeForLine(int lineNumber) const;
|
|
- [[nodiscard]] std::pair<qsizetype, qsizetype> getLineRange(qsizetype position) const;
|
|
+ [[nodiscard]] std::pair<qsizetype, qsizetype> getLineRangeForPosition(qsizetype position) const;
|
|
|
|
[[nodiscard]] qsizetype getPrevBreak(qsizetype pos) const;
|
|
[[nodiscard]] qsizetype getNextBreak(qsizetype pos) const;
|
|
diff --git a/src/widgets/tools/texttool.cpp b/src/widgets/tools/texttool.cpp
|
|
index e05eb700..8a042944 100644
|
|
--- a/src/widgets/tools/texttool.cpp
|
|
+++ b/src/widgets/tools/texttool.cpp
|
|
@@ -141,7 +141,7 @@ void TextTool::mouseMoved(ApplicationContext *context)
|
|
m_curItem->setSelectionEnd(m_curItem->getNextBreak(curIndex));
|
|
}
|
|
} else if (m_tripleClicked) {
|
|
- auto [start, end] = m_curItem->getLineRange(curIndex);
|
|
+ auto [start, end] = m_curItem->getLineRangeForPosition(curIndex);
|
|
if (isLeft) {
|
|
m_curItem->setSelectionStart(std::max(curStart, curEnd));
|
|
m_curItem->setSelectionEnd(start);
|
|
@@ -217,7 +217,7 @@ void TextTool::mouseTripleClick(ApplicationContext *context)
|
|
|
|
const qsizetype curIndex{m_curItem->getIndexFromCursor(worldPos)};
|
|
|
|
- const auto [start, end] = m_curItem->getLineRange(curIndex);
|
|
+ const auto [start, end] = m_curItem->getLineRangeForPosition(curIndex);
|
|
m_curItem->setSelectionStart(start);
|
|
m_curItem->setSelectionEnd(end + 1);
|
|
|
|
--
|
|
GitLab
|