MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / process_mouse_left_button

Method process_mouse_left_button

src/RichText/TextBox.cpp:191–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191void TextBox::process_mouse_left_button(Cursor& cur, const Vector2f& pos, int clickCount, bool held, bool shift) {
192 if(clickCount == 1)
193 lastClicksAtCursorPos = 1;
194 else if(clickCount >= 2) {
195 lastClicksAtCursorPos++;
196 if(lastClicksAtCursorPos > 3)
197 lastClicksAtCursorPos = 1;
198 }
199
200 if(clickCount || held) {
201 rebuild();
202
203 cur.pos = get_text_pos_closest_to_point(pos);
204 if(lastClicksCursorPos != cur.pos && clickCount) {
205 lastClicksAtCursorPos = 1;
206 lastClicksCursorPos = cur.pos;
207 }
208 cur.selectionBeginPos = cur.pos;
209 if(lastClicksAtCursorPos && !shift) {
210 if(!cur.selectionEndPosBeforeHeld.has_value()) {
211 cur.selectionEndPos = cur.selectionBeginPos;
212 cur.selectionEndPosBeforeHeld = cur.selectionEndPos;
213 }
214 if(lastClicksAtCursorPos == 3) {
215 cur.selectionEndPos = cur.selectionEndPosBeforeHeld.value();
216 if(cur.selectionBeginPos < cur.selectionEndPos) {
217 cur.selectionBeginPos.fTextByteIndex = 0;
218 cur.selectionEndPos.fTextByteIndex = paragraphs[cur.selectionEndPos.fParagraphIndex].text.size();
219 }
220 else {
221 cur.selectionBeginPos.fTextByteIndex = paragraphs[cur.selectionBeginPos.fParagraphIndex].text.size();
222 cur.selectionEndPos.fTextByteIndex = 0;
223 }
224 }
225 else if(lastClicksAtCursorPos == 2) {
226 cur.selectionEndPos = cur.selectionEndPosBeforeHeld.value();
227 if(cur.selectionBeginPos < cur.selectionEndPos) {
228 cur.selectionBeginPos = move(Movement::LEFT_WORD_TIGHT, cur.selectionBeginPos);
229 cur.selectionEndPos = move(Movement::RIGHT_WORD_TIGHT, cur.selectionEndPos);
230 }
231 else {
232 cur.selectionBeginPos = move(Movement::RIGHT_WORD_TIGHT, cur.selectionBeginPos);
233 cur.selectionEndPos = move(Movement::LEFT_WORD_TIGHT, cur.selectionEndPos);
234 }
235 }
236 }
237
238 cur.previousX = std::nullopt;
239 }
240 else
241 cur.selectionEndPosBeforeHeld = std::nullopt;
242}
243
244std::pair<std::string, TextData> TextBox::process_copy(Cursor& cur) {
245 return {get_text_between(cur.selectionBeginPos, cur.selectionEndPos), get_rich_text_data_between(cur.selectionBeginPos, cur.selectionEndPos)};

Calls 2

valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected