Skip to content

Commit

Permalink
fix: change command behavior for monacos
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Oct 3, 2022
1 parent ad0ffb5 commit 0a67d3f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 46 deletions.
25 changes: 11 additions & 14 deletions frontend/src/lib/components/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -364,20 +364,6 @@
editorConfig(model, code, lang, automaticLayout)
)
if (shouldBindKey) {
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, function () {
code = getCode()
format()
})
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, function () {
if (cmdEnterAction) {
code = getCode()
cmdEnterAction()
}
})
}
let timeoutModel: NodeJS.Timeout | undefined = undefined
editor.onDidChangeModelContent((event) => {
timeoutModel && clearTimeout(timeoutModel)
Expand All @@ -389,6 +375,17 @@
editor.onDidFocusEditorText(() => {
dispatch('focus')
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, function () {
code = getCode()
shouldBindKey && format && format()
})
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, function () {
code = getCode()
shouldBindKey && cmdEnterAction && cmdEnterAction()
})
if (
!websocketAlive.black &&
!websocketAlive.deno &&
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/lib/components/FlowBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@
<div class="flex flex-col flex-1 h-full">
<!-- Nav between steps-->
<div class="justify-between flex flex-row w-full my-2 px-4 space-x-4 h-10">
<div id="flow_title" class="flex justify-between items-center">
<button class="flex flex-row items-center w-full h-full" on:click={() => select('settings')}>
<span class="font-mono text-sm"> {$flowStore.path}</span>
<Icon
data={faPen}
scale={0.8}
class="text-gray-500 ml-2 flex justify-center items-center mb-0.5"
/>
</button>
</div>
<div class="shrink h-full">
<button
class="flex flex-row items-center w-full h-full"
Expand Down
24 changes: 10 additions & 14 deletions frontend/src/lib/components/SimpleEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
export let automaticLayout = true
export let extraLib: string = ''
export let extraLibPath: string = ''
export let shouldBindKey: boolean = false
export let shouldBindKey: boolean = true
const dispatch = createEventDispatcher()
Expand Down Expand Up @@ -105,19 +105,6 @@
editorConfig(model, code, lang, automaticLayout)
)
if (shouldBindKey) {
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, function () {
format()
})
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, function () {
if (cmdEnterAction) {
code = getCode()
cmdEnterAction()
}
})
}
let timeoutModel: NodeJS.Timeout | undefined = undefined
editor.onDidChangeModelContent((event) => {
timeoutModel && clearTimeout(timeoutModel)
Expand All @@ -128,6 +115,15 @@
})
editor.onDidFocusEditorText(() => {
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, function () {
code = getCode()
shouldBindKey && format && format()
})
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, function () {
code = getCode()
shouldBindKey && cmdEnterAction && cmdEnterAction()
})
dispatch('focus')
})
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/components/flows/content/FlowLoop.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
lang="javascript"
bind:code={$flowStore.value.modules[index].value.iterator.expr}
class="small-editor"
shouldBindKey={false}
/>
</PropPickerWrapper>
</div>
Expand Down
18 changes: 0 additions & 18 deletions frontend/src/lib/components/flows/header/FlowEditorHeader.svelte
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
<script lang="ts">
import { flowStore } from '$lib/components/flows/flowStore'
import { faPen } from '@fortawesome/free-solid-svg-icons'
import Icon from 'svelte-awesome'
import FlowPreviewButtons from './FlowPreviewButtons.svelte'
import FlowStatus from './FlowStatus.svelte'
import { getContext } from 'svelte'
import type { FlowEditorContext } from '../types'
const { select } = getContext<FlowEditorContext>('FlowEditorContext')
</script>

<div class="flex justify-between items-center border-y p-2 px-4 space-x-2">
<div id="flow_title" class="flex justify-between items-center">
<button on:click={() => select('settings')}>
<span class="font-mono text-sm"> {$flowStore.path}</span>
<Icon
data={faPen}
scale={0.8}
class="text-gray-500 ml-2 flex justify-center items-center mb-0.5"
/>
</button>
</div>
<FlowStatus />
<FlowPreviewButtons />
</div>

0 comments on commit 0a67d3f

Please sign in to comment.