@@ -775,33 +775,6 @@ function add_page_after() {
775775}
776776
777777
778- function getKeyString ( event ) {
779- const keys = [ ] ;
780-
781- // Check for modifier keys
782- if ( event . ctrlKey ) keys . push ( 'ctrl' ) ;
783- if ( event . shiftKey ) keys . push ( 'shift' ) ;
784- if ( event . altKey ) keys . push ( 'alt' ) ;
785- if ( event . metaKey ) keys . push ( 'meta' ) ;
786-
787- // Map special keys to names if needed
788- const keyMap = {
789- ' ' : 'space'
790- } ;
791-
792- const key = keyMap [ event . key ] || event . key . toLowerCase ( ) ;
793-
794- // If it's a normal key (not a modifier), add it to the keys array
795- if ( ! [ 'shift' , 'ctrl' , 'alt' , 'meta' ] . includes ( key ) ) {
796- keys . push ( key ) ;
797- }
798-
799- const ret = keys . join ( '+' ) ;
800- console . log ( `Got keydown = ${ ret } ` ) ;
801- return ret ;
802- }
803-
804-
805778function get_right_increment ( ) {
806779 // read/index.js has some data rendered at the top of the page.
807780 const lang_is_rtl = $ ( '#lang_is_rtl' ) ;
@@ -819,55 +792,35 @@ function handle_keydown (e) {
819792 return ; // Nothing to do.
820793 }
821794
822- // User hotkeys, to be read from UserSettings.
823- const user_keys = {
824- 'HotkeyStartHover' : 'escape' ,
825- 'HotkeyPrevWord' : 'arrowleft' ,
826- 'HotkeyNextWord' : 'arrowright' ,
827- 'HotkeyStatusUp' : 'arrowup' ,
828- 'HotkeyStatusDown' : 'arrowdown' ,
829- 'HotkeyBookmark' : 'b' ,
830- 'HotkeyCopySentence' : 'c' ,
831- 'HotkeyCopyPara' : 'shift+c' ,
832- 'HotkeyTranslateSentence' : 't' ,
833- 'HotkeyTranslatePara' : 'shift+t' ,
834- 'HotkeyNextTheme' : 'm' ,
835- 'HotkeyToggleHighlight' : 'h' ,
836- 'HotkeyToggleFocus' : 'f' ,
837- 'HotkeyStatus1' : '1' ,
838- 'HotkeyStatus2' : '2' ,
839- 'HotkeyStatus3' : '3' ,
840- 'HotkeyStatus4' : '4' ,
841- 'HotkeyStatus5' : '5' ,
842- 'HotkeyStatusIgnore' : 'i' ,
843- 'HotkeyStatusWellKnown' : 'w' ,
844- } ;
795+ // User hotkeys are stored in LUTE_USER_SETTINGS
796+ // hash in global space.
797+ const k = LUTE_USER_SETTINGS ; // shorthand varname.
845798
846799 // Map of shortcuts to lambdas:
847800 let map = {
848- [ user_keys [ 'HotkeyStartHover' ] ] : ( ) => start_hover_mode ( ) ,
849- [ user_keys [ 'HotkeyPrevWord' ] ] : ( ) => move_cursor ( - 1 * get_right_increment ( ) ) ,
850- [ user_keys [ 'HotkeyNextWord' ] ] : ( ) => move_cursor ( get_right_increment ( ) ) ,
851- [ user_keys [ 'HotkeyStatusUp' ] ] : ( ) => increment_status_for_selected_elements ( + 1 ) ,
852- [ user_keys [ 'HotkeyStatusDown' ] ] : ( ) => increment_status_for_selected_elements ( - 1 ) ,
853- [ user_keys [ 'HotkeyBookmark' ] ] : ( ) => handle_bookmark ( ) ,
854- [ user_keys [ 'HotkeyCopySentence' ] ] : ( ) => handle_copy ( 'sentence-id' ) ,
855- [ user_keys [ 'HotkeyCopyPara' ] ] : ( ) => handle_copy ( 'paragraph-id' ) ,
856- [ user_keys [ 'HotkeyTranslateSentence' ] ] : ( ) => handle_translate ( 'sentence-id' ) ,
857- [ user_keys [ 'HotkeyTranslatePara' ] ] : ( ) => handle_translate ( 'paragraph-id' ) ,
858- [ user_keys [ 'HotkeyNextTheme' ] ] : ( ) => next_theme ( ) ,
859- [ user_keys [ 'HotkeyToggleHighlight' ] ] : ( ) => toggle_highlight ( ) ,
860- [ user_keys [ 'HotkeyToggleFocus' ] ] : ( ) => toggleFocus ( ) ,
861- [ user_keys [ 'HotkeyStatus1' ] ] : ( ) => update_status_for_marked_elements ( 1 ) ,
862- [ user_keys [ 'HotkeyStatus2' ] ] : ( ) => update_status_for_marked_elements ( 2 ) ,
863- [ user_keys [ 'HotkeyStatus3' ] ] : ( ) => update_status_for_marked_elements ( 3 ) ,
864- [ user_keys [ 'HotkeyStatus4' ] ] : ( ) => update_status_for_marked_elements ( 4 ) ,
865- [ user_keys [ 'HotkeyStatus5' ] ] : ( ) => update_status_for_marked_elements ( 5 ) ,
866- [ user_keys [ 'HotkeyStatusIgnore' ] ] : ( ) => update_status_for_marked_elements ( 98 ) ,
867- [ user_keys [ 'HotkeyStatusWellKnown' ] ] : ( ) => update_status_for_marked_elements ( 99 ) ,
868- }
869-
870- const ks = getKeyString ( e ) ;
801+ [ k . hotkey_StartHover ] : ( ) => start_hover_mode ( ) ,
802+ [ k . hotkey_PrevWord ] : ( ) => move_cursor ( - 1 * get_right_increment ( ) ) ,
803+ [ k . hotkey_NextWord ] : ( ) => move_cursor ( get_right_increment ( ) ) ,
804+ [ k . hotkey_StatusUp ] : ( ) => increment_status_for_selected_elements ( + 1 ) ,
805+ [ k . hotkey_StatusDown ] : ( ) => increment_status_for_selected_elements ( - 1 ) ,
806+ [ k . hotkey_Bookmark ] : ( ) => handle_bookmark ( ) ,
807+ [ k . hotkey_CopySentence ] : ( ) => handle_copy ( 'sentence-id' ) ,
808+ [ k . hotkey_CopyPara ] : ( ) => handle_copy ( 'paragraph-id' ) ,
809+ [ k . hotkey_TranslateSentence ] : ( ) => handle_translate ( 'sentence-id' ) ,
810+ [ k . hotkey_TranslatePara ] : ( ) => handle_translate ( 'paragraph-id' ) ,
811+ [ k . hotkey_NextTheme ] : ( ) => next_theme ( ) ,
812+ [ k . hotkey_ToggleHighlight ] : ( ) => toggle_highlight ( ) ,
813+ [ k . hotkey_ToggleFocus ] : ( ) => toggleFocus ( ) ,
814+ [ k . hotkey_Status1 ] : ( ) => update_status_for_marked_elements ( 1 ) ,
815+ [ k . hotkey_Status2 ] : ( ) => update_status_for_marked_elements ( 2 ) ,
816+ [ k . hotkey_Status3 ] : ( ) => update_status_for_marked_elements ( 3 ) ,
817+ [ k . hotkey_Status4 ] : ( ) => update_status_for_marked_elements ( 4 ) ,
818+ [ k . hotkey_Status5 ] : ( ) => update_status_for_marked_elements ( 5 ) ,
819+ [ k . hotkey_StatusIgnore ] : ( ) => update_status_for_marked_elements ( 98 ) ,
820+ [ k . hotkey_StatusWellKnown ] : ( ) => update_status_for_marked_elements ( 99 ) ,
821+ }
822+
823+ const ks = get_pressed_keys_as_string ( e ) ;
871824 if ( ks in map ) {
872825 // Override any existing event - e.g., if "up" arrow is in the map,
873826 // don't scroll screen.
0 commit comments