implement go-parent command
This commit is contained in:
parent
0be9776cb3
commit
e9863299ab
6 changed files with 34 additions and 5 deletions
|
@ -39,7 +39,7 @@ Firefox by WebExtensions API.
|
||||||
- [ ] navigations
|
- [ ] navigations
|
||||||
- [ ] yank/paste page
|
- [ ] yank/paste page
|
||||||
- [x] pagenation
|
- [x] pagenation
|
||||||
- [ ] open parent page
|
- [x] open parent page
|
||||||
- [ ] hints
|
- [ ] hints
|
||||||
- [x] open a link
|
- [x] open a link
|
||||||
- [ ] open a link in new tab
|
- [ ] open a link in new tab
|
||||||
|
|
|
@ -32,6 +32,7 @@ const defaultKeymap = {
|
||||||
'L': { type: operations.NAVIGATE_HISTORY_NEXT },
|
'L': { type: operations.NAVIGATE_HISTORY_NEXT },
|
||||||
'[[': { type: operations.NAVIGATE_LINK_PREV },
|
'[[': { type: operations.NAVIGATE_LINK_PREV },
|
||||||
']]': { type: operations.NAVIGATE_LINK_NEXT },
|
']]': { type: operations.NAVIGATE_LINK_NEXT },
|
||||||
|
'gu': { type: operations.NAVIGATE_PARENT },
|
||||||
};
|
};
|
||||||
|
|
||||||
const asKeymapChars = (keys) => {
|
const asKeymapChars = (keys) => {
|
||||||
|
|
|
@ -43,6 +43,8 @@ const execOperation = (operation) => {
|
||||||
return navigates.linkPrev(window);
|
return navigates.linkPrev(window);
|
||||||
case operations.NAVIGATE_LINK_NEXT:
|
case operations.NAVIGATE_LINK_NEXT:
|
||||||
return navigates.linkNext(window);
|
return navigates.linkNext(window);
|
||||||
|
case operations.NAVIGATE_PARENT:
|
||||||
|
return navigates.parent(window);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,4 +44,23 @@ const linkNext = (win) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export { historyPrev, historyNext, linkPrev, linkNext };
|
const parent = (win) => {
|
||||||
|
let loc = win.location;
|
||||||
|
if (loc.hash !== '') {
|
||||||
|
loc.hash = '';
|
||||||
|
return;
|
||||||
|
} else if (loc.search !== '') {
|
||||||
|
loc.search = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const basenamePattern = /\/[^/]+$/;
|
||||||
|
const lastDirPattern = /\/[^/]+\/$/;
|
||||||
|
if (basenamePattern.test(loc.pathname)) {
|
||||||
|
loc.pathname = loc.pathname.replace(basenamePattern, '/');
|
||||||
|
} else if (lastDirPattern.test(loc.pathname)) {
|
||||||
|
loc.pathname = loc.pathname.replace(lastDirPattern, '/');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export { historyPrev, historyNext, linkPrev, linkNext, parent };
|
||||||
|
|
|
@ -15,6 +15,7 @@ export default {
|
||||||
NAVIGATE_HISTORY_NEXT: 'navigate.history.next',
|
NAVIGATE_HISTORY_NEXT: 'navigate.history.next',
|
||||||
NAVIGATE_LINK_PREV: 'navigate.link.prev',
|
NAVIGATE_LINK_PREV: 'navigate.link.prev',
|
||||||
NAVIGATE_LINK_NEXT: 'navigate.link.next',
|
NAVIGATE_LINK_NEXT: 'navigate.link.next',
|
||||||
|
NAVIGATE_PARENT: 'navigate.parent',
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
TABS_CLOSE: 'tabs.close',
|
TABS_CLOSE: 'tabs.close',
|
||||||
|
|
|
@ -2,9 +2,6 @@ import { expect } from "chai";
|
||||||
import * as navigates from '../../src/content/navigates';
|
import * as navigates from '../../src/content/navigates';
|
||||||
|
|
||||||
describe('navigates module', () => {
|
describe('navigates module', () => {
|
||||||
beforeEach(() => {
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#linkPrev', () => {
|
describe('#linkPrev', () => {
|
||||||
it('clicks prev link by text content', (done) => {
|
it('clicks prev link by text content', (done) => {
|
||||||
document.body.innerHTML = '<a href="#dummy">xprevx</a> <a href="#prev">go to prev</a>';
|
document.body.innerHTML = '<a href="#dummy">xprevx</a> <a href="#prev">go to prev</a>';
|
||||||
|
@ -45,6 +42,15 @@ describe('navigates module', () => {
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#parent', () => {
|
||||||
|
// NOTE: not able to test location
|
||||||
|
it('removes hash', () => {
|
||||||
|
window.location.hash = "#section-1";
|
||||||
|
navigates.parent(window);
|
||||||
|
expect(document.location.hash).to.be.empty;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue