editor context menu, focus fix

This commit is contained in:
Jan Prochazka
2021-03-11 07:53:37 +01:00
parent 5f97f7d922
commit c193955fbe
6 changed files with 91 additions and 12 deletions

View File

@@ -1,8 +1,8 @@
<script lang="ts">
<script lang="ts" context="module">
import { commands } from '../stores';
import { get } from 'svelte/store';
function handleKeyDown(e) {
export function handleCommandKeyDown(e) {
let keyText = '';
if (e.ctrlKey) keyText += 'Ctrl+';
if (e.shiftKey) keyText += 'Shift+';
@@ -20,7 +20,13 @@
.toLowerCase()
.split('|')
.map(x => x.trim())
.includes(keyText.toLowerCase())
.includes(keyText.toLowerCase()) &&
(x.disableHandleKeyText == null ||
!x.disableHandleKeyText
.toLowerCase()
.split('|')
.map(x => x.trim())
.includes(keyText.toLowerCase()))
);
if (command) {
@@ -30,4 +36,4 @@
}
</script>
<svelte:window on:keydown={handleKeyDown} />
<svelte:window on:keydown={handleCommandKeyDown} />

View File

@@ -31,7 +31,13 @@
$: selectedIndex = true ? 0 : filter;
onMount(() => domInput.focus());
onMount(() => {
const oldFocus = document.activeElement;
domInput.focus();
return () => {
if (oldFocus) oldFocus.focus();
};
});
$: sortedComands = _.sortBy(
Object.values($commands).filter(x => x.enabled),

View File

@@ -20,6 +20,7 @@ export interface GlobalCommand {
showDisabled?: boolean;
toolbarName?: string;
toolbarOrder?: number;
disableHandleKeyText?: string;
}
export default function registerCommand(command: GlobalCommand) {