chiark / gitweb /
script: Suppress default actions of our keystrokes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 9 Apr 2021 17:57:54 +0000 (18:57 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 9 Apr 2021 17:57:54 +0000 (18:57 +0100)
In particular, this means that pressing SPC to cancel a special
selection mode will no longer scroll the main window.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
templates/script.ts

index 66bcf57577621598b7d87a61992e35ba69645caf..5cc48fb89137d5fe2007e46d66a533e1f7c04b6f 100644 (file)
@@ -429,27 +429,35 @@ function some_keydown(e: KeyboardEvent) {
     if (tag == 'INPUT') return;
   }
 
+  let y = function() { e.preventDefault(); e.stopPropagation(); }
+
   let pane = pane_keys[e.key];
   if (pane) {
+    y();
     return pane_switch(pane);
   }
 
   let special_count_key = parseInt(e.key);
   if (isFinite(special_count_key)) {
+    y();
     if (special_count == null) special_count = 0;
     special_count *= 10;
     special_count += special_count_key;
     special_count %= 100;
     special_count_reupdate();
+    return;
   }
   if (e.key == ' ') {
+    y();
     special_count = null;
     special_count_reupdate();
+    return;
   }
 
   let uo = uo_map[e.key];
   if (uo === undefined || uo === null) return;
 
+  y();
   console.log('KEY UO', e, uo);
   if (uo.kind == 'Client' || uo.kind == 'ClientExtra') {
     let f = keyops_local[uo.opname];