1+ #include "key_handlers.h"
2+
3+ #include "video/VGA_text.h"
4+
5+ void specialHandler (KeyPress out ) {
6+ if (!(out .modifiers & KEY_MOD_SHIFT )) {
7+ switch (out .code ) {
8+ case Key_backspace :
9+ if (getCursor ()-> highlight_offset ) {
10+ highlightDeletePrev (getCursor ()-> highlight_offset );
11+ getCursor ()-> highlight_offset = 0 ;
12+ } else
13+ deletePrevChar ();
14+ break ;
15+ case Key_delete :
16+ if (getCursor ()-> highlight_offset ) {
17+ highlightDeleteCurrent (getCursor ()-> highlight_offset );
18+ getCursor ()-> highlight_offset = 0 ;
19+ } else
20+ deleteCurrentChar ();
21+ break ;
22+ case Key_left :
23+ if (getCursor ()-> highlight_offset ) {
24+ cursorHighlightLeft (getCursor ()-> highlight_offset );
25+ getCursor ()-> highlight_offset = 0 ;
26+ } else
27+ cursorLeft ();
28+ break ;
29+ case Key_down :
30+ if (getCursor ()-> highlight_offset ) {
31+ cursorHighlightDown (getCursor ()-> highlight_offset );
32+ getCursor ()-> highlight_offset = 0 ;
33+ } else
34+ cursorDown ();
35+ break ;
36+ case Key_up :
37+ if (getCursor ()-> highlight_offset ) {
38+ cursorHighlightUp (getCursor ()-> highlight_offset );
39+ getCursor ()-> highlight_offset = 0 ;
40+ } else
41+ cursorUp ();
42+ break ;
43+ case Key_right :
44+ if (getCursor ()-> highlight_offset ) {
45+ cursorHighlightRight (getCursor ()-> highlight_offset );
46+ getCursor ()-> highlight_offset = 0 ;
47+ } else
48+ cursorRight ();
49+ break ;
50+ default :
51+ break ;
52+ }
53+ } else {
54+ if (((out .code == Key_up || out .code == Key_left ) &&
55+ cursorIsAtStart ()) ||
56+ ((out .code == Key_down || out .code == Key_right ) &&
57+ cursorIsAtEnd ()))
58+ return ;
59+ if ((out .code == Key_up || out .code == Key_left ||
60+ out .code == Key_down || out .code == Key_right ) &&
61+ !getCursor ()-> highlight_offset )
62+ highlightCurrentChar ();
63+ switch (out .code ) {
64+ case Key_up :
65+ for (int i = 0 ; i < VGA_WIDTH && !cursorIsAtStart (); i ++ ) {
66+ if (getCursor ()-> highlight_offset > 0 ) {
67+ highlightCurrentChar ();
68+ cursorLeft ();
69+ } else {
70+ cursorLeft ();
71+ highlightCurrentChar ();
72+ }
73+ getCursor ()-> highlight_offset -- ;
74+ }
75+ break ;
76+ case Key_down :
77+ for (int i = 0 ; i < VGA_WIDTH && !cursorIsAtEnd (); i ++ ) {
78+ if (getCursor ()-> highlight_offset < 0 ) {
79+ highlightCurrentChar ();
80+ cursorRight ();
81+ } else {
82+ cursorRight ();
83+ highlightCurrentChar ();
84+ }
85+ getCursor ()-> highlight_offset ++ ;
86+ }
87+ break ;
88+ case Key_left :
89+ if (getCursor ()-> highlight_offset > 0 ) {
90+ highlightCurrentChar ();
91+ cursorLeft ();
92+ } else {
93+ cursorLeft ();
94+ highlightCurrentChar ();
95+ }
96+ getCursor ()-> highlight_offset -- ;
97+ break ;
98+ case Key_right :
99+ if (getCursor ()-> highlight_offset < 0 ) {
100+ highlightCurrentChar ();
101+ cursorRight ();
102+ } else {
103+ cursorRight ();
104+ highlightCurrentChar ();
105+ }
106+ getCursor ()-> highlight_offset ++ ;
107+ break ;
108+ default :
109+ break ;
110+ }
111+ if ((out .code == Key_up || out .code == Key_left ||
112+ out .code == Key_down || out .code == Key_right ) &&
113+ !getCursor ()-> highlight_offset )
114+ highlightCurrentChar ();
115+ }
116+ }
0 commit comments