Commit 1a5f38ae authored by Konrad Borowski's avatar Konrad Borowski

Add Ctrl+Enter keyboard shortcut

parent 2291ea4d
Pipeline #98460604 passed with stages
in 16 minutes and 44 seconds
......@@ -92,6 +92,7 @@ export default function createMonacoEditor(textarea, onChange) {
value: textarea.value,
})
editor.onDidChangeModelContent(onChange)
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, () => {})
textarea.form.addEventListener('submit', () => textarea.value = editor.getValue())
return new MonacoEditor(textarea, container, editor)
}
......@@ -4,10 +4,11 @@ export default class WrapperButtons {
buttonsContainer: HTMLSpanElement
compilerOptions: HTMLInputElement
buttons: HTMLSpanElement
run: (wrapper: Wrapper, compilerOptions: string) => void;
run: (wrapper: Wrapper, compilerOptions: string) => void
abortController: AbortController
select: HTMLSelectElement
optionMap = new WeakMap<HTMLOptionElement, { identifier: string, wrappers: Wrapper[] }>()
globalKeyEvent: (e: KeyboardEvent) => void | null = null
constructor(buttonsContainer, run) {
this.buttonsContainer = buttonsContainer
......@@ -39,6 +40,8 @@ export default class WrapperButtons {
}
clear() {
document.removeEventListener('keydown', this.globalKeyEvent)
this.globalKeyEvent = null
this.buttonsContainer.textContent = ''
}
......@@ -50,13 +53,24 @@ export default class WrapperButtons {
}
if (options.length !== 0) {
const option = options[0]
let first = true
for (const wrapper of this.optionMap.get(option).wrappers) {
const button = document.createElement('button')
button.textContent = wrapper.label
button.addEventListener('click', e => {
const event = (e: Event) => {
e.preventDefault()
this.run(wrapper, this.compilerOptions.value)
})
}
if (first) {
this.globalKeyEvent = e => {
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
event(e)
}
}
document.addEventListener('keydown', this.globalKeyEvent)
first = false
}
button.addEventListener('click', event)
this.buttons.append(button)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment