Skip to content

Commit

Permalink
fix: #275 flush debounced changes in text mode before blur and destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed May 18, 2023
1 parent 6b21bf6 commit e8270e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/lib/components/modes/textmode/TextMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,20 @@
// This is used to track whether the editor still has focus
let modalOpen = false
onDestroy(() => {
flush()
})
createFocusTracker({
onMount,
onDestroy,
getWindow: () => getWindow(domTextMode),
hasFocus: () => (modalOpen && document.hasFocus()) || activeElementIsChildOf(domTextMode),
onFocus,
onBlur
onBlur: () => {
flush()
onBlur()
}
})
export function patch(operations: JSONPatchDocument): JSONPatchResult {
Expand Down Expand Up @@ -737,6 +744,10 @@
TEXT_MODE_ONCHANGE_DELAY
)
function flush() {
onChangeCodeMirrorValueDebounced.flush()
}
function emitOnChange(content: Content, previousContent: Content) {
if (onChange) {
onChange(content, previousContent, {
Expand Down Expand Up @@ -778,7 +789,7 @@
export function validate(): ContentErrors | null {
debug('validate:start')
onChangeCodeMirrorValueDebounced.flush()
flush()
const contentErrors = memoizedValidateText(
normalization.escapeValue(text),
Expand Down
4 changes: 4 additions & 0 deletions src/routes/development/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@
onChange={onChangeTree}
onRenderValue={$useCustomValueRenderer ? customRenderValue : renderValue}
{onChangeMode}
onFocus={() => console.log('onFocus tree')}
onBlur={() => console.log('onBlur tree', { content: refTreeEditor.get() })}
/>
{/if}
</div>
Expand Down Expand Up @@ -700,6 +702,8 @@
onChange={onChangeText}
onRenderValue={$useCustomValueRenderer ? customRenderValue : renderValue}
{onChangeMode}
onFocus={() => console.log('onFocus text')}
onBlur={() => console.log('onBlur text', { content: refTextEditor.get() })}
/>
{/if}
</div>
Expand Down

0 comments on commit e8270e9

Please sign in to comment.