Merge pull request #308 from ueokande/focus-input

Focus input
This commit is contained in:
Shin'ya Ueoka 2018-01-18 10:41:08 +00:00 committed by GitHub
commit 1f57547c0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 22 deletions

View file

@ -31,6 +31,9 @@ export default {
NAVIGATE_PARENT: 'navigate.parent',
NAVIGATE_ROOT: 'navigate.root',
// Focus
FOCUS_INPUT: 'focus.input',
// Tabs
TAB_CLOSE: 'tabs.close',
TAB_CLOSE_FORCE: 'tabs.close.force',

View file

@ -45,6 +45,7 @@ export default {
"]]": { "type": "navigate.link.next" },
"gu": { "type": "navigate.parent" },
"gU": { "type": "navigate.root" },
"gi": { "type": "focus.input" },
"y": { "type": "urls.yank" },
"p": { "type": "urls.paste", "newTab": false },
"P": { "type": "urls.paste", "newTab": true },

View file

@ -81,4 +81,26 @@ const viewportRect = (e) => {
};
};
export { isContentEditable, viewportRect };
const isVisible = (element) => {
let rect = element.getBoundingClientRect();
if (rect.width === 0 || rect.height === 0) {
return false;
}
if (rect.right < 0 && rect.bottom < 0) {
return false;
}
if (window.innerWidth < rect.left && window.innerHeight < rect.top) {
return false;
}
if (element.nodeName === 'INPUT' && element.type.toLowerCase() === 'hidden') {
return false;
}
let { display, visibility } = window.getComputedStyle(element);
if (display === 'none' || visibility === 'hidden') {
return false;
}
return true;
};
export { isContentEditable, viewportRect, isVisible };