aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-24 21:51:18 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-24 21:51:18 +0900
commit8d0739463d970deae2ebdd88eedac29e9c4379ff (patch)
tree72cda1df081e5d094c39cab5444855cf09669b0d /src/background
parente779fb1779f33fb15857b5d20cb72a4b00d20f77 (diff)
Move open parent and open root to background
Diffstat (limited to 'src/background')
-rw-r--r--src/background/controllers/OperationController.ts4
-rw-r--r--src/background/presenters/TabPresenter.ts2
-rw-r--r--src/background/usecases/NavigateUseCase.ts25
3 files changed, 26 insertions, 5 deletions
diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts
index cb5c043..1e80f54 100644
--- a/src/background/controllers/OperationController.ts
+++ b/src/background/controllers/OperationController.ts
@@ -84,6 +84,10 @@ export default class OperationController {
return this.navigateUseCase.openLinkPrev();
case operations.NAVIGATE_LINK_NEXT:
return this.navigateUseCase.openLinkNext();
+ case operations.NAVIGATE_PARENT:
+ return this.navigateUseCase.openParent();
+ case operations.NAVIGATE_ROOT:
+ return this.navigateUseCase.openRoot();
}
throw new Error('unknown operation: ' + operation.type);
}
diff --git a/src/background/presenters/TabPresenter.ts b/src/background/presenters/TabPresenter.ts
index 5665bf0..5e6e56e 100644
--- a/src/background/presenters/TabPresenter.ts
+++ b/src/background/presenters/TabPresenter.ts
@@ -36,7 +36,7 @@ export default class TabPresenter {
return tabId;
}
- async getByKeyword(keyword: string, excludePinned = false): Promise<Tab[]> {
+ async getByKeyword(keyword: string, excludePinned: boolean = false): Promise<Tab[]> {
let tabs = await browser.tabs.query({ currentWindow: true });
return tabs.filter((t) => {
return t.url && t.url.toLowerCase().includes(keyword.toLowerCase()) ||
diff --git a/src/background/usecases/NavigateUseCase.ts b/src/background/usecases/NavigateUseCase.ts
index 76e1c8e..ced2a0b 100644
--- a/src/background/usecases/NavigateUseCase.ts
+++ b/src/background/usecases/NavigateUseCase.ts
@@ -30,11 +30,28 @@ export default class NavigateUseCase {
await this.navigateClient.linkPrev(tab.id!!);
}
- openParent(): Promise<void> {
- throw new Error('not implemented');
+ async openParent(): Promise<void> {
+ let tab = await this.tabPresenter.getCurrent();
+ let url = new URL(tab.url!!);
+ if (url.hash !== '') {
+ url.hash = '';
+ } else if (url.search !== '') {
+ url.search = '';
+ } else {
+ const basenamePattern = /\/[^/]+$/;
+ const lastDirPattern = /\/[^/]+\/$/;
+ if (basenamePattern.test(url.pathname)) {
+ url.pathname = url.pathname.replace(basenamePattern, '/');
+ } else if (lastDirPattern.test(url.pathname)) {
+ url.pathname = url.pathname.replace(lastDirPattern, '/');
+ }
+ }
+ await this.tabPresenter.open(url.href);
}
- openRoot(): Promise<void> {
- throw new Error('not implemented');
+ async openRoot(): Promise<void> {
+ let tab = await this.tabPresenter.getCurrent();
+ let url = new URL(tab.url!!);
+ await this.tabPresenter.open(url.origin);
}
}