@@ -51,26 +51,23 @@ const Commands = {
51
51
52
52
// Parses the text supplied by the user in their "keyMappings" setting.
53
53
// - shouldLogWarnings: if true, logs to the console when part of the user's config is invalid.
54
- // Returns { keyToRegistryEntry, keyToMappedKey }.
54
+ // Returns { keyToRegistryEntry, keyToMappedKey, validationErrors }.
55
55
parseKeyMappingsConfig ( configText , shouldLogWarnings ) {
56
56
let keyToRegistryEntry = { } ;
57
57
let mapKeyRegistry = { } ;
58
+ const errors = [ ] ;
58
59
59
60
const configLines = Utils . parseLines ( configText ) ;
60
- const logWarning = ( ...args ) => {
61
- if ( ! shouldLogWarnings ) return ;
62
- console . warn . apply ( console , args ) ;
63
- } ;
64
61
65
62
for ( const line of configLines ) {
66
63
const tokens = line . split ( / \s + / ) ;
67
- const command = tokens [ 0 ] . toLowerCase ( ) ;
68
- switch ( command ) {
64
+ const action = tokens [ 0 ] . toLowerCase ( ) ;
65
+ switch ( action ) {
69
66
case "map" :
70
67
if ( tokens . length >= 3 ) {
71
68
const [ _ , key , command , ...optionList ] = tokens ;
72
69
if ( ! this . availableCommands [ command ] ) {
73
- logWarning ( `"${ command } " is not a valid command in the line:` , line ) ;
70
+ errors . push ( `"${ command } " is not a valid command in the line: ${ line } ` ) ;
74
71
continue ;
75
72
}
76
73
const keySequence = this . parseKeySequence ( key ) ;
@@ -87,7 +84,7 @@ const Commands = {
87
84
break ;
88
85
case "unmap" :
89
86
if ( tokens . length != 2 ) {
90
- logWarning ( " Incorrect usage for unmap in the line:" , line ) ;
87
+ errors . push ( ` Incorrect usage for unmap in the line: ${ line } ` ) ;
91
88
continue ;
92
89
}
93
90
const key = tokens [ 1 ] ;
@@ -100,7 +97,7 @@ const Commands = {
100
97
break ;
101
98
case "mapkey" :
102
99
if ( tokens . length != 3 ) {
103
- logWarning ( " Incorrect usage for mapkey in the line:" , line ) ;
100
+ errors . push ( ` Incorrect usage for mapKey in the line: ${ line } ` ) ;
104
101
continue ;
105
102
}
106
103
const fromChar = this . parseKeySequence ( tokens [ 1 ] ) ;
@@ -111,20 +108,20 @@ const Commands = {
111
108
if ( isValid ) {
112
109
mapKeyRegistry [ fromChar [ 0 ] ] = toChar [ 0 ] ;
113
110
} else {
114
- logWarning (
115
- "mapkey only supports mapping keys which are single characters. Line:" ,
116
- line ,
111
+ errors . push (
112
+ `mapkey only supports mapping keys which are single characters. Line: ${ line } ` ,
117
113
) ;
118
114
}
119
115
break ;
120
116
default :
121
- logWarning ( `"${ command } " is not a valid config command in line:` , line ) ;
117
+ errors . push ( `"${ action } " is not a valid config command in line: ${ line } ` ) ;
122
118
}
123
119
}
124
120
125
121
return {
126
122
keyToRegistryEntry,
127
123
keyToMappedKey : mapKeyRegistry ,
124
+ validationErrors : errors ,
128
125
} ;
129
126
} ,
130
127
@@ -257,24 +254,46 @@ const Commands = {
257
254
// Build the "helpPageData" data structure which the help page needs and place it in Chrome
258
255
// storage.
259
256
prepareHelpPageData ( ) {
260
- const commandToKey = { } ;
257
+ /*
258
+ Map of commands to option sets to keys to trigger that command option set.
259
+ Commands with no options will have the empty string options set.
260
+ Example:
261
+ {
262
+ "zoomReset": {
263
+ "": ["z0", "zz"] // No options, with two key maps, ie: `map zz zoomReset`
264
+ },
265
+ "setZoom": {
266
+ "1.1": ["z1"], // `map z1 setZoom 1.1`
267
+ "1.2": ["z2"], // `map z2 setZoom 1.2`
268
+ }
269
+ }
270
+ */
271
+ const commandToOptionsToKeys = { } ;
261
272
for ( const key of Object . keys ( this . keyToRegistryEntry || { } ) ) {
262
273
const registryEntry = this . keyToRegistryEntry [ key ] ;
263
- ( commandToKey [ registryEntry . command ] != null
264
- ? commandToKey [ registryEntry . command ]
265
- : ( commandToKey [ registryEntry . command ] = [ ] ) ) . push ( key ) ;
274
+ const optionString = registryEntry . optionList ?. join ( " " ) || "" ;
275
+ commandToOptionsToKeys [ registryEntry . command ] ||= { } ;
276
+ commandToOptionsToKeys [ registryEntry . command ] [ optionString ] ||= [ ] ;
277
+ commandToOptionsToKeys [ registryEntry . command ] [ optionString ] . push ( key ) ;
266
278
}
267
279
const commandGroups = { } ;
268
280
for ( const group of Object . keys ( this . commandGroups || { } ) ) {
269
281
const commands = this . commandGroups [ group ] ;
270
282
commandGroups [ group ] = [ ] ;
271
283
for ( const command of commands ) {
272
- commandGroups [ group ] . push ( {
273
- command,
274
- description : this . availableCommands [ command ] . description ,
275
- keys : commandToKey [ command ] != null ? commandToKey [ command ] : [ ] ,
276
- advanced : this . advancedCommands . includes ( command ) ,
277
- } ) ;
284
+ // Default to base command has no keys for "show available commands" menu.
285
+ const optionsToKeys = commandToOptionsToKeys [ command ] ?? { "" : [ ] } ;
286
+ for ( const [ options , keys ] of Object . entries ( optionsToKeys ) ) {
287
+ const advanced = this . advancedCommands . includes ( command ) ||
288
+ this . advancedCommands . includes ( `${ command } ${ options } ` ) ;
289
+ commandGroups [ group ] . push ( {
290
+ command,
291
+ description : this . availableCommands [ command ] . description ,
292
+ keys,
293
+ advanced,
294
+ options,
295
+ } ) ;
296
+ }
278
297
}
279
298
}
280
299
chrome . storage . session . set ( { helpPageData : commandGroups } ) ;
@@ -297,7 +316,6 @@ const Commands = {
297
316
"scrollToLeft" ,
298
317
"scrollToRight" ,
299
318
"reload" ,
300
- "hardReload" ,
301
319
"copyCurrentUrl" ,
302
320
"openCopiedUrlInCurrentTab" ,
303
321
"openCopiedUrlInNewTab" ,
@@ -331,7 +349,13 @@ const Commands = {
331
349
"Vomnibar.activateEditUrl" ,
332
350
"Vomnibar.activateEditUrlInNewTab" ,
333
351
] ,
334
- findCommands : [ "enterFindMode" , "performFind" , "performBackwardsFind" ] ,
352
+ findCommands : [
353
+ "enterFindMode" ,
354
+ "performFind" ,
355
+ "performBackwardsFind" ,
356
+ "findSelected" ,
357
+ "findSelectedBackwards" ,
358
+ ] ,
335
359
historyNavigation : [ "goBack" , "goForward" ] ,
336
360
tabManipulation : [
337
361
"createTab" ,
@@ -374,6 +398,8 @@ const Commands = {
374
398
"mergeTabToExistingWindowOnRight" ,
375
399
"mergeTabToExistingWindowAbove" ,
376
400
"mergeTabToExistingWindowBelow" ,
401
+ "findSelected" ,
402
+ "findSelectedBackwards" ,
377
403
"goUp" ,
378
404
"goToRoot" ,
379
405
"LinkHints.activateModeWithQueue" ,
@@ -394,11 +420,11 @@ const Commands = {
394
420
"enterVisualLineMode" ,
395
421
"toggleViewSource" ,
396
422
"passNextKey" ,
397
- "hardReload" ,
398
423
"setZoom" ,
399
424
"zoomIn" ,
400
425
"zoomOut" ,
401
426
"zoomReset" ,
427
+ "reload hard" ,
402
428
] ,
403
429
} ;
404
430
@@ -417,7 +443,7 @@ const defaultKeyMappings = {
417
443
"d" : "scrollPageDown" ,
418
444
"u" : "scrollPageUp" ,
419
445
"r" : "reload" ,
420
- "R" : "hardReload " ,
446
+ "R" : "reload hard " ,
421
447
"yy" : "copyCurrentUrl" ,
422
448
"p" : "openCopiedUrlInCurrentTab" ,
423
449
"P" : "openCopiedUrlInNewTab" ,
@@ -442,6 +468,8 @@ const defaultKeyMappings = {
442
468
"/" : "enterFindMode" ,
443
469
"n" : "performFind" ,
444
470
"N" : "performBackwardsFind" ,
471
+ "*" : "findSelected" ,
472
+ "#" : "findSelectedBackwards" ,
445
473
446
474
// Vomnibar
447
475
"o" : "Vomnibar.activate" ,
@@ -511,7 +539,6 @@ const commandDescriptions = {
511
539
scrollFullPageUp : [ "Scroll a full page up" ] ,
512
540
513
541
reload : [ "Reload the page" , { background : true } ] ,
514
- hardReload : [ "Hard reload the page" , { background : true } ] ,
515
542
toggleViewSource : [ "View page source" , { noRepeat : true } ] ,
516
543
517
544
copyCurrentUrl : [ "Copy the current URL to the clipboard" , { noRepeat : true } ] ,
@@ -536,6 +563,8 @@ const commandDescriptions = {
536
563
enterFindMode : [ "Enter find mode" , { noRepeat : true } ] ,
537
564
performFind : [ "Cycle forward to the next find match" ] ,
538
565
performBackwardsFind : [ "Cycle backward to the previous find match" ] ,
566
+ findSelected : [ "Find the selected text" ] ,
567
+ findSelectedBackwards : [ "Find the selected text, searching backwards" ] ,
539
568
540
569
goPrevious : [ "Follow the link labeled previous or <" , { noRepeat : true } ] ,
541
570
goNext : [ "Follow the link labeled next or >" , { noRepeat : true } ] ,
@@ -580,9 +609,9 @@ const commandDescriptions = {
580
609
moveTabLeft : [ "Move tab to the left" , { background : true } ] ,
581
610
moveTabRight : [ "Move tab to the right" , { background : true } ] ,
582
611
583
- setZoom : [ "Set zoom level to a given value. E.g. map zz setZoom 1.5 " , { background : true } ] ,
584
- zoomIn : [ "Increase zoom " , { background : true } ] ,
585
- zoomOut : [ "Decrease zoom " , { background : true } ] ,
612
+ setZoom : [ "Set zoom" , { background : true } ] ,
613
+ zoomIn : [ "Zoom in " , { background : true } ] ,
614
+ zoomOut : [ "Zoom out " , { background : true } ] ,
586
615
zoomReset : [ "Reset zoom" , { background : true } ] ,
587
616
588
617
"Vomnibar.activate" : [ "Open URL, bookmark or history entry" , { topFrame : true } ] ,
0 commit comments