#pragma once // Spec: INV-social 9 (SelectableTextPopover). // // ViewPtr SelectableTextPopover(ViewPtr content, std::string text, QuoteComposer quote); // // Wraps `content`: a long press (0.5 s, host level) opens a popover (Overlays::popover) anchored at the content with // the raw `text` (max 360 x 400, scrolls beyond), selectable by mouse drag (double click selects a word), and a footer // of icon buttons: select first word, select all, copy (copies the selection or the whole text, then closes) and, // only when quote.active, insert as quote (quote.insert("> " + selected + "\n\n"), then closes). #include #include "screens/components/QuoteComposer.hpp" #include "ui/Views.hpp" namespace dp { ui::ViewPtr SelectableTextPopover(ui::ViewPtr content, std::string text, QuoteComposer quote = {}); // Selection model of the popover (unit tested). Offsets are byte offsets on UTF-8 boundaries. class TextSelection { public: explicit TextSelection(std::string text) : text_(std::move(text)) {} const std::string& text() const { return text_; } int anchor = 0; int caret = 0; bool hasSelection() const { return anchor != caret; } // Selected range, or the whole text when nothing is selected. std::string selectedText() const; void selectAll(); void selectFirstWord(); // first run of non-whitespace private: std::string text_; }; } // namespace dp