Skip to content

Commit

Permalink
allow setContentStateFromText to be immediate
Browse files Browse the repository at this point in the history
We have a use-case for content-state to be updated immediately when switching to a full-screen behavior. This should allow that to be possible
  • Loading branch information
abrin committed Jul 3, 2024
1 parent 05780c2 commit e74229e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type NormalisedContentState = {
motivation: ['contentState', ...string[]];
target: Array<SupportedTarget>;
extensions: Record<string, any>;
immediate?: boolean;
};

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/canvas-panel/src/web-components/canvas-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,12 @@ export const CanvasPanel: FC<CanvasPanelProps> = (props) => {
contentStateStack.current = [];
},

setContentStateFromText(text: string) {
setContentStateFromText(text: string, immediate = false) {
if (text == undefined || text.trim() === '') {
return;
}
const contentState = normaliseContentState(parseContentState(text));
contentState.immediate = immediate;
const firstTarget = contentState.target[0];

if (canvasIdRef.current === firstTarget.source.id) {
Expand All @@ -234,7 +235,7 @@ export const CanvasPanel: FC<CanvasPanelProps> = (props) => {
contentState.target[0].selector &&
contentState.target[0].selector.type === 'BoxSelector'
) {
runtime.current.world.gotoRegion(contentState.target[0].selector.spatial);
runtime.current.world.gotoRegion({ ...contentState.target[0].selector.spatial, immediate });
}
} else {
setParsedContentState(contentState);
Expand Down Expand Up @@ -275,6 +276,7 @@ export const CanvasPanel: FC<CanvasPanelProps> = (props) => {
y,
width,
height,
immediate: contentState.immediate,
});
} else {
setParsedTarget(firstTarget);
Expand Down
4 changes: 3 additions & 1 deletion packages/canvas-panel/src/web-components/sequence-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ export function SequencePanel(props: SequencePanelProps) {
return ContentStateEvent;
},

setContentStateFromText(text: string) {
setContentStateFromText(text: string, immediate = false) {
if (text == undefined || text.trim() === '') {
return;
}
const contentState = normaliseContentState(parseContentState(text));
contentState.immediate = immediate;
setParsedContentState(contentState);
},

Expand Down Expand Up @@ -185,6 +186,7 @@ export function SequencePanel(props: SequencePanelProps) {
y,
width,
height,
immediate: contentState.immediate,
});
}
}
Expand Down

0 comments on commit e74229e

Please sign in to comment.