Move open parent and open root to background
This commit is contained in:
parent
e779fb1779
commit
8d0739463d
8 changed files with 108 additions and 57 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()) ||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue