Skip to content

Commit

Permalink
InputField: only soften line breaks inside format tags
Browse files Browse the repository at this point in the history
In `InputField::PrepareForInsert`, avoid replacing all line break
characters with `kSoftLine` (aka `QChar::LineSeparator`) because that
makes the selection behavior inconsistent (different for typed text and
restored text, e.g., from a draft). Instead, only soften line breaks
inside formatting tags.

Should fix telegramdesktop/tdesktop#28805
  • Loading branch information
kolayne committed Dec 29, 2024
1 parent daf6a61 commit f66a895
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ui/widgets/fields/input_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,11 +1069,6 @@ void ApplyTagFormat(QTextCharFormat &to, const QTextCharFormat &from) {
text[position] = ch;
}
};
for (auto i = 0, length = int(data.text.size()); i != length; ++i) {
if (newline(i)) {
force(i, kSoftLine);
}
}
for (auto i = data.tags.begin(); i != data.tags.end();) {
auto &tagStart = *i;
const auto &id = tagStart.id;
Expand All @@ -1098,6 +1093,13 @@ void ApplyTagFormat(QTextCharFormat &to, const QTextCharFormat &from) {
}
auto &tagEnd = *(j - 1);

// Multiple lines in the same formatting tag belong to the same block
for (auto c = from; c < till; ++c) {
if (newline(c)) {
force(c, kSoftLine);
}
}

if (from > 0 && newline(from - 1)) {
force(from - 1, kHardLine);
} else if (newline(from)) {
Expand Down

0 comments on commit f66a895

Please sign in to comment.