Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/ts/hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export function initHotkey(){
!ev.ctrlKey &&
!ev.altKey &&
!ev.shiftKey &&
(['INPUT', 'TEXTAREA'].includes(document.activeElement.tagName) ||
document.activeElement.getAttribute('contenteditable'))
isTypingTarget(document.activeElement)
){
return
}
Expand Down Expand Up @@ -337,11 +336,27 @@ export function hotkeyMatches(hotkey: typeof DBState.db.hotkeys[number], ev: Key
if(hotkey.shift !== ev.shiftKey) return false
if(hotkey.key.toLowerCase() !== ev.key.toLowerCase()) return false
if(!hotkey.ctrl && !hotkey.alt && !hotkey.shift){
if(['INPUT', 'TEXTAREA'].includes(document.activeElement.tagName)) return false
return !isTypingTarget(document.activeElement)
}
return true
}

/**
* Whether `el` accepts text input.
*/
function isTypingTarget(el: Element | null): boolean {
if(!el){
return false
}
if(['INPUT', 'TEXTAREA'].includes(el.tagName)){
return true
}
if(el instanceof HTMLElement && el.isContentEditable){
return true
}
return 'editContext' in el && el.editContext != null
}

function clickQuery(query:string){
let ele = document.querySelector(query) as HTMLElement
console.log(ele)
Expand Down
Loading