| 189 | } |
| 190 | |
| 191 | void 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 | |
| 244 | std::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)}; |
no test coverage detected