From 655fe8de49a4391ea00d4ba9f3ff5c9eee95f0a9 Mon Sep 17 00:00:00 2001 From: thecalcc Date: Fri, 8 Sep 2023 13:11:38 +0300 Subject: [PATCH 1/2] Multi line image caption --- .../core/editor3/components/media/MediaBlock.tsx | 1 + .../PlainTextEditor/PlainTextEditor.tsx | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/core/editor3/components/media/MediaBlock.tsx b/scripts/core/editor3/components/media/MediaBlock.tsx index b88588fd81..37d0897aee 100644 --- a/scripts/core/editor3/components/media/MediaBlock.tsx +++ b/scripts/core/editor3/components/media/MediaBlock.tsx @@ -292,6 +292,7 @@ export class MediaBlockComponent extends React.Component { void; disabled?: boolean; + multiLine?: boolean; } interface IState { @@ -51,15 +52,17 @@ function updateStateWithValue(value: string, editorState: EditorState) { } export class PlainTextEditor extends React.Component { - spellcheckerTimeout?: number; - selection: SelectionState; + private spellcheckerTimeout?: number; + private selection: SelectionState; + private lastComputedValue: string; constructor(props) { super(props); + this.lastComputedValue = props.value?.toString() || ''; this.state = { editorState: EditorState.createWithContent( - ContentState.createFromText(props.value?.toString() || ''), + ContentState.createFromText(this.lastComputedValue), ), hasFocus: false, }; @@ -120,7 +123,9 @@ export class PlainTextEditor extends React.Component { * This version works fine and we can still handle our own selection state * */ UNSAFE_componentWillReceiveProps(props: IProps) { - this.setState({editorState: updateStateWithValue(props.value || '', this.state.editorState)}); + if (this.lastComputedValue !== props.value) { + this.setState({editorState: updateStateWithValue(props.value || '', this.state.editorState)}); + } } handleEditorChange(editorState: EditorState) { @@ -130,6 +135,7 @@ export class PlainTextEditor extends React.Component { ) { const value = editorState.getCurrentContent().getPlainText(); + this.lastComputedValue = value; this.props.onChange(value, this.props.onChangeData); } @@ -153,7 +159,7 @@ export class PlainTextEditor extends React.Component { } handleKeyCommand(command: DraftEditorCommand): DraftHandleValue { - if (command === 'split-block') { + if (command === 'split-block' && this.props.multiLine !== true) { return 'handled'; // disable Enter } From 8d8d553d26ebb6d4f33d562eff5f06e4f69968db Mon Sep 17 00:00:00 2001 From: thecalcc Date: Fri, 8 Sep 2023 13:15:04 +0300 Subject: [PATCH 2/2] Add comment --- scripts/core/ui/components/PlainTextEditor/PlainTextEditor.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/core/ui/components/PlainTextEditor/PlainTextEditor.tsx b/scripts/core/ui/components/PlainTextEditor/PlainTextEditor.tsx index 52fbe58281..3baaf01d2f 100644 --- a/scripts/core/ui/components/PlainTextEditor/PlainTextEditor.tsx +++ b/scripts/core/ui/components/PlainTextEditor/PlainTextEditor.tsx @@ -28,6 +28,8 @@ export interface IProps { placeholder?: string; onFocus?: () => void; disabled?: boolean; + + // Defaults to false. multiLine?: boolean; }