Fixes @mention draft changes
This commit is contained in:
parent
fa938e8c7d
commit
e3d9e6b906
3 changed files with 23 additions and 9 deletions
|
@ -369,7 +369,7 @@ export function CompositionArea({
|
||||||
const previousConversationId = usePrevious(conversationId, conversationId);
|
const previousConversationId = usePrevious(conversationId, conversationId);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!draftText) {
|
if (!draftText) {
|
||||||
inputApiRef.current?.setText('');
|
inputApiRef.current?.setContents('');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,8 +377,8 @@ export function CompositionArea({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputApiRef.current?.setText(draftText, true);
|
inputApiRef.current?.setContents(draftText, draftBodyRanges, true);
|
||||||
}, [conversationId, draftText, previousConversationId]);
|
}, [conversationId, draftBodyRanges, draftText, previousConversationId]);
|
||||||
|
|
||||||
const handleToggleLarge = useCallback(() => {
|
const handleToggleLarge = useCallback(() => {
|
||||||
setLarge(l => !l);
|
setLarge(l => !l);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import Delta from 'quill-delta';
|
||||||
import ReactQuill from 'react-quill';
|
import ReactQuill from 'react-quill';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { Manager, Reference } from 'react-popper';
|
import { Manager, Reference } from 'react-popper';
|
||||||
import type { KeyboardStatic, RangeStatic } from 'quill';
|
import type { DeltaStatic, KeyboardStatic, RangeStatic } from 'quill';
|
||||||
import Quill from 'quill';
|
import Quill from 'quill';
|
||||||
|
|
||||||
import { MentionCompletion } from '../quill/mentions/completion';
|
import { MentionCompletion } from '../quill/mentions/completion';
|
||||||
|
@ -60,7 +60,11 @@ type HistoryStatic = {
|
||||||
export type InputApi = {
|
export type InputApi = {
|
||||||
focus: () => void;
|
focus: () => void;
|
||||||
insertEmoji: (e: EmojiPickDataType) => void;
|
insertEmoji: (e: EmojiPickDataType) => void;
|
||||||
setText: (text: string, cursorToEnd?: boolean) => void;
|
setContents: (
|
||||||
|
text: string,
|
||||||
|
draftBodyRanges?: DraftBodyRangesType,
|
||||||
|
cursorToEnd?: boolean
|
||||||
|
) => void;
|
||||||
reset: () => void;
|
reset: () => void;
|
||||||
submit: () => void;
|
submit: () => void;
|
||||||
};
|
};
|
||||||
|
@ -234,15 +238,25 @@ export function CompositionInput(props: Props): React.ReactElement {
|
||||||
historyModule.clear();
|
historyModule.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
const setText = (text: string, cursorToEnd?: boolean) => {
|
const setContents = (
|
||||||
|
text: string,
|
||||||
|
bodyRanges?: DraftBodyRangesType,
|
||||||
|
cursorToEnd?: boolean
|
||||||
|
) => {
|
||||||
const quill = quillRef.current;
|
const quill = quillRef.current;
|
||||||
|
|
||||||
if (quill === undefined) {
|
if (quill === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const delta = generateDelta(text || '', bodyRanges || []);
|
||||||
|
|
||||||
canSendRef.current = true;
|
canSendRef.current = true;
|
||||||
quill.setText(text);
|
// We need to cast here because we use @types/quill@1.3.10 which has types
|
||||||
|
// for quill-delta even though quill-delta is written in TS and has its own
|
||||||
|
// types. @types/quill@2.0.0 fixes the issue but react-quill has a peer-dep
|
||||||
|
// on the older quill types.
|
||||||
|
quill.setContents(delta as unknown as DeltaStatic);
|
||||||
if (cursorToEnd) {
|
if (cursorToEnd) {
|
||||||
quill.setSelection(quill.getLength(), 0);
|
quill.setSelection(quill.getLength(), 0);
|
||||||
}
|
}
|
||||||
|
@ -276,7 +290,7 @@ export function CompositionInput(props: Props): React.ReactElement {
|
||||||
inputApi.current = {
|
inputApi.current = {
|
||||||
focus,
|
focus,
|
||||||
insertEmoji,
|
insertEmoji,
|
||||||
setText,
|
setContents,
|
||||||
reset,
|
reset,
|
||||||
submit,
|
submit,
|
||||||
};
|
};
|
||||||
|
|
|
@ -112,7 +112,7 @@ export function CompositionTextArea({
|
||||||
// was modifying text in the middle of the editor
|
// was modifying text in the middle of the editor
|
||||||
// a better solution would be to prevent the change to begin with, but
|
// a better solution would be to prevent the change to begin with, but
|
||||||
// quill makes this VERY difficult
|
// quill makes this VERY difficult
|
||||||
inputEl.setText(newValueSized, true);
|
inputEl.setContents(newValueSized, bodyRanges, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCharacterCount(newCharacterCount);
|
setCharacterCount(newCharacterCount);
|
||||||
|
|
Loading…
Reference in a new issue