aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-10-12 14:59:45 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-10-12 14:59:45 +0900
commite248477ecb46596af734589615118ba573971dc0 (patch)
tree8167efec0a4f539d4aecea4a0555c38f6a0934a3 /src
parent003742ec51aa7aea9214442bc0b611e2eb5eaf6e (diff)
Scroll on global mark and handle gone tab
Diffstat (limited to 'src')
-rw-r--r--src/background/domains/global-mark.js7
-rw-r--r--src/background/infrastructures/content-message-client.js8
-rw-r--r--src/background/repositories/mark.js4
-rw-r--r--src/background/usecases/mark.js16
-rw-r--r--src/content/components/common/mark.js8
-rw-r--r--src/content/components/top-content/index.js3
-rw-r--r--src/shared/messages.js2
7 files changed, 40 insertions, 8 deletions
diff --git a/src/background/domains/global-mark.js b/src/background/domains/global-mark.js
index 77afdba..f0586f1 100644
--- a/src/background/domains/global-mark.js
+++ b/src/background/domains/global-mark.js
@@ -1,6 +1,7 @@
export default class GlobalMark {
- constructor(tabId, x, y) {
+ constructor(tabId, url, x, y) {
this.tabId0 = tabId;
+ this.url0 = url;
this.x0 = x;
this.y0 = y;
}
@@ -9,6 +10,10 @@ export default class GlobalMark {
return this.tabId0;
}
+ get url() {
+ return this.url0;
+ }
+
get x() {
return this.x0;
}
diff --git a/src/background/infrastructures/content-message-client.js b/src/background/infrastructures/content-message-client.js
index d659560..7e7e602 100644
--- a/src/background/infrastructures/content-message-client.js
+++ b/src/background/infrastructures/content-message-client.js
@@ -22,4 +22,12 @@ export default class ContentMessageClient {
type: messages.ADDON_TOGGLE_ENABLED,
});
}
+
+ scrollTo(tabId, x, y) {
+ return browser.tabs.sendMessage(tabId, {
+ type: messages.TAB_SCROLL_TO,
+ x,
+ y,
+ });
+ }
}
diff --git a/src/background/repositories/mark.js b/src/background/repositories/mark.js
index a1f6a16..339a660 100644
--- a/src/background/repositories/mark.js
+++ b/src/background/repositories/mark.js
@@ -14,13 +14,13 @@ export default class MarkRepository {
if (!data) {
return Promise.resolve(undefined);
}
- let mark = new GlobalMark(data.tabId, data.x, data.y);
+ let mark = new GlobalMark(data.tabId, data.url, data.x, data.y);
return Promise.resolve(mark);
}
setMark(key, mark) {
let marks = this.getOrEmptyMarks();
- marks[key] = { tabId: mark.tabId, x: mark.x, y: mark.y };
+ marks[key] = { tabId: mark.tabId, url: mark.url, x: mark.x, y: mark.y };
this.cache.set(MARK_KEY, marks);
return Promise.resolve();
diff --git a/src/background/usecases/mark.js b/src/background/usecases/mark.js
index 2cb3b45..34b8a74 100644
--- a/src/background/usecases/mark.js
+++ b/src/background/usecases/mark.js
@@ -2,17 +2,19 @@ import GlobalMark from '../domains/global-mark';
import TabPresenter from '../presenters/tab';
import MarkRepository from '../repositories/mark';
import ConsolePresenter from '../presenters/console';
+import ContentMessageClient from '../infrastructures/content-message-client';
export default class MarkInteractor {
constructor() {
this.tabPresenter = new TabPresenter();
this.markRepository = new MarkRepository();
this.consolePresenter = new ConsolePresenter();
+ this.contentMessageClient = new ContentMessageClient();
}
async setGlobal(key, x, y) {
let tab = await this.tabPresenter.getCurrent();
- let mark = new GlobalMark(tab.id, x, y);
+ let mark = new GlobalMark(tab.id, tab.url, x, y);
return this.markRepository.setMark(key, mark);
}
@@ -23,7 +25,15 @@ export default class MarkInteractor {
if (!mark) {
return this.consolePresenter.showError(current.id, 'Mark is not set');
}
- // TODO scroll pages and handle if tab is gone
- return this.tabPresenter.select(mark.tabId);
+
+ return this.contentMessageClient.scrollTo(
+ mark.tabId, mark.x, mark.y
+ ).then(() => {
+ return this.tabPresenter.select(mark.tabId);
+ }).catch(async() => {
+ let tab = await this.tabPresenter.create(mark.url);
+ let mark2 = new GlobalMark(tab.id, mark.url, mark.x, mark.y);
+ return this.markRepository.setMark(key, mark2);
+ });
}
}
diff --git a/src/content/components/common/mark.js b/src/content/components/common/mark.js
index ce35afa..1ed636b 100644
--- a/src/content/components/common/mark.js
+++ b/src/content/components/common/mark.js
@@ -7,6 +7,10 @@ const cancelKey = (key) => {
return key.key === 'Esc' || key.key === '[' && key.ctrlKey;
};
+const globalKey = (key) => {
+ return (/^[A-Z0-9]$/).test(key);
+};
+
export default class MarkComponent {
constructor(body, store) {
this.body = body;
@@ -30,9 +34,9 @@ export default class MarkComponent {
if (key.ctrlKey || key.metaKey || key.altKey) {
consoleFrames.postError(window.document, 'Unknown mark');
- } else if (key.shiftKey && markStage.setMode) {
+ } else if (globalKey(key.key) && markStage.setMode) {
this.doSetGlobal(key);
- } else if (key.shiftKey && markStage.jumpMode) {
+ } else if (globalKey(key.key) && markStage.jumpMode) {
this.doJumpGlobal(key);
} else if (markStage.setMode) {
this.doSet(key);
diff --git a/src/content/components/top-content/index.js b/src/content/components/top-content/index.js
index e22e957..1aaef1b 100644
--- a/src/content/components/top-content/index.js
+++ b/src/content/components/top-content/index.js
@@ -3,6 +3,7 @@ import FollowController from './follow-controller';
import FindComponent from './find';
import * as consoleFrames from '../../console-frames';
import messages from 'shared/messages';
+import * as scrolls from 'content/scrolls';
export default class TopContent {
@@ -33,6 +34,8 @@ export default class TopContent {
type: messages.ADDON_ENABLED_RESPONSE,
enabled: addonState.enabled,
});
+ case messages.TAB_SCROLL_TO:
+ return scrolls.scrollTo(message.x, message.y, false);
}
}
}
diff --git a/src/shared/messages.js b/src/shared/messages.js
index cd076ee..dad2b7a 100644
--- a/src/shared/messages.js
+++ b/src/shared/messages.js
@@ -46,6 +46,8 @@ export default {
MARK_SET_GLOBAL: 'mark.set.global',
MARK_JUMP_GLOBAL: 'mark.jump.global',
+ TAB_SCROLL_TO: 'tab.scroll.to',
+
FIND_NEXT: 'find.next',
FIND_PREV: 'find.prev',
FIND_GET_KEYWORD: 'find.get.keyword',