@@ -206,90 +206,38 @@ void TerminalWidget::keydown_event(GUI::KeyEvent& event)
206
206
m_cursor_blink_timer->stop ();
207
207
m_cursor_blink_state = true ;
208
208
m_cursor_blink_timer->start ();
209
- auto ctrl_held = !!(event.modifiers () & Mod_Ctrl);
210
209
211
- switch (event.key ()) {
212
- case KeyCode::Key_Up:
213
- write (m_ptm_fd, ctrl_held ? " \033 [OA" : " \033 [A" , 3 + ctrl_held);
214
- return ;
215
- case KeyCode::Key_Down:
216
- write (m_ptm_fd, ctrl_held ? " \033 [OB" : " \033 [B" , 3 + ctrl_held);
217
- return ;
218
- case KeyCode::Key_Right:
219
- write (m_ptm_fd, ctrl_held ? " \033 [OC" : " \033 [C" , 3 + ctrl_held);
220
- return ;
221
- case KeyCode::Key_Left:
222
- write (m_ptm_fd, ctrl_held ? " \033 [OD" : " \033 [D" , 3 + ctrl_held);
223
- return ;
224
- case KeyCode::Key_Insert:
225
- write (m_ptm_fd, " \033 [2~" , 4 );
210
+ if (event.key () == KeyCode::Key_PageUp && event.modifiers () == Mod_Shift) {
211
+ m_scrollbar->set_value (m_scrollbar->value () - m_terminal.rows ());
226
212
return ;
227
- case KeyCode::Key_Delete:
228
- write (m_ptm_fd, " \033 [3~" , 4 );
229
- return ;
230
- case KeyCode::Key_Home:
231
- write (m_ptm_fd, " \033 [H" , 3 );
232
- return ;
233
- case KeyCode::Key_End:
234
- write (m_ptm_fd, " \033 [F" , 3 );
235
- return ;
236
- case KeyCode::Key_PageUp:
237
- if (event.modifiers () == Mod_Shift) {
238
- m_scrollbar->set_value (m_scrollbar->value () - m_terminal.rows ());
239
- return ;
240
- }
241
- write (m_ptm_fd, " \033 [5~" , 4 );
242
- return ;
243
- case KeyCode::Key_PageDown:
244
- if (event.modifiers () == Mod_Shift) {
245
- m_scrollbar->set_value (m_scrollbar->value () + m_terminal.rows ());
246
- return ;
247
- }
248
- write (m_ptm_fd, " \033 [6~" , 4 );
249
- return ;
250
- case KeyCode::Key_Alt:
251
- m_alt_key_held = true ;
213
+ }
214
+ if (event.key () == KeyCode::Key_PageDown && event.modifiers () == Mod_Shift) {
215
+ m_scrollbar->set_value (m_scrollbar->value () + m_terminal.rows ());
252
216
return ;
253
- default :
254
- break ;
255
217
}
256
-
257
- if (event.shift () && event.key () == KeyCode::Key_Tab) {
258
- write (m_ptm_fd, " \033 [Z" , 3 );
218
+ if (event.key () == KeyCode::Key_Alt) {
219
+ m_alt_key_held = true ;
259
220
return ;
260
221
}
261
222
262
- // Key event was not one of the above special cases,
263
- // attempt to treat it as a character...
264
- if (event.text ().length () == 1 ) {
265
- // 1 byte input == ASCII
266
- char ch = !event.text ().is_empty () ? event.text ()[0 ] : 0 ;
267
- if (event.ctrl ()) {
268
- if (ch >= ' a' && ch <= ' z' ) {
269
- ch = ch - ' a' + 1 ;
270
- } else if (ch == ' \\ ' ) {
271
- ch = 0x1c ;
272
- }
273
- }
274
-
275
- // ALT modifier sends escape prefix
276
- if (event.alt ())
277
- write (m_ptm_fd, " \033 " , 1 );
278
-
279
- // Clear the selection if we type in/behind it
280
- auto future_cursor_column = (event.key () == KeyCode::Key_Backspace) ? m_terminal.cursor_column () - 1 : m_terminal.cursor_column ();
281
- auto min_selection_row = min (m_selection_start.row (), m_selection_end.row ());
282
- auto max_selection_row = max (m_selection_start.row (), m_selection_end.row ());
223
+ // Clear the selection if we type in/behind it.
224
+ auto future_cursor_column = (event.key () == KeyCode::Key_Backspace) ? m_terminal.cursor_column () - 1 : m_terminal.cursor_column ();
225
+ auto min_selection_row = min (m_selection_start.row (), m_selection_end.row ());
226
+ auto max_selection_row = max (m_selection_start.row (), m_selection_end.row ());
283
227
284
- if (future_cursor_column <= last_selection_column_on_row (m_terminal.cursor_row ()) && m_terminal.cursor_row () >= min_selection_row && m_terminal.cursor_row () <= max_selection_row) {
285
- m_selection_end = {};
286
- update ();
287
- }
228
+ if (future_cursor_column <= last_selection_column_on_row (m_terminal.cursor_row ()) && m_terminal.cursor_row () >= min_selection_row && m_terminal.cursor_row () <= max_selection_row) {
229
+ m_selection_end = {};
230
+ update ();
231
+ }
288
232
289
- write (m_ptm_fd, &ch, 1 );
290
- } else if (event.text ().length () > 1 ) {
291
- // 2+ byte input == Unicode
233
+ if (event.text ().length () > 2 ) {
234
+ // Unicode (likely emoji), just emit it.
292
235
write (m_ptm_fd, event.text ().characters (), event.text ().length ());
236
+ } else {
237
+ // Ask the terminal to generate the correct character sequence and send
238
+ // it back to us via emit().
239
+ u8 character = event.text ().length () == 1 ? event.text ()[0 ] : 0 ;
240
+ m_terminal.handle_key_press (event.key (), character, event.modifiers ());
293
241
}
294
242
295
243
if (event.key () != Key_Control && event.key () != Key_Alt && event.key () != Key_Shift && event.key () != Key_Logo)
0 commit comments