aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
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);
}
}