mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-05 08:55:59 +00:00
Improved message edition with pre-selected text.
This commit is contained in:
@@ -1037,3 +1037,28 @@ base::unique_qptr<Ui::RpWidget> PremiumRequiredSendRestriction(
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
void SelectTextInFieldWithMargins(
|
||||
not_null<Ui::InputField*> field,
|
||||
const TextSelection &selection) {
|
||||
if (selection.empty()) {
|
||||
return;
|
||||
}
|
||||
auto textCursor = field->textCursor();
|
||||
// Try to set equal margins for top and bottom sides.
|
||||
const auto charsCountInLine = field->width()
|
||||
/ field->st().font->width('W');
|
||||
const auto linesCount = (field->height() / field->st().font->height);
|
||||
const auto selectedLines = (selection.to - selection.from)
|
||||
/ charsCountInLine;
|
||||
constexpr auto kMinDiff = ushort(3);
|
||||
if ((linesCount - selectedLines) > kMinDiff) {
|
||||
textCursor.setPosition(selection.from
|
||||
- charsCountInLine * ((linesCount - 1) / 2));
|
||||
field->setTextCursor(textCursor);
|
||||
}
|
||||
textCursor.setPosition(selection.from);
|
||||
field->setTextCursor(textCursor);
|
||||
textCursor.setPosition(selection.to, QTextCursor::KeepAnchor);
|
||||
field->setTextCursor(textCursor);
|
||||
}
|
||||
|
Reference in New Issue
Block a user