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 next and previous position retrieval in KoSvgTextShape
Wolthera van Hövell tot Westerflierdba50da94aac
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex ae3d6817b0..f6b3e19469 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -552,19 +552,28 @@ int KoSvgTextShape::previousLine(int pos)int KoSvgTextShape::wordEnd(int pos){- if (pos < 0 || pos > d->cursorPos.size()-1 || d->result.isEmpty() || d->cursorPos.isEmpty()) {- return pos;- }- int currentLineEnd = lineEnd(pos);- if (pos == lineStart(pos) || pos == currentLineEnd) {+ if (pos < 0 || pos >= d->cursorPos.size() || d->result.isEmpty() || d->cursorPos.isEmpty()) {return pos;}int wordEnd = pos;- for (int i = pos; i<= currentLineEnd; i++) {+ for (int i = pos; i < d->cursorPos.size(); i++) {wordEnd = i;CursorPos cursorPos = d->cursorPos.at(i);- if (d->result.at(cursorPos.cluster).cursorInfo.isWordBoundary && cursorPos.offset == 0) {+ bool isWhiteSpace = false;+ const CharacterResult res = d->result.at(cursorPos.cluster);+ const int pIndex = res.plaintTextIndex;+ if (pIndex >= 0 && pIndex < d->plainText.size()) {+ QChar c = d->plainText.at(pIndex);+ isWhiteSpace = KoCssTextUtils::IsCssWordSeparator(QString(c)) || c.isSpace();+ }+ if (res.breakType != BreakType::NoBreak+ && (cursorPos.offset == 0 || cursorPos.offset+1 == res.cursorInfo.offsets.size())+ && i > pos) {++ if (isWhiteSpace) {+ wordEnd = qMax(pos, wordEnd-1);+ }break;}@@ -575,23 +584,20 @@ int KoSvgTextShape::wordEnd(int pos)int KoSvgTextShape::wordStart(int pos){- if (pos < 0 || pos > d->cursorPos.size()-1 || d->result.isEmpty() || d->cursorPos.isEmpty()) {- return pos;- }- int currentLineStart = lineStart(pos);- if (pos == currentLineStart || pos == lineEnd(pos)) {+ if (pos <= 0 || pos > d->cursorPos.size() || d->result.isEmpty() || d->cursorPos.isEmpty()) {return pos;}int wordStart = pos;- bool breakNext = false;- for (int i = pos; i >= currentLineStart; i--) {- if (breakNext) break;+ for (int i = pos; i >= 0; i--) {+ wordStart = i;CursorPos cursorPos = d->cursorPos.at(i);- if (d->result.at(cursorPos.cluster).cursorInfo.isWordBoundary && cursorPos.offset == 0) {- breakNext = true;+ const CharacterResult res = d->result.at(cursorPos.cluster);+ if (res.breakType != BreakType::NoBreak+ && (cursorPos.offset == 0 || cursorPos.offset+1 == res.cursorInfo.offsets.size())+ && i < pos) {+ break;}- wordStart = i;}return wordStart;diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.hindex 63ea0e81d7..94488ebb51 100644--- a/libs/flake/text/KoSvgTextShape_p.h+++ b/libs/flake/text/KoSvgTextShape_p.h@@ -65,7 +65,7 @@ struct CursorInfo {struct CursorPos {int cluster; ///< Which character result this position belongs in.int index; ///< Which grapheme this position belongs with.- int offset; ///< Which offset this position belongs with.+ int offset = 0; ///< Which offset this position belongs with.bool synthetic = false; ///< Whether this position was inserted to have a visual indicator.};