mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-23 00:37:47 +00:00
Fix action handler performance. (#2828)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
c37502077c
commit
a004c6dfbb
@ -108,6 +108,23 @@
|
|||||||
return m(fp, lc) || m(fp2, lc)
|
return m(fp, lc) || m(fp2, lc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let currentElement: EventTarget | null = null
|
||||||
|
let currentActions: Action[] | undefined = undefined
|
||||||
|
|
||||||
|
function clearActions (doc: any) {
|
||||||
|
currentActions = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
$: selectionDocs = getSelection($focusStore, $selectionStore)
|
||||||
|
|
||||||
|
$: clearActions({
|
||||||
|
mode: mode as ViewContextType,
|
||||||
|
application,
|
||||||
|
focus: $focusStore.focus,
|
||||||
|
selectionStore: $selectionStore,
|
||||||
|
docs: selectionDocs
|
||||||
|
})
|
||||||
|
|
||||||
async function handleKeys (evt: KeyboardEvent): Promise<void> {
|
async function handleKeys (evt: KeyboardEvent): Promise<void> {
|
||||||
const targetTagName = (evt.target as any)?.tagName?.toLowerCase()
|
const targetTagName = (evt.target as any)?.tagName?.toLowerCase()
|
||||||
|
|
||||||
@ -123,11 +140,22 @@
|
|||||||
elm = prt
|
elm = prt
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentActions = await getCurrentActions(
|
if (currentElement !== evt.target) {
|
||||||
{ mode: mode as ViewContextType, application },
|
currentElement = evt.target
|
||||||
$focusStore.focus,
|
currentActions = undefined
|
||||||
$selectionStore
|
}
|
||||||
)
|
|
||||||
|
if (currentActions === undefined) {
|
||||||
|
currentActions = await getCurrentActions(
|
||||||
|
{ mode: mode as ViewContextType, application },
|
||||||
|
$focusStore.focus,
|
||||||
|
$selectionStore
|
||||||
|
)
|
||||||
|
if (targetTagName === 'input' || targetTagName === 'button' || targetTagName === 'textarea') {
|
||||||
|
// Retrieve actual list of actions for input context
|
||||||
|
currentActions = await getContextActions(client, selectionDocs, { ...ctx, mode: 'input' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// For none we ignore all actions.
|
// For none we ignore all actions.
|
||||||
if (ctx.mode === 'none') {
|
if (ctx.mode === 'none') {
|
||||||
@ -135,12 +163,6 @@
|
|||||||
}
|
}
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
|
|
||||||
const docs = getSelection($focusStore, $selectionStore)
|
|
||||||
|
|
||||||
if (targetTagName === 'input' || targetTagName === 'button' || targetTagName === 'textarea') {
|
|
||||||
// Retrieve actual list of actions for input context
|
|
||||||
currentActions = await getContextActions(client, docs, { ...ctx, mode: 'input' })
|
|
||||||
}
|
|
||||||
currentActions = currentActions.filter((p) => p.keyBinding !== undefined && p.keyBinding.length > 0)
|
currentActions = currentActions.filter((p) => p.keyBinding !== undefined && p.keyBinding.length > 0)
|
||||||
if (lastKey !== undefined) {
|
if (lastKey !== undefined) {
|
||||||
for (const a of sequences) {
|
for (const a of sequences) {
|
||||||
@ -151,7 +173,7 @@
|
|||||||
sequences = []
|
sequences = []
|
||||||
lastKey = undefined
|
lastKey = undefined
|
||||||
delayedAction = undefined
|
delayedAction = undefined
|
||||||
return await action(docs, evt, a.actionProps)
|
return await action(selectionDocs, evt, a.actionProps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,9 +190,9 @@
|
|||||||
lastKey = undefined
|
lastKey = undefined
|
||||||
sequences = []
|
sequences = []
|
||||||
delayedAction = undefined
|
delayedAction = undefined
|
||||||
return await action(docs, evt, a.actionProps)
|
return await action(selectionDocs, evt, a.actionProps)
|
||||||
} else {
|
} else {
|
||||||
delayedAction = async () => await action(docs, evt, a.actionProps)
|
delayedAction = async () => await action(selectionDocs, evt, a.actionProps)
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user