| 361 | } |
| 362 | |
| 363 | void TextEdit::OnKeyDown(EInputKey key) |
| 364 | { |
| 365 | if (!readonly && key == IK_Enter) |
| 366 | { |
| 367 | if (FuncEnterPressed) |
| 368 | { |
| 369 | FuncEnterPressed(); |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | ClearSelection(); |
| 374 | InsertText(cursor_pos, "\n"); |
| 375 | SetCursorPos(GetCursorPos() + 1); |
| 376 | } |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | if (!readonly) // Do not flash cursor when readonly |
| 381 | { |
| 382 | cursor_blink_visible = true; |
| 383 | timer->Start(500); // don't blink cursor when moving or typing. |
| 384 | } |
| 385 | |
| 386 | if (key == IK_Enter || key == IK_Escape || key == IK_Tab) |
| 387 | { |
| 388 | // Do not consume these. |
| 389 | return; |
| 390 | } |
| 391 | else if (key == IK_A && GetKeyState(IK_Ctrl)) |
| 392 | { |
| 393 | // select all |
| 394 | SelectAll(); |
| 395 | } |
| 396 | else if (key == IK_C && GetKeyState(IK_Ctrl)) |
| 397 | { |
| 398 | std::string str = GetSelection(); |
| 399 | SetClipboardText(str); |
| 400 | } |
| 401 | else if (readonly) |
| 402 | { |
| 403 | // Do not consume messages on read only component (only allow CTRL-A and CTRL-C) |
| 404 | return; |
| 405 | } |
| 406 | else if (key == IK_Up) |
| 407 | { |
| 408 | if (GetKeyState(IK_Shift) && selection_length == 0) |
| 409 | selection_start = cursor_pos; |
| 410 | |
| 411 | if (cursor_pos.y > 0) |
| 412 | { |
| 413 | cursor_pos.y--; |
| 414 | cursor_pos.x = std::min(lines[cursor_pos.y].text.size(), (size_t)cursor_pos.x); |
| 415 | } |
| 416 | |
| 417 | if (GetKeyState(IK_Shift)) |
| 418 | { |
| 419 | selection_length = ToOffset(cursor_pos) - ToOffset(selection_start); |
| 420 | } |