From 56945859e3e7166ec26abf62b0bca0209ad5b498 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Apr 2023 13:36:15 +0400 Subject: [PATCH] Try allowing correct   handling. --- ui/text/text_block.cpp | 36 ++++++++++++++++++++++++++---------- ui/text/text_parser.cpp | 4 ++-- ui/widgets/input_fields.cpp | 3 --- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/ui/text/text_block.cpp b/ui/text/text_block.cpp index 5cd9f92..54ccc74 100644 --- a/ui/text/text_block.cpp +++ b/ui/text/text_block.cpp @@ -185,6 +185,7 @@ public: private: void parseWords(QFixed minResizeWidth, int blockFrom); bool isLineBreak(const QCharAttributes *attributes, int index); + bool isSpaceBreak(const QCharAttributes *attributes, int index); TextBlock *block; QTextEngine *eng; @@ -257,7 +258,17 @@ void BlockParser::parseWords(QFixed minResizeWidth, int blockFrom) { } const QScriptItem ¤t = eng->layoutData->items[item]; - if (attributes[lbh.currentPosition].whiteSpace) { + const auto atSpaceBreak = [&] { + for (auto index = lbh.currentPosition; index < end; ++index) { + if (!attributes[index].whiteSpace) { + return false; + } else if (isSpaceBreak(attributes, index)) { + return true; + } + } + return false; + }(); + if (atSpaceBreak) { while (lbh.currentPosition < end && attributes[lbh.currentPosition].whiteSpace) addNextCluster(lbh.currentPosition, end, lbh.spaceData, lbh.glyphCount, current, lbh.logClusters, lbh.glyphs); @@ -281,7 +292,7 @@ void BlockParser::parseWords(QFixed minResizeWidth, int blockFrom) { current, lbh.logClusters, lbh.glyphs); if (lbh.currentPosition >= eng->layoutData->string.length() - || attributes[lbh.currentPosition].whiteSpace + || isSpaceBreak(attributes, lbh.currentPosition) || isLineBreak(attributes, lbh.currentPosition)) { lbh.calculateRightBearing(); block->_words.push_back(TextWord(wordStart + blockFrom, lbh.tmpData.textWidth, -lbh.negativeRightBearing())); @@ -330,14 +341,19 @@ void BlockParser::parseWords(QFixed minResizeWidth, int blockFrom) { bool BlockParser::isLineBreak( const QCharAttributes *attributes, int index) { - bool lineBreak = attributes[index].lineBreak; - if (lineBreak - && block->lnkIndex() > 0 - && index > 0 - && str.at(index - 1) == '/') { - return false; // don't break after / in links - } - return lineBreak; + // Don't break after / in links. + return attributes[index].lineBreak + && (block->lnkIndex() <= 0 + || index <= 0 + || str[index - 1] != '/'); +} + +bool BlockParser::isSpaceBreak( + const QCharAttributes *attributes, + int index) { + // Don't break on   + return attributes[index].whiteSpace + && (str[index] != QChar::Nbsp); } AbstractBlock::AbstractBlock( diff --git a/ui/text/text_parser.cpp b/ui/text/text_parser.cpp index 61c7ab9..41c5da8 100644 --- a/ui/text/text_parser.cpp +++ b/ui/text/text_parser.cpp @@ -422,7 +422,7 @@ void Parser::parseCurrentChar() { _emojiLookback = 0; const auto inCustomEmoji = !_customEmojiData.isEmpty(); const auto isNewLine = !inCustomEmoji && _multiline && IsNewline(_ch); - const auto isSpace = IsSpace(_ch); + const auto replaceWithSpace = IsSpace(_ch) && (_ch != QChar::Nbsp); const auto isDiac = IsDiac(_ch); const auto isTilde = !inCustomEmoji && _checkTilde && (_ch == '~'); const auto skip = [&] { @@ -487,7 +487,7 @@ void Parser::parseCurrentChar() { } if (isNewLine) { createNewlineBlock(); - } else if (isSpace) { + } else if (replaceWithSpace) { _t->_text.push_back(QChar::Space); _allowDiacritic = false; } else { diff --git a/ui/widgets/input_fields.cpp b/ui/widgets/input_fields.cpp index 640efdf..ee7ee3b 100644 --- a/ui/widgets/input_fields.cpp +++ b/ui/widgets/input_fields.cpp @@ -1974,9 +1974,6 @@ QString InputField::getTextPart( if (IsNewline(*ch) && ch->unicode() != '\r') { *ch = QLatin1Char('\n'); } else switch (ch->unicode()) { - case QChar::Nbsp: { - *ch = QLatin1Char(' '); - } break; case QChar::ObjectReplacementCharacter: { if (ch > begin) { result.append(begin, ch - begin);