Added utility to replace spoiler entities with text commands.
This commit is contained in:
parent
fc6c3841ee
commit
9c1572564b
2 changed files with 19 additions and 0 deletions
|
|
@ -2332,6 +2332,22 @@ void SetClipboardText(
|
|||
}
|
||||
}
|
||||
|
||||
QString TextWithSpoilerCommands(const TextWithEntities &textWithEntities) {
|
||||
auto text = textWithEntities.text;
|
||||
auto offset = 0;
|
||||
const auto start = textcmdStartSpoiler();
|
||||
const auto stop = textcmdStopSpoiler();
|
||||
for (const auto &e : textWithEntities.entities) {
|
||||
if (e.type() == EntityType::Spoiler) {
|
||||
text.insert(e.offset() + offset, start);
|
||||
offset += start.size();
|
||||
text.insert(e.offset() + e.length() + offset, stop);
|
||||
offset += stop.size();
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
} // namespace TextUtilities
|
||||
|
||||
EntityInText::EntityInText(
|
||||
|
|
|
|||
|
|
@ -381,4 +381,7 @@ void SetClipboardText(
|
|||
const TextForMimeData &text,
|
||||
QClipboard::Mode mode = QClipboard::Clipboard);
|
||||
|
||||
[[nodiscard]] QString TextWithSpoilerCommands(
|
||||
const TextWithEntities &textWithEntities);
|
||||
|
||||
} // namespace TextUtilities
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue