Skip to content

Commit 55cc093

Browse files
committed
InputField: only soften line breaks inside format tags
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
1 parent da44ac8 commit 55cc093

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ui/widgets/fields/input_field.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -1069,11 +1069,6 @@ void ApplyTagFormat(QTextCharFormat &to, const QTextCharFormat &from) {
10691069
text[position] = ch;
10701070
}
10711071
};
1072-
for (auto i = 0, length = int(data.text.size()); i != length; ++i) {
1073-
if (newline(i)) {
1074-
force(i, kSoftLine);
1075-
}
1076-
}
10771072
for (auto i = data.tags.begin(); i != data.tags.end();) {
10781073
auto &tagStart = *i;
10791074
const auto &id = tagStart.id;
@@ -1098,6 +1093,13 @@ void ApplyTagFormat(QTextCharFormat &to, const QTextCharFormat &from) {
10981093
}
10991094
auto &tagEnd = *(j - 1);
11001095

1096+
// Multiple lines in the same formatting tag belong to the same block
1097+
for (auto c = from; c < till; ++c) {
1098+
if (newline(c)) {
1099+
force(c, kSoftLine);
1100+
}
1101+
}
1102+
11011103
if (from > 0 && newline(from - 1)) {
11021104
force(from - 1, kHardLine);
11031105
} else if (newline(from)) {

0 commit comments

Comments
 (0)