From 177940981ed9c4f096ad7db20f0b7ee044fd7b17 Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Thu, 16 Nov 2017 13:03:38 +0000 Subject: Open adjacent tabs and background tabs --- src/content/actions/operation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/content/actions/operation.js') diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 767f14b..5c8fe83 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -40,7 +40,8 @@ const exec = (operation) => { case operations.FOLLOW_START: return window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, - newTab: operation.newTab + newTab: operation.newTab, + background: operation.background, }), '*'); case operations.NAVIGATE_HISTORY_PREV: return navigates.historyPrev(window); -- cgit v1.2.3 From 54a7662cd1e7372910e9ce81aae1a904f3b26c82 Mon Sep 17 00:00:00 2001 From: usk Date: Wed, 3 Jan 2018 07:19:25 +0900 Subject: open clipboard's URL in current/new tab --- QA.md | 2 ++ README.md | 2 ++ manifest.json | 3 ++- src/content/actions/operation.js | 2 ++ src/content/urls.js | 26 +++++++++++++++++++++++++- src/settings/components/form/keymaps-form.jsx | 2 ++ src/shared/operations.js | 3 ++- src/shared/settings/default.js | 2 ++ 8 files changed, 39 insertions(+), 3 deletions(-) (limited to 'src/content/actions/operation.js') diff --git a/QA.md b/QA.md index 1a0839e..1c06861 100644 --- a/QA.md +++ b/QA.md @@ -46,6 +46,8 @@ The behaviors of the console are tested in [Console section](#consoles). - [ ] zi, zo: zoom-in and zoom-out - [ ] zz: set zoom level as default - [ ] y: yank current URL and show a message +- [ ] p: open clipbord's URL in current tab +- [ ] P: open clipbord's URL in new tab - [ ] Toggle enabled/disabled of plugin bu Shift+Esc ### Following links diff --git a/README.md b/README.md index fdc48d4..a249ada 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ The default mappings are as follows: - zi, zo: zoom-in/zoom-out - zz: Set default zoom level - y: copy URL in current tab +- p: open clipbord's URL in current tab +- P: open clipbord's URL in new tab - Shift+Esc: enable or disable the add-on in current tab. ### Console commands diff --git a/manifest.json b/manifest.json index 78479c2..02d8589 100644 --- a/manifest.json +++ b/manifest.json @@ -30,7 +30,8 @@ "history", "sessions", "storage", - "tabs" + "tabs", + "clipboardRead" ], "web_accessible_resources": [ "build/console.html", diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 767f14b..0a5cd97 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -60,6 +60,8 @@ const exec = (operation) => { type: messages.CONSOLE_SHOW_INFO, text: 'Current url yanked', }); + case operations.URLS_PASTE: + return urls.paste(window, operation.newTab ? operation.newTab : false); default: browser.runtime.sendMessage({ type: messages.BACKGROUND_OPERATION, diff --git a/src/content/urls.js b/src/content/urls.js index 8f8a1ac..9b7b284 100644 --- a/src/content/urls.js +++ b/src/content/urls.js @@ -1,3 +1,5 @@ +import messages from 'shared/messages'; + const yank = (win) => { let input = win.document.createElement('input'); win.document.body.append(input); @@ -12,4 +14,26 @@ const yank = (win) => { input.remove(); }; -export { yank }; +const paste = (win, newTab) => { + let textarea = win.document.createElement('textarea'); + win.document.body.append(textarea); + + textarea.style.position = 'fixed'; + textarea.style.top = '-100px'; + textarea.contentEditable = 'true'; + textarea.focus(); + + if (win.document.execCommand('paste')) { + if (/^(https?|ftp):\/\//.test(textarea.textContent)) { + browser.runtime.sendMessage({ + type: messages.OPEN_URL, + url: textarea.textContent, + newTab: newTab ? newTab : false, + }); + } + } + + textarea.remove(); +}; + +export { yank, paste }; diff --git a/src/settings/components/form/keymaps-form.jsx b/src/settings/components/form/keymaps-form.jsx index c399570..eb77e52 100644 --- a/src/settings/components/form/keymaps-form.jsx +++ b/src/settings/components/form/keymaps-form.jsx @@ -52,6 +52,8 @@ const KeyMapFields = [ ], [ ['addon.toggle.enabled', 'Enable or disable'], ['urls.yank', 'Copy current URL'], + ['urls.paste?{"newTab":false}', 'Open clipboard\'s URL in current tab'], + ['urls.paste?{"newTab":true}', 'Open clipboard\'s URL in new tab'], ['zoom.in', 'Zoom-in'], ['zoom.out', 'Zoom-out'], ['zoom.neutral', 'Reset zoom level'], diff --git a/src/shared/operations.js b/src/shared/operations.js index 4c221ba..7334369 100644 --- a/src/shared/operations.js +++ b/src/shared/operations.js @@ -49,8 +49,9 @@ export default { ZOOM_OUT: 'zoom.out', ZOOM_NEUTRAL: 'zoom.neutral', - // Url yank + // Url yank/paste URLS_YANK: 'urls.yank', + URLS_PASTE: 'urls.paste', // Find FIND_START: 'find.start', diff --git a/src/shared/settings/default.js b/src/shared/settings/default.js index d187565..6b71717 100644 --- a/src/shared/settings/default.js +++ b/src/shared/settings/default.js @@ -44,6 +44,8 @@ export default { "gu": { "type": "navigate.parent" }, "gU": { "type": "navigate.root" }, "y": { "type": "urls.yank" }, + "p": { "type": "urls.paste", "newTab": false }, + "P": { "type": "urls.paste", "newTab": true }, "/": { "type": "find.start" }, "n": { "type": "find.next" }, "N": { "type": "find.prev" }, -- cgit v1.2.3 From 057a0b8a4608939af1208b8946876d849e873d37 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 13 Jan 2018 14:48:53 +0900 Subject: remove window from scrolls --- src/content/actions/operation.js | 14 +++++----- src/content/scrolls.js | 60 ++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 37 deletions(-) (limited to 'src/content/actions/operation.js') diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 767f14b..8157127 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -24,19 +24,19 @@ const exec = (operation) => { type: messages.FIND_PREV, }), '*'); case operations.SCROLL_VERTICALLY: - return scrolls.scrollVertically(window, operation.count); + return scrolls.scrollVertically(operation.count); case operations.SCROLL_HORIZONALLY: - return scrolls.scrollHorizonally(window, operation.count); + return scrolls.scrollHorizonally(operation.count); case operations.SCROLL_PAGES: - return scrolls.scrollPages(window, operation.count); + return scrolls.scrollPages(operation.count); case operations.SCROLL_TOP: - return scrolls.scrollTop(window); + return scrolls.scrollTop(); case operations.SCROLL_BOTTOM: - return scrolls.scrollBottom(window); + return scrolls.scrollBottom(); case operations.SCROLL_HOME: - return scrolls.scrollHome(window); + return scrolls.scrollHome(); case operations.SCROLL_END: - return scrolls.scrollEnd(window); + return scrolls.scrollEnd(); case operations.FOLLOW_START: return window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, diff --git a/src/content/scrolls.js b/src/content/scrolls.js index ef38273..251b222 100644 --- a/src/content/scrolls.js +++ b/src/content/scrolls.js @@ -1,7 +1,7 @@ const SCROLL_DELTA_X = 48; const SCROLL_DELTA_Y = 48; -const isVisible = (win, element) => { +const isVisible = (element) => { let rect = element.getBoundingClientRect(); if (rect.width === 0 || rect.height === 0) { return false; @@ -9,19 +9,19 @@ const isVisible = (win, element) => { if (rect.right < 0 && rect.bottom < 0) { return false; } - if (win.innerWidth < rect.left && win.innerHeight < rect.top) { + if (window.innerWidth < rect.left && window.innerHeight < rect.top) { return false; } - let { display, visibility } = win.getComputedStyle(element); + let { display, visibility } = window.getComputedStyle(element); if (display === 'none' || visibility === 'hidden') { return false; } return true; }; -const isScrollableStyle = (win, element) => { - let { overflowX, overflowY } = win.getComputedStyle(element); +const isScrollableStyle = (element) => { + let { overflowX, overflowY } = window.getComputedStyle(element); return !(overflowX !== 'scroll' && overflowX !== 'auto' && overflowY !== 'scroll' && overflowY !== 'auto'); }; @@ -35,15 +35,15 @@ const isOverflowed = (element) => { // this method is called by each scrolling, and the returned value of this // method is not cached. That does not cause performance issue because in the // most pages, the window is root element i,e, documentElement. -const findScrollable = (win, element) => { - if (isScrollableStyle(win, element) && isOverflowed(element)) { +const findScrollable = (element) => { + if (isScrollableStyle(element) && isOverflowed(element)) { return element; } let children = Array.prototype - .filter.call(element.children, e => isVisible(win, e)); + .filter.call(element.children, e => isVisible(e)); for (let child of children) { - let scrollable = findScrollable(win, child); + let scrollable = findScrollable(child); if (scrollable) { return scrollable; } @@ -51,65 +51,65 @@ const findScrollable = (win, element) => { return null; }; -const scrollTarget = (win) => { - if (isOverflowed(win.document.documentElement)) { - return win.document.documentElement; +const scrollTarget = () => { + if (isOverflowed(window.document.documentElement)) { + return window.document.documentElement; } - if (isOverflowed(win.document.body)) { - return win.document.body; + if (isOverflowed(window.document.body)) { + return window.document.body; } - let target = findScrollable(win, win.document.documentElement); + let target = findScrollable(window.document.documentElement); if (target) { return target; } - return win.document.documentElement; + return window.document.documentElement; }; -const scrollVertically = (win, count) => { - let target = scrollTarget(win); +const scrollVertically = (count) => { + let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollTop + SCROLL_DELTA_Y * count; target.scrollTo(x, y); }; -const scrollHorizonally = (win, count) => { - let target = scrollTarget(win); +const scrollHorizonally = (count) => { + let target = scrollTarget(); let x = target.scrollLeft + SCROLL_DELTA_X * count; let y = target.scrollTop; target.scrollTo(x, y); }; -const scrollPages = (win, count) => { - let target = scrollTarget(win); +const scrollPages = (count) => { + let target = scrollTarget(); let height = target.clientHeight; let x = target.scrollLeft; let y = target.scrollTop + height * count; target.scrollTo(x, y); }; -const scrollTop = (win) => { - let target = scrollTarget(win); +const scrollTop = () => { + let target = scrollTarget(); let x = target.scrollLeft; let y = 0; target.scrollTo(x, y); }; -const scrollBottom = (win) => { - let target = scrollTarget(win); +const scrollBottom = () => { + let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollHeight; target.scrollTo(x, y); }; -const scrollHome = (win) => { - let target = scrollTarget(win); +const scrollHome = () => { + let target = scrollTarget(); let x = 0; let y = target.scrollTop; target.scrollTo(x, y); }; -const scrollEnd = (win) => { - let target = scrollTarget(win); +const scrollEnd = () => { + let target = scrollTarget(); let x = target.scrollWidth; let y = target.scrollTop; target.scrollTo(x, y); -- cgit v1.2.3 From 2ca1b54faacb261e5a25331e030da13d07c09662 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 13 Jan 2018 15:31:39 +0900 Subject: add smoothscroll property --- src/content/actions/operation.js | 19 +++++++++------- src/content/components/common/keymapper.js | 2 +- src/content/scrolls.js | 36 ++++++++++++++++++------------ src/shared/settings/properties.js | 2 ++ 4 files changed, 36 insertions(+), 23 deletions(-) (limited to 'src/content/actions/operation.js') diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 8157127..d2e258c 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -5,9 +5,12 @@ import * as navigates from 'content/navigates'; import * as urls from 'content/urls'; import * as consoleFrames from 'content/console-frames'; import * as addonActions from './addon'; +import * as properties from 'shared/settings/properties'; // eslint-disable-next-line complexity -const exec = (operation) => { +const exec = (operation, settings) => { + let smoothscroll = settings.properties.smoothscroll || + properties.defaults.smoothscroll; switch (operation.type) { case operations.ADDON_ENABLE: return addonActions.enable(); @@ -24,19 +27,19 @@ const exec = (operation) => { type: messages.FIND_PREV, }), '*'); case operations.SCROLL_VERTICALLY: - return scrolls.scrollVertically(operation.count); + return scrolls.scrollVertically(operation.count, smoothscroll); case operations.SCROLL_HORIZONALLY: - return scrolls.scrollHorizonally(operation.count); + return scrolls.scrollHorizonally(operation.count, smoothscroll); case operations.SCROLL_PAGES: - return scrolls.scrollPages(operation.count); + return scrolls.scrollPages(operation.count, smoothscroll); case operations.SCROLL_TOP: - return scrolls.scrollTop(); + return scrolls.scrollTop(smoothscroll); case operations.SCROLL_BOTTOM: - return scrolls.scrollBottom(); + return scrolls.scrollBottom(smoothscroll); case operations.SCROLL_HOME: - return scrolls.scrollHome(); + return scrolls.scrollHome(smoothscroll); case operations.SCROLL_END: - return scrolls.scrollEnd(); + return scrolls.scrollEnd(smoothscroll); case operations.FOLLOW_START: return window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js index fb8fabe..fa8c33a 100644 --- a/src/content/components/common/keymapper.js +++ b/src/content/components/common/keymapper.js @@ -47,7 +47,7 @@ export default class KeymapperComponent { return true; } let operation = keymaps.get(matched[0]); - this.store.dispatch(operationActions.exec(operation)); + this.store.dispatch(operationActions.exec(operation, state.setting)); this.store.dispatch(inputActions.clearKeys()); return true; } diff --git a/src/content/scrolls.js b/src/content/scrolls.js index 8daa36f..5aef1df 100644 --- a/src/content/scrolls.js +++ b/src/content/scrolls.js @@ -108,54 +108,62 @@ const roughScroll = (element, x, y) => { element.scrollTo(x, y); }; -const scrollVertically = (count) => { +const scroll = (element, x, y, smooth) => { + if (smooth) { + smoothScroll(element, x, y); + } else { + roughScroll(element, x, y); + } +}; + +const scrollVertically = (count, smooth) => { let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollTop + SCROLL_DELTA_Y * count; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollHorizonally = (count) => { +const scrollHorizonally = (count, smooth) => { let target = scrollTarget(); let x = target.scrollLeft + SCROLL_DELTA_X * count; let y = target.scrollTop; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollPages = (count) => { +const scrollPages = (count, smooth) => { let target = scrollTarget(); let height = target.clientHeight; let x = target.scrollLeft; let y = target.scrollTop + height * count; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollTop = () => { +const scrollTop = (smooth) => { let target = scrollTarget(); let x = target.scrollLeft; let y = 0; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollBottom = () => { +const scrollBottom = (smooth) => { let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollHeight; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollHome = () => { +const scrollHome = (smooth) => { let target = scrollTarget(); let x = 0; let y = target.scrollTop; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; -const scrollEnd = () => { +const scrollEnd = (smooth) => { let target = scrollTarget(); let x = target.scrollWidth; let y = target.scrollTop; - roughScroll(target, x, y); + scroll(target, x, y, smooth); }; export { diff --git a/src/shared/settings/properties.js b/src/shared/settings/properties.js index f695c58..37dc881 100644 --- a/src/shared/settings/properties.js +++ b/src/shared/settings/properties.js @@ -4,11 +4,13 @@ // mybool: 'boolean', const types = { hintchars: 'string', + smoothscroll: 'boolean', }; // describe default values of a property const defaults = { hintchars: 'abcdefghijklmnopqrstuvwxyz', + smoothscroll: false, }; export { types, defaults }; -- cgit v1.2.3 From 335b9ca47458b1817ef7705f4d999c25f423fad9 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 13 Jan 2018 19:49:11 +0900 Subject: fix smooth scroll on key repeated --- src/content/actions/operation.js | 16 ++++---- src/content/components/common/keymapper.js | 3 +- src/content/scrolls.js | 63 +++++++++++++++++++++--------- src/shared/utils/keys.js | 1 + 4 files changed, 55 insertions(+), 28 deletions(-) (limited to 'src/content/actions/operation.js') diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index d2e258c..1c0a5fb 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -8,7 +8,7 @@ import * as addonActions from './addon'; import * as properties from 'shared/settings/properties'; // eslint-disable-next-line complexity -const exec = (operation, settings) => { +const exec = (operation, repeat, settings) => { let smoothscroll = settings.properties.smoothscroll || properties.defaults.smoothscroll; switch (operation.type) { @@ -27,19 +27,19 @@ const exec = (operation, settings) => { type: messages.FIND_PREV, }), '*'); case operations.SCROLL_VERTICALLY: - return scrolls.scrollVertically(operation.count, smoothscroll); + return scrolls.scrollVertically(operation.count, smoothscroll, repeat); case operations.SCROLL_HORIZONALLY: - return scrolls.scrollHorizonally(operation.count, smoothscroll); + return scrolls.scrollHorizonally(operation.count, smoothscroll, repeat); case operations.SCROLL_PAGES: - return scrolls.scrollPages(operation.count, smoothscroll); + return scrolls.scrollPages(operation.count, smoothscroll, repeat); case operations.SCROLL_TOP: - return scrolls.scrollTop(smoothscroll); + return scrolls.scrollTop(smoothscroll, repeat); case operations.SCROLL_BOTTOM: - return scrolls.scrollBottom(smoothscroll); + return scrolls.scrollBottom(smoothscroll, repeat); case operations.SCROLL_HOME: - return scrolls.scrollHome(smoothscroll); + return scrolls.scrollHome(smoothscroll, repeat); case operations.SCROLL_END: - return scrolls.scrollEnd(smoothscroll); + return scrolls.scrollEnd(smoothscroll, repeat); case operations.FOLLOW_START: return window.top.postMessage(JSON.stringify({ type: messages.FOLLOW_START, diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js index fa8c33a..d9d1b2f 100644 --- a/src/content/components/common/keymapper.js +++ b/src/content/components/common/keymapper.js @@ -47,7 +47,8 @@ export default class KeymapperComponent { return true; } let operation = keymaps.get(matched[0]); - this.store.dispatch(operationActions.exec(operation, state.setting)); + this.store.dispatch(operationActions.exec( + operation, key.repeat, state.setting)); this.store.dispatch(inputActions.clearKeys()); return true; } diff --git a/src/content/scrolls.js b/src/content/scrolls.js index 2fe06c0..e8e9642 100644 --- a/src/content/scrolls.js +++ b/src/content/scrolls.js @@ -2,6 +2,9 @@ const SCROLL_DELTA_X = 48; const SCROLL_DELTA_Y = 48; const SMOOTH_SCROLL_DURATION = 150; +// dirty way to store scrolling state on globally +let scrolling = [false]; + const isVisible = (element) => { let rect = element.getBoundingClientRect(); if (rect.width === 0 || rect.height === 0) { @@ -67,11 +70,23 @@ const scrollTarget = () => { }; class SmoothScroller { - constructor(element) { + constructor(element, repeat) { this.element = element; + this.repeat = repeat; + this.scrolling = scrolling; + if (repeat) { + this.easing = SmoothScroller.linearEasing; + } else { + this.easing = SmoothScroller.inOutQuadEasing; + } } scroll(x, y) { + if (this.scrolling[0]) { + return; + } + scrolling[0] = true; + this.startX = this.element.scrollLeft; this.startY = this.element.scrollTop; @@ -99,17 +114,21 @@ class SmoothScroller { if (elapsed < SMOOTH_SCROLL_DURATION) { window.requestAnimationFrame(this.loop.bind(this)); } else { + scrolling[0] = false; this.element.scrollTo(this.targetX, this.targetY); } } - // in-out quad easing - easing(t) { + static inOutQuadEasing(t) { if (t < 1) { return t * t; } return -(t - 1) * (t - 1) + 1; } + + static linearEasing(t) { + return t; + } } class RoughtScroller { @@ -122,61 +141,67 @@ class RoughtScroller { } } -const scroller = (element, smooth) => { +const scroller = (element, smooth, repeat) => { if (smooth) { - return new SmoothScroller(element); + return new SmoothScroller(element, repeat); } return new RoughtScroller(element); }; -const scrollVertically = (count, smooth) => { +const scrollVertically = (count, smooth, repeat) => { let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollTop + SCROLL_DELTA_Y * count; - scroller(target, smooth).scroll(x, y); + if (repeat && smooth) { + y = target.scrollTop + SCROLL_DELTA_Y * count * 4; + } + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollHorizonally = (count, smooth) => { +const scrollHorizonally = (count, smooth, repeat) => { let target = scrollTarget(); let x = target.scrollLeft + SCROLL_DELTA_X * count; let y = target.scrollTop; - scroller(target, smooth).scroll(x, y); + if (repeat && smooth) { + y = target.scrollTop + SCROLL_DELTA_Y * count * 4; + } + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollPages = (count, smooth) => { +const scrollPages = (count, smooth, repeat) => { let target = scrollTarget(); let height = target.clientHeight; let x = target.scrollLeft; let y = target.scrollTop + height * count; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollTop = (smooth) => { +const scrollTop = (smooth, repeat) => { let target = scrollTarget(); let x = target.scrollLeft; let y = 0; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollBottom = (smooth) => { +const scrollBottom = (smooth, repeat) => { let target = scrollTarget(); let x = target.scrollLeft; let y = target.scrollHeight; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollHome = (smooth) => { +const scrollHome = (smooth, repeat) => { let target = scrollTarget(); let x = 0; let y = target.scrollTop; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; -const scrollEnd = (smooth) => { +const scrollEnd = (smooth, repeat) => { let target = scrollTarget(); let x = target.scrollWidth; let y = target.scrollTop; - scroller(target, smooth).scroll(x, y); + scroller(target, smooth, repeat).scroll(x, y); }; export { diff --git a/src/shared/utils/keys.js b/src/shared/utils/keys.js index fba8ce3..8a86dfb 100644 --- a/src/shared/utils/keys.js +++ b/src/shared/utils/keys.js @@ -18,6 +18,7 @@ const fromKeyboardEvent = (e) => { return { key: modifierdKeyName(e.key), + repeat: e.repeat, shiftKey: shift, ctrlKey: e.ctrlKey, altKey: e.altKey, -- cgit v1.2.3 From 9384fd07d5cc63841a832af053b5e792cae9f798 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 13 Jan 2018 23:05:51 +0900 Subject: implement focus input --- src/content/actions/operation.js | 3 +++ src/content/focuses.js | 10 ++++++++++ src/shared/operations.js | 3 +++ 3 files changed, 16 insertions(+) create mode 100644 src/content/focuses.js (limited to 'src/content/actions/operation.js') diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index b4b2e38..5fd0f48 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -2,6 +2,7 @@ import operations from 'shared/operations'; import messages from 'shared/messages'; import * as scrolls from 'content/scrolls'; import * as navigates from 'content/navigates'; +import * as focuses from 'content/focuses'; import * as urls from 'content/urls'; import * as consoleFrames from 'content/console-frames'; import * as addonActions from './addon'; @@ -57,6 +58,8 @@ const exec = (operation, repeat, settings) => { return navigates.parent(window); case operations.NAVIGATE_ROOT: return navigates.root(window); + case operations.FOCUS_INPUT: + return focuses.focusInput(); case operations.URLS_YANK: urls.yank(window); return consoleFrames.postMessage(window.document, { diff --git a/src/content/focuses.js b/src/content/focuses.js new file mode 100644 index 0000000..c2658b4 --- /dev/null +++ b/src/content/focuses.js @@ -0,0 +1,10 @@ +const focusInput = () => { + let inputTypes = ['email', 'number', 'search', 'tel', 'text', 'url']; + let inputSelector = inputTypes.map(type => `input[type=${type}]`).join(','); + let target = window.document.querySelector(inputSelector + ',textarea'); + if (target) { + target.focus(); + } +}; + +export { focusInput }; diff --git a/src/shared/operations.js b/src/shared/operations.js index 7334369..ff833a2 100644 --- a/src/shared/operations.js +++ b/src/shared/operations.js @@ -31,6 +31,9 @@ export default { NAVIGATE_PARENT: 'navigate.parent', NAVIGATE_ROOT: 'navigate.root', + // Focus + FOCUS_INPUT: 'focus.input', + // Tabs TAB_CLOSE: 'tabs.close', TAB_REOPEN: 'tabs.reopen', -- cgit v1.2.3 From 93bd0bc54fd5ce7a2803f2ebc7c834b1b815afda Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 6 Mar 2018 21:37:12 +0900 Subject: show message on find --- src/content/actions/find.js | 12 +++++++++++- src/content/actions/operation.js | 5 +---- src/content/components/top-content/find.js | 8 ++++++++ src/content/console-frames.js | 9 ++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) (limited to 'src/content/actions/operation.js') diff --git a/src/content/actions/find.js b/src/content/actions/find.js index 80d6210..b266216 100644 --- a/src/content/actions/find.js +++ b/src/content/actions/find.js @@ -14,6 +14,13 @@ const postPatternNotFound = (pattern) => { 'Pattern not found: ' + pattern); }; +const postPatternFound = (pattern) => { + return consoleFrames.postInfo( + window.document, + 'Pattern found: ' + pattern, + ); +}; + const find = (string, backwards) => { let caseSensitive = false; let wrapScan = true; @@ -34,9 +41,12 @@ const findNext = (keyword, reset, backwards) => { window.getSelection().removeAllRanges(); found = find(keyword, backwards); } - if (!found) { + if (found) { + postPatternFound(keyword); + } else { postPatternNotFound(keyword); } + return { type: actions.FIND_SET_KEYWORD, keyword, diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 5fd0f48..71b2470 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -62,10 +62,7 @@ const exec = (operation, repeat, settings) => { return focuses.focusInput(); case operations.URLS_YANK: urls.yank(window); - return consoleFrames.postMessage(window.document, { - type: messages.CONSOLE_SHOW_INFO, - text: 'Current url yanked', - }); + return consoleFrames.postInfo(window.document, 'Current url yanked'); case operations.URLS_PASTE: return urls.paste(window, operation.newTab ? operation.newTab : false); default: diff --git a/src/content/components/top-content/find.js b/src/content/components/top-content/find.js index bccf040..9967d36 100644 --- a/src/content/components/top-content/find.js +++ b/src/content/components/top-content/find.js @@ -38,6 +38,10 @@ export default class FindComponent { window.document, 'Pattern not found: ' + state.keyword); } + consoleFrames.postInfo( + window.document, + 'Pattern found: ' + state.keyword, + ); return this.store.dispatch(findActions.next(state.keyword, false)); } @@ -49,6 +53,10 @@ export default class FindComponent { window.document, 'Pattern not found: ' + state.keyword); } + consoleFrames.postInfo( + window.document, + 'Pattern found: ' + state.keyword, + ); return this.store.dispatch(findActions.prev(state.keyword, false)); } } diff --git a/src/content/console-frames.js b/src/content/console-frames.js index 515ae09..0c0ec02 100644 --- a/src/content/console-frames.js +++ b/src/content/console-frames.js @@ -28,4 +28,11 @@ const postError = (doc, message) => { }); }; -export { initialize, blur, postMessage, postError }; +const postInfo = (doc, message) => { + return postMessage(doc, { + type: messages.CONSOLE_SHOW_INFO, + text: message, + }); +}; + +export { initialize, blur, postError, postInfo }; -- cgit v1.2.3