From 02c0cfd97d44c8568dee6f0d11d2e45732309c67 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 27 Aug 2017 10:12:12 +0900 Subject: [PATCH] scroll lines action --- src/background/key-queue.js | 4 ++-- src/content/index.js | 7 ++----- src/content/scrolls.js | 10 ++-------- src/shared/actions.js | 6 ++---- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/background/key-queue.js b/src/background/key-queue.js index f5f9a53..8bd3158 100644 --- a/src/background/key-queue.js +++ b/src/background/key-queue.js @@ -5,8 +5,8 @@ const DEFAULT_KEYMAP = [ { keys: [{ code: KeyboardEvent.DOM_VK_SEMICOLON, shift: true }], action: [ actions.CMD_OPEN ]}, { keys: [{ code: KeyboardEvent.DOM_VK_O }], action: [ actions.CMD_TABS_OPEN, false ]}, { keys: [{ code: KeyboardEvent.DOM_VK_O, shift: true }], action: [ actions.CMD_TABS_OPEN, true ]}, - { keys: [{ code: KeyboardEvent.DOM_VK_K }], action: [ actions.SCROLL_UP, 1 ]}, - { keys: [{ code: KeyboardEvent.DOM_VK_J }], action: [ actions.SCROLL_DOWN, 1 ]}, + { keys: [{ code: KeyboardEvent.DOM_VK_K }], action: [ actions.SCROLL_LINES, -1 ]}, + { keys: [{ code: KeyboardEvent.DOM_VK_J }], action: [ actions.SCROLL_LINES, 1 ]}, { keys: [{ code: KeyboardEvent.DOM_VK_G }, { code: KeyboardEvent.DOM_VK_G }], action: [ actions.SCROLL_TOP ]}, { keys: [{ code: KeyboardEvent.DOM_VK_G, shift: true }], action: [ actions.SCROLL_BOTTOM ]}, { keys: [{ code: KeyboardEvent.DOM_VK_D }], action: [ actions.TABS_CLOSE ]}, diff --git a/src/content/index.js b/src/content/index.js index 2bbe39c..b233e27 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -42,11 +42,8 @@ const invokeEvent = (action) => { createFooterLine('open '); } break; - case actions.SCROLL_UP: - scrolls.scrollUp(window, action[1] || 1); - break; - case actions.SCROLL_DOWN: - scrolls.scrollDown(window, action[1] || 1); + case actions.SCROLL_LINES: + scrolls.scrollLines(window, action[1]); break; case actions.SCROLL_TOP: scrolls.scrollTop(window, action[1]); diff --git a/src/content/scrolls.js b/src/content/scrolls.js index 2a233c2..ef112a4 100644 --- a/src/content/scrolls.js +++ b/src/content/scrolls.js @@ -1,12 +1,6 @@ const SCROLL_DELTA = 48; -const scrollUp = (page, count) => { - let x = page.scrollX; - let y = page.scrollY - SCROLL_DELTA * count; - page.scrollTo(x, y); -}; - -const scrollDown = (page, count) => { +const scrollLines = (page, count) => { let x = page.scrollX; let y = page.scrollY + SCROLL_DELTA * count; page.scrollTo(x, y); @@ -24,4 +18,4 @@ const scrollBottom = (page) => { page.scrollTo(x, y); }; -export { scrollUp, scrollDown, scrollTop, scrollBottom } +export { scrollLines, scrollTop, scrollBottom } diff --git a/src/shared/actions.js b/src/shared/actions.js index f0a224c..379a236 100644 --- a/src/shared/actions.js +++ b/src/shared/actions.js @@ -5,8 +5,7 @@ export const TABS_REOPEN = 'tabs.reopen'; export const TABS_PREV = 'tabs.prev'; export const TABS_NEXT = 'tabs.next'; export const TABS_RELOAD = 'tabs.reload'; -export const SCROLL_UP = 'scroll.up'; -export const SCROLL_DOWN = 'scroll.down'; +export const SCROLL_LINES = 'scroll.lines'; export const SCROLL_TOP = 'scroll.top'; export const SCROLL_BOTTOM = 'scroll.bottom'; export const FOLLOW_START = 'follow.start'; @@ -30,8 +29,7 @@ const BACKGROUND_ACTION_SET = new Set([ const CONTENT_ACTION_SET = new Set([ CMD_OPEN, CMD_TABS_OPEN, - SCROLL_UP, - SCROLL_DOWN, + SCROLL_LINES, SCROLL_TOP, SCROLL_BOTTOM, FOLLOW_START,