diff --git a/src/examples/basics.tsx b/src/examples/basics.tsx index faba8ed8..74d163a2 100644 --- a/src/examples/basics.tsx +++ b/src/examples/basics.tsx @@ -156,7 +156,22 @@ export function Lists() { } export function Table() { - return + return ( + ( + + + + ) + }) + ]} + /> + ) } export function Link() { diff --git a/src/plugins/core/index.ts b/src/plugins/core/index.ts index 3e336039..9244fe0a 100644 --- a/src/plugins/core/index.ts +++ b/src/plugins/core/index.ts @@ -706,24 +706,32 @@ export type ViewMode = 'rich-text' | 'source' | 'diff' * @group Diff/Source */ export const viewMode$ = Cell('rich-text', (r) => { + function currentNextViewMode() { + return scan( + (prev, next: ViewMode) => { + return { + current: prev.next, + next + } + }, + { current: 'rich-text' as ViewMode, next: 'rich-text' as ViewMode } + ) + } + r.sub(r.pipe(viewMode$, currentNextViewMode(), withLatestFrom(markdownSourceEditorValue$)), ([{ current }, markdownSourceFromEditor]) => { + if (current === 'source' || current === 'diff') { + r.pub(setMarkdown$, markdownSourceFromEditor) + } + }) + r.sub( r.pipe( viewMode$, - scan( - (prev, next) => { - return { - current: prev.next, - next - } - }, - { current: 'rich-text' as ViewMode, next: 'rich-text' as ViewMode } - ), - withLatestFrom(markdownSourceEditorValue$) + currentNextViewMode(), + filter((mode) => mode.current === 'rich-text'), + withLatestFrom(activeEditor$) ), - ([{ current }, markdownSourceFromEditor]) => { - if (current === 'source' || current === 'diff') { - r.pub(setMarkdown$, markdownSourceFromEditor) - } + ([mode, editor]) => { + editor?.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, undefined) } ) }) diff --git a/src/plugins/table/TableEditor.tsx b/src/plugins/table/TableEditor.tsx index 6f21edaf..f6900fed 100644 --- a/src/plugins/table/TableEditor.tsx +++ b/src/plugins/table/TableEditor.tsx @@ -30,6 +30,7 @@ import styles from '../../styles/ui.module.css' import { isPartOftheEditorUI } from '../../utils/isPartOftheEditorUI' import { uuidv4 } from '../../utils/uuid4' import { + NESTED_EDITOR_UPDATED_COMMAND, editorRootElementRef$, exportVisitors$, iconComponentFor$, @@ -394,6 +395,15 @@ const CellEditor: React.FC = ({ focus, setActiveCell, parentEditor, l return true }, COMMAND_PRIORITY_CRITICAL + ), + + editor.registerCommand( + NESTED_EDITOR_UPDATED_COMMAND, + () => { + saveAndFocus(null) + return true + }, + COMMAND_PRIORITY_CRITICAL ) ) }, [colIndex, editor, rootEditor, rowIndex, saveAndFocus, setActiveCell])