Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Fix word selection when there's hard breaks present.

Wolthera van Hövell tot Westerflier7f1454ca276c
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index 3af47d9db2..71b9f944bb 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -577,6 +577,21 @@ int KoSvgTextShape::wordEnd(int pos)
break;
}
+ // Also test the next cluster on whether it is a hardbreak. This is because hardbreaks by default get hidden.
+ if (i < d->cursorPos.size()-1 && i > pos) {
+ const CursorPos nextCursorPos = d->cursorPos.at(i+1);
+ bool found = false;
+ for (int j = cursorPos.cluster; j < nextCursorPos.cluster; j++) {
+ if (d->result.at(j).breakType == BreakType::HardBreak && d->result.at(j).addressable) {
+ wordEnd = qMax(pos, wordEnd);
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ break;
+ }
+ }
}
return wordEnd;
@@ -598,6 +613,21 @@ int KoSvgTextShape::wordStart(int pos)
&& i < pos) {
break;
}
+ // Also test the previous cluster on whether it is a hardbreak. This is because hardbreaks by default get hidden.
+ if (i > 1 && i < pos) {
+ const CursorPos prevCursorPos = d->cursorPos.at(i-1);
+ bool found = false;
+ for (int j = cursorPos.cluster; j > prevCursorPos.cluster; j--) {
+ if (d->result.at(j).breakType == BreakType::HardBreak && d->result.at(j).addressable) {
+ wordStart = qMin(pos, i-1);
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ break;
+ }
+ }
}
return wordStart;