Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when resetting mode to the default value (undefined), the mode switches successfully, but the corresponding menu item is not selected #424

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/lib/components/modes/JSONEditorRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
TransformModalOptions,
Validator
} from '$lib/types'
import DEFAULT_PROPERTIES from '../../utils/DEFAULT_PROPERTIES'
import { Mode } from '$lib/types.js'
import TextMode from './textmode/TextMode.svelte'
import TableMode from './tablemode/TableMode.svelte'
Expand All @@ -42,7 +43,7 @@
export let readOnly: boolean
export let indentation: number | string
export let tabSize: number
export let mode: Mode
export let mode: Mode | undefined
export let mainMenuBar: boolean
export let navigationBar: boolean
export let statusBar: boolean
Expand Down Expand Up @@ -84,21 +85,27 @@
// check for 'code' mode is here for backward compatibility (deprecated since v0.4.0)
className:
'jse-group-button jse-first' +
(mode === Mode.text || (mode as string) === 'code' ? ' jse-selected' : ''),
((mode || DEFAULT_PROPERTIES.mode) === Mode.text || (mode as string) === 'code'
? ' jse-selected'
: ''),
onClick: () => onChangeMode(Mode.text)
},
{
type: 'button',
text: 'tree',
title: `Switch to tree mode (current mode: ${mode})`,
className: 'jse-group-button ' + (mode === Mode.tree ? ' jse-selected' : ''),
className:
'jse-group-button ' +
((mode || DEFAULT_PROPERTIES.mode) === Mode.tree ? ' jse-selected' : ''),
onClick: () => onChangeMode(Mode.tree)
},
{
type: 'button',
text: 'table',
title: `Switch to table mode (current mode: ${mode})`,
className: 'jse-group-button jse-last' + (mode === Mode.table ? ' jse-selected' : ''),
className:
'jse-group-button jse-last' +
((mode || DEFAULT_PROPERTIES.mode) === Mode.table ? ' jse-selected' : ''),
onClick: () => onChangeMode(Mode.table)
}
]
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils/DEFAULT_PROPERTIES.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Mode } from '$lib/types.js'

export default {
mode: Mode.tree
// ...others
}
1 change: 1 addition & 0 deletions src/routes/development/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@
<input type="checkbox" bind:checked={$showTreeEditor} /> Show tree editor
</label>
<select class="mode-toggle" bind:value={leftEditorMode}>
<option value={undefined}>undefined</option>
<option value="tree">tree</option>
<option value="text">text</option>
<option value="table">table</option>
Expand Down