@@ -21,15 +21,14 @@ pub fn init(context: *Context) Self {
2121pub fn handleKeyStroke (self : * Self , key : vaxis.Key , km : Config.KeyMap ) ! void {
2222 // O(n) but n is small
2323 // Centralized key handling
24- const key_actions = &[_ ]KeyAction {
24+ const allocator = self .context .arena .allocator ();
25+ const key_actions = try allocator .dupe (KeyAction , &[_ ]KeyAction {
2526 .{
2627 .codepoint = km .next .codepoint ,
2728 .mods = km .next .mods ,
2829 .handler = struct {
2930 fn action (s : * Context ) void {
30- if (s .document_handler .changePage (1 )) {
31- s .resetCurrentPage ();
32- }
31+ if (s .document_handler .changePage (1 )) s .resetCurrentPage ();
3332 }
3433 }.action ,
3534 },
@@ -38,9 +37,7 @@ pub fn handleKeyStroke(self: *Self, key: vaxis.Key, km: Config.KeyMap) !void {
3837 .mods = km .prev .mods ,
3938 .handler = struct {
4039 fn action (s : * Context ) void {
41- if (s .document_handler .changePage (-1 )) {
42- s .resetCurrentPage ();
43- }
40+ if (s .document_handler .changePage (-1 )) s .resetCurrentPage ();
4441 }
4542 }.action ,
4643 },
@@ -49,7 +46,17 @@ pub fn handleKeyStroke(self: *Self, key: vaxis.Key, km: Config.KeyMap) !void {
4946 .mods = km .zoom_in .mods ,
5047 .handler = struct {
5148 fn action (s : * Context ) void {
52- s .document_handler .zoomIn ();
49+ s .document_handler .zoomIn (1.0 );
50+ s .reload_page = true ;
51+ }
52+ }.action ,
53+ },
54+ .{
55+ .codepoint = km .zoom_in_mult .codepoint ,
56+ .mods = km .zoom_in_mult .mods ,
57+ .handler = struct {
58+ fn action (s : * Context ) void {
59+ s .document_handler .zoomIn (s .config .general .zoom_mult );
5360 s .reload_page = true ;
5461 }
5562 }.action ,
@@ -59,7 +66,17 @@ pub fn handleKeyStroke(self: *Self, key: vaxis.Key, km: Config.KeyMap) !void {
5966 .mods = km .zoom_out .mods ,
6067 .handler = struct {
6168 fn action (s : * Context ) void {
62- s .document_handler .zoomOut ();
69+ s .document_handler .zoomOut (1.0 );
70+ s .reload_page = true ;
71+ }
72+ }.action ,
73+ },
74+ .{
75+ .codepoint = km .zoom_out_mult .codepoint ,
76+ .mods = km .zoom_out_mult .mods ,
77+ .handler = struct {
78+ fn action (s : * Context ) void {
79+ s .document_handler .zoomOut (s .config .general .zoom_mult );
6380 s .reload_page = true ;
6481 }
6582 }.action ,
@@ -91,7 +108,17 @@ pub fn handleKeyStroke(self: *Self, key: vaxis.Key, km: Config.KeyMap) !void {
91108 .mods = km .scroll_up .mods ,
92109 .handler = struct {
93110 fn action (s : * Context ) void {
94- s .document_handler .scroll (.Up );
111+ s .document_handler .scroll (.Up , 1.0 );
112+ s .reload_page = true ;
113+ }
114+ }.action ,
115+ },
116+ .{
117+ .codepoint = km .scroll_up_mult .codepoint ,
118+ .mods = km .scroll_up_mult .mods ,
119+ .handler = struct {
120+ fn action (s : * Context ) void {
121+ s .document_handler .scroll (.Up , s .config .general .scroll_mult );
95122 s .reload_page = true ;
96123 }
97124 }.action ,
@@ -101,7 +128,17 @@ pub fn handleKeyStroke(self: *Self, key: vaxis.Key, km: Config.KeyMap) !void {
101128 .mods = km .scroll_down .mods ,
102129 .handler = struct {
103130 fn action (s : * Context ) void {
104- s .document_handler .scroll (.Down );
131+ s .document_handler .scroll (.Down , 1.0 );
132+ s .reload_page = true ;
133+ }
134+ }.action ,
135+ },
136+ .{
137+ .codepoint = km .scroll_down_mult .codepoint ,
138+ .mods = km .scroll_down_mult .mods ,
139+ .handler = struct {
140+ fn action (s : * Context ) void {
141+ s .document_handler .scroll (.Down , s .config .general .scroll_mult );
105142 s .reload_page = true ;
106143 }
107144 }.action ,
@@ -111,7 +148,17 @@ pub fn handleKeyStroke(self: *Self, key: vaxis.Key, km: Config.KeyMap) !void {
111148 .mods = km .scroll_left .mods ,
112149 .handler = struct {
113150 fn action (s : * Context ) void {
114- s .document_handler .scroll (.Left );
151+ s .document_handler .scroll (.Left , 1.0 );
152+ s .reload_page = true ;
153+ }
154+ }.action ,
155+ },
156+ .{
157+ .codepoint = km .scroll_left_mult .codepoint ,
158+ .mods = km .scroll_left_mult .mods ,
159+ .handler = struct {
160+ fn action (s : * Context ) void {
161+ s .document_handler .scroll (.Left , s .config .general .scroll_mult );
115162 s .reload_page = true ;
116163 }
117164 }.action ,
@@ -121,7 +168,17 @@ pub fn handleKeyStroke(self: *Self, key: vaxis.Key, km: Config.KeyMap) !void {
121168 .mods = km .scroll_right .mods ,
122169 .handler = struct {
123170 fn action (s : * Context ) void {
124- s .document_handler .scroll (.Right );
171+ s .document_handler .scroll (.Right , 1.0 );
172+ s .reload_page = true ;
173+ }
174+ }.action ,
175+ },
176+ .{
177+ .codepoint = km .scroll_right_mult .codepoint ,
178+ .mods = km .scroll_right_mult .mods ,
179+ .handler = struct {
180+ fn action (s : * Context ) void {
181+ s .document_handler .scroll (.Right , s .config .general .scroll_mult );
125182 s .reload_page = true ;
126183 }
127184 }.action ,
@@ -145,7 +202,7 @@ pub fn handleKeyStroke(self: *Self, key: vaxis.Key, km: Config.KeyMap) !void {
145202 }
146203 }.action ,
147204 },
148- };
205+ }) ;
149206
150207 for (key_actions ) | action | {
151208 if (key .matches (action .codepoint , action .mods )) {
0 commit comments