| 130 | } |
| 131 | |
| 132 | void TextBox::process_key_input(Cursor& cur, InputKey in, bool ctrl, bool shift, const std::optional<TextStyleModifier::ModifierMap>& inputModMap) { |
| 133 | bool moved = false; |
| 134 | |
| 135 | switch(in) { |
| 136 | case InputKey::LEFT: |
| 137 | cur.pos = cur.selectionBeginPos = move(ctrl ? Movement::LEFT_WORD : Movement::LEFT, cur.pos, nullptr, true); |
| 138 | moved = true; |
| 139 | break; |
| 140 | case InputKey::RIGHT: |
| 141 | cur.pos = cur.selectionBeginPos = move(ctrl ? Movement::RIGHT_WORD : Movement::RIGHT, cur.pos, nullptr, true); |
| 142 | moved = true; |
| 143 | break; |
| 144 | case InputKey::UP: |
| 145 | cur.pos = cur.selectionBeginPos = move(Movement::UP, cur.pos, &cur.previousX); |
| 146 | moved = true; |
| 147 | break; |
| 148 | case InputKey::DOWN: |
| 149 | cur.pos = cur.selectionBeginPos = move(Movement::DOWN, cur.pos, &cur.previousX); |
| 150 | moved = true; |
| 151 | break; |
| 152 | case InputKey::HOME: |
| 153 | cur.pos = cur.selectionBeginPos = move(Movement::HOME, cur.pos); |
| 154 | moved = true; |
| 155 | break; |
| 156 | case InputKey::END: |
| 157 | cur.pos = cur.selectionBeginPos = move(Movement::END, cur.pos); |
| 158 | moved = true; |
| 159 | break; |
| 160 | case InputKey::BACKSPACE: |
| 161 | if(cur.selectionBeginPos != cur.selectionEndPos) |
| 162 | cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.selectionBeginPos, cur.selectionEndPos); |
| 163 | else |
| 164 | cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.pos, move(ctrl ? Movement::LEFT_WORD : Movement::LEFT, cur.pos)); |
| 165 | break; |
| 166 | case InputKey::DEL: |
| 167 | if(cur.selectionBeginPos != cur.selectionEndPos) |
| 168 | cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.selectionBeginPos, cur.selectionEndPos); |
| 169 | else |
| 170 | cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.pos, move(ctrl ? Movement::RIGHT_WORD : Movement::RIGHT, cur.pos)); |
| 171 | break; |
| 172 | case InputKey::ENTER: |
| 173 | process_text_input(cur, "\n", inputModMap); |
| 174 | break; |
| 175 | case InputKey::TAB: |
| 176 | process_text_input(cur, "\t", inputModMap); |
| 177 | break; |
| 178 | case InputKey::SELECT_ALL: |
| 179 | cur.selectionBeginPos = move(Movement::HOME, cur.pos); |
| 180 | cur.pos = cur.selectionEndPos = move(Movement::END, cur.pos); |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | if(moved && !shift) |
| 185 | cur.selectionEndPos = cur.selectionBeginPos; |
| 186 | |
| 187 | if(in != InputKey::UP && in != InputKey::DOWN) |
| 188 | cur.previousX = std::nullopt; |
| 189 | } |