Skip to content

Commit

Permalink
fix: keep focus on the editor after clicking a message action button
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jun 8, 2023
1 parent 78771cd commit aeb5d8f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lib/components/controls/Message.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
import Icon from 'svelte-awesome'
import type { MessageAction } from '$lib/types'
import type { IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { onDestroy } from 'svelte'
export let type: 'success' | 'error' = 'success' // 'success' or 'error'
export let icon: IconDefinition | undefined = undefined
export let message: string | undefined = undefined
export let actions: MessageAction[] = []
export let onClick: (() => void) | undefined = undefined
export let onClose: (() => void) | undefined = undefined
if (onClose) {
onDestroy(onClose)
}
function handleClick() {
if (onClick) {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/components/modes/tablemode/TableMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,10 @@
onClick: handleClearPastedJson
}
]}
onClose={() => {
// TODO: the need for setTimeout is ugly
setTimeout(focus)
}}
/>
{/if}

Expand All @@ -1858,6 +1862,7 @@
}
]
: []}
onClose={focus}
/>
{/if}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/modes/textmode/TextMode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@

&.jse-preview {
flex: 1;
font-family: var(--jse-font-family-mono);
font-size: var(--jse-font-size-mono);
color: var(--jse-panel-color-readonly);
overflow: auto;
white-space: pre-wrap;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/modes/textmode/TextMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@
onClick: cancelLoadTooLarge
}
]}
onClose={focus}
/>

<div class="jse-contents jse-preview">
Expand All @@ -920,6 +921,7 @@
message={jsonParseError.message}
actions={repairActions}
onClick={handleShowMe}
onClose={focus}
/>
{/if}

Expand All @@ -941,6 +943,7 @@
onClick: () => (askToFormat = false)
}
]}
onClose={focus}
/>
{/if}

Expand Down
5 changes: 5 additions & 0 deletions src/lib/components/modes/treemode/TreeMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,10 @@
onClick: handleClearPastedJson
}
]}
onClose={() => {
// TODO: the need for setTimeout is ugly
setTimeout(focus)
}}
/>
{/if}

Expand All @@ -2202,6 +2206,7 @@
}
]
: []}
onClose={focus}
/>
{/if}

Expand Down
2 changes: 1 addition & 1 deletion src/routes/development/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
<button
on:click={() => {
content = {
text: 'abc',
text: '[1,2,3',
json: undefined
}
}}
Expand Down

0 comments on commit aeb5d8f

Please sign in to comment.