mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 01:26:01 +00:00
50 lines
1.2 KiB
Svelte
50 lines
1.2 KiB
Svelte
<script lang="ts">
|
|
import _ from 'lodash';
|
|
|
|
import TextField from '../forms/TextField.svelte';
|
|
import keycodes from '../utility/keycodes';
|
|
import ModalBase from './ModalBase.svelte';
|
|
import { closeCurrentModal } from './modalTools';
|
|
import { _t } from '../translations';
|
|
|
|
export let onChange;
|
|
let value;
|
|
|
|
function handleKeyDown(e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
if (e.keyCode == keycodes.escape) {
|
|
closeCurrentModal();
|
|
return;
|
|
}
|
|
|
|
if (e.keyCode == keycodes.enter && value) {
|
|
onChange(value);
|
|
closeCurrentModal();
|
|
return;
|
|
}
|
|
|
|
let keyText = '';
|
|
if (e.ctrlKey) keyText += 'Ctrl+';
|
|
if (e.shiftKey) keyText += 'Shift+';
|
|
if (e.metaKey) keyText += 'Command+';
|
|
if (e.altKey) keyText += 'Alt+';
|
|
if (e.key != 'Control' && e.key != 'Alt' && e.key != 'Shift' && e.key != 'Meta') {
|
|
keyText += _.upperFirst(e.key);
|
|
}
|
|
|
|
value = keyText;
|
|
}
|
|
</script>
|
|
|
|
<ModalBase {...$$restProps} simple>
|
|
<div class="mb-2">{_t('commandModal.showKeyCombination', { defaultMessage: 'Show desired key combination and press ENTER' })}</div>
|
|
<div class="largeFormMarker">
|
|
<TextField on:keydown={handleKeyDown} bind:value focused />
|
|
</div>
|
|
</ModalBase>
|
|
|
|
<style>
|
|
</style>
|