aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/default-settings.js7
-rw-r--r--src/shared/messages.js10
-rw-r--r--src/shared/operations.js11
-rw-r--r--src/shared/utils/keys.js86
4 files changed, 111 insertions, 3 deletions
diff --git a/src/shared/default-settings.js b/src/shared/default-settings.js
index 60e7876..608890b 100644
--- a/src/shared/default-settings.js
+++ b/src/shared/default-settings.js
@@ -28,8 +28,12 @@ export default {
"u": { "type": "tabs.reopen" },
"K": { "type": "tabs.prev", "count": 1 },
"J": { "type": "tabs.next", "count": 1 },
+ "g0": { "type": "tabs.first" },
+ "g$": { "type": "tabs.last" },
"r": { "type": "tabs.reload", "cache": false },
"R": { "type": "tabs.reload", "cache": true },
+ "zp": { "type": "tabs.pin.toggle" },
+ "zd": { "type": "tabs.duplicate" },
"zi": { "type": "zoom.in" },
"zo": { "type": "zoom.out" },
"zz": { "type": "zoom.neutral" },
@@ -42,6 +46,9 @@ export default {
"gu": { "type": "navigate.parent" },
"gU": { "type": "navigate.root" },
"y": { "type": "urls.yank" },
+ "/": { "type": "find.start" },
+ "n": { "type": "find.next" },
+ "N": { "type": "find.prev" },
"<S-Esc>": { "type": "addon.toggle.enabled" }
},
"search": {
diff --git a/src/shared/messages.js b/src/shared/messages.js
index dc497b6..de00a3f 100644
--- a/src/shared/messages.js
+++ b/src/shared/messages.js
@@ -24,13 +24,14 @@ const onMessage = (listener) => {
export default {
BACKGROUND_OPERATION: 'background.operation',
- CONSOLE_BLURRED: 'console.blured',
- CONSOLE_ENTERED: 'console.entered',
+ CONSOLE_UNFOCUS: 'console.unfocus',
+ CONSOLE_ENTER_COMMAND: 'console.enter.command',
+ CONSOLE_ENTER_FIND: 'console.enter.find',
CONSOLE_QUERY_COMPLETIONS: 'console.query.completions',
CONSOLE_SHOW_COMMAND: 'console.show.command',
CONSOLE_SHOW_ERROR: 'console.show.error',
CONSOLE_SHOW_INFO: 'console.show.info',
- CONSOLE_HIDE_COMMAND: 'console.hide.command',
+ CONSOLE_SHOW_FIND: 'console.show.find',
FOLLOW_START: 'follow.start',
FOLLOW_REQUEST_COUNT_TARGETS: 'follow.request.count.targets',
@@ -41,6 +42,9 @@ export default {
FOLLOW_ACTIVATE: 'follow.activate',
FOLLOW_KEY_PRESS: 'follow.key.press',
+ FIND_NEXT: 'find.next',
+ FIND_PREV: 'find.prev',
+
OPEN_URL: 'open.url',
SETTINGS_RELOAD: 'settings.reload',
diff --git a/src/shared/operations.js b/src/shared/operations.js
index d5c2985..4c221ba 100644
--- a/src/shared/operations.js
+++ b/src/shared/operations.js
@@ -36,7 +36,13 @@ export default {
TAB_REOPEN: 'tabs.reopen',
TAB_PREV: 'tabs.prev',
TAB_NEXT: 'tabs.next',
+ TAB_FIRST: 'tabs.first',
+ TAB_LAST: 'tabs.last',
TAB_RELOAD: 'tabs.reload',
+ TAB_PIN: 'tabs.pin',
+ TAB_UNPIN: 'tabs.unpin',
+ TAB_TOGGLE_PINNED: 'tabs.pin.toggle',
+ TAB_DUPLICATE: 'tabs.duplicate',
// Zooms
ZOOM_IN: 'zoom.in',
@@ -45,4 +51,9 @@ export default {
// Url yank
URLS_YANK: 'urls.yank',
+
+ // Find
+ FIND_START: 'find.start',
+ FIND_NEXT: 'find.next',
+ FIND_PREV: 'find.prev',
};
diff --git a/src/shared/utils/keys.js b/src/shared/utils/keys.js
new file mode 100644
index 0000000..fba8ce3
--- /dev/null
+++ b/src/shared/utils/keys.js
@@ -0,0 +1,86 @@
+const modifierdKeyName = (name) => {
+ if (name.length === 1) {
+ return name;
+ } else if (name === 'Escape') {
+ return 'Esc';
+ }
+ return name;
+};
+
+const fromKeyboardEvent = (e) => {
+ let key = modifierdKeyName(e.key);
+ let shift = e.shiftKey;
+ if (key.length === 1 && key.toUpperCase() === key.toLowerCase()) {
+ // make shift false for symbols to enable key bindings by symbold keys.
+ // But this limits key bindings by symbol keys with Shift (such as Shift+$>.
+ shift = false;
+ }
+
+ return {
+ key: modifierdKeyName(e.key),
+ shiftKey: shift,
+ ctrlKey: e.ctrlKey,
+ altKey: e.altKey,
+ metaKey: e.metaKey,
+ };
+};
+
+const fromMapKey = (key) => {
+ if (key.startsWith('<') && key.endsWith('>')) {
+ let inner = key.slice(1, -1);
+ let shift = inner.includes('S-');
+ let base = inner.slice(inner.lastIndexOf('-') + 1);
+ if (shift && base.length === 1) {
+ base = base.toUpperCase();
+ } else if (!shift && base.length === 1) {
+ base = base.toLowerCase();
+ }
+ return {
+ key: base,
+ shiftKey: inner.includes('S-'),
+ ctrlKey: inner.includes('C-'),
+ altKey: inner.includes('A-'),
+ metaKey: inner.includes('M-'),
+ };
+ }
+ return {
+ key: key,
+ shiftKey: key.toLowerCase() !== key,
+ ctrlKey: false,
+ altKey: false,
+ metaKey: false,
+ };
+};
+
+const fromMapKeys = (keys) => {
+ const fromMapKeysRecursive = (remainings, mappedKeys) => {
+ if (remainings.length === 0) {
+ return mappedKeys;
+ }
+
+ let nextPos = 1;
+ if (remainings.startsWith('<')) {
+ let ltPos = remainings.indexOf('>');
+ if (ltPos > 0) {
+ nextPos = ltPos + 1;
+ }
+ }
+
+ return fromMapKeysRecursive(
+ remainings.slice(nextPos),
+ mappedKeys.concat([fromMapKey(remainings.slice(0, nextPos))])
+ );
+ };
+
+ return fromMapKeysRecursive(keys, []);
+};
+
+const equals = (e1, e2) => {
+ return e1.key === e2.key &&
+ e1.ctrlKey === e2.ctrlKey &&
+ e1.metaKey === e2.metaKey &&
+ e1.altKey === e2.altKey &&
+ e1.shiftKey === e2.shiftKey;
+};
+
+export { fromKeyboardEvent, fromMapKey, fromMapKeys, equals };