From c530d7cc891f6eb86691d067f40dbe9dabc7238b Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 10 Nov 2023 17:43:58 +0400 Subject: [PATCH] Apply Ui::Text::String modifications in highlighting. --- .../history/view/history_view_element.cpp | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 1ba43758618b9..bacc1d8af8c31 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -1673,21 +1673,27 @@ TextSelection Element::FindSelectionFromQuote( } offset = i + 1; } - //for (const auto &modification : text.modifications()) { - // if (modification.position >= selection.to) { - // break; - // } else if (modification.position <= selection.from) { - // modified.from += modification.skipped; - // if (modification.added - // && modification.position < selection.from) { - // --modified.from; - // } - // } - // modified.to += modification.skipped; - // if (modification.added && modified.to > modified.from) { - // --modified.to; - // } - //} + for (const auto &modification : text.modifications()) { + if (modification.position >= result.to) { + break; + } + if (modification.added) { + ++result.to; + } + const auto shiftTo = std::min( + int(modification.skipped), + result.to - modification.position); + result.to -= shiftTo; + if (modification.position <= result.from) { + if (modification.added) { + ++result.from; + } + const auto shiftFrom = std::min( + int(modification.skipped), + result.from - modification.position); + result.from -= shiftFrom; + } + } return result; }