| 633 | } |
| 634 | |
| 635 | void TextEdit::Move(int steps, bool shift, bool ctrl) |
| 636 | { |
| 637 | if (shift && selection_length == 0) |
| 638 | selection_start = cursor_pos; |
| 639 | |
| 640 | // Jump over words if control is pressed. |
| 641 | if (ctrl) |
| 642 | { |
| 643 | if (steps < 0 && cursor_pos.x == 0 && cursor_pos.y > 0) |
| 644 | { |
| 645 | cursor_pos.x = (int)lines[cursor_pos.y - 1].text.size(); |
| 646 | cursor_pos.y--; |
| 647 | } |
| 648 | else if (steps > 0 && cursor_pos.x == (int)lines[cursor_pos.y].text.size() && cursor_pos.y + 1 < (int)lines.size()) |
| 649 | { |
| 650 | cursor_pos.x = 0; |
| 651 | cursor_pos.y++; |
| 652 | } |
| 653 | |
| 654 | ivec2 new_pos; |
| 655 | if (steps < 0) |
| 656 | new_pos = FindPreviousBreakCharacter(cursor_pos); |
| 657 | else |
| 658 | new_pos = FindNextBreakCharacter(cursor_pos); |
| 659 | |
| 660 | cursor_pos = new_pos; |
| 661 | } |
| 662 | else if (steps < 0 && cursor_pos.x == 0 && cursor_pos.y > 0) |
| 663 | { |
| 664 | cursor_pos.x = (int)lines[cursor_pos.y - 1].text.size(); |
| 665 | cursor_pos.y--; |
| 666 | } |
| 667 | else if (steps > 0 && cursor_pos.x == (int)lines[cursor_pos.y].text.size() && cursor_pos.y + 1 < (int)lines.size()) |
| 668 | { |
| 669 | cursor_pos.x = 0; |
| 670 | cursor_pos.y++; |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | UTF8Reader utf8_reader(lines[cursor_pos.y].text.data(), lines[cursor_pos.y].text.length()); |
| 675 | utf8_reader.set_position(cursor_pos.x); |
| 676 | if (steps > 0) |
| 677 | { |
| 678 | for (int i = 0; i < steps; i++) |
| 679 | utf8_reader.next(); |
| 680 | } |
| 681 | else if (steps < 0) |
| 682 | { |
| 683 | for (int i = 0; i < -steps; i++) |
| 684 | utf8_reader.prev(); |
| 685 | } |
| 686 | |
| 687 | cursor_pos.x = (int)utf8_reader.position(); |
| 688 | } |
| 689 | |
| 690 | if (shift) |
| 691 | { |
| 692 | selection_length = (int)ToOffset(cursor_pos) - (int)ToOffset(selection_start); |