mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-05 23:10:28 +03:00
Fix editor bugs (#1281)
* focus editor on reply click * fix emoji and sticker img object-fit * fix cursor not moving with autocomplete * stop sanitizing sending plain text body * improve autocomplete query parsing * add escape to turn off active editor toolbar item
This commit is contained in:
parent
6d199244ef
commit
2883b4c35b
9 changed files with 69 additions and 22 deletions
|
|
@ -2,11 +2,25 @@ import { BasePoint, BaseRange, Editor, Element, Point, Range, Transforms } from
|
|||
import { BlockType, MarkType } from './Elements';
|
||||
import { EmoticonElement, FormattedText, HeadingLevel, LinkElement, MentionElement } from './slate';
|
||||
|
||||
const ALL_MARK_TYPE: MarkType[] = [
|
||||
MarkType.Bold,
|
||||
MarkType.Code,
|
||||
MarkType.Italic,
|
||||
MarkType.Spoiler,
|
||||
MarkType.StrikeThrough,
|
||||
MarkType.Underline,
|
||||
];
|
||||
|
||||
export const isMarkActive = (editor: Editor, format: MarkType) => {
|
||||
const marks = Editor.marks(editor);
|
||||
return marks ? marks[format] === true : false;
|
||||
};
|
||||
|
||||
export const isAnyMarkActive = (editor: Editor) => {
|
||||
const marks = Editor.marks(editor);
|
||||
return marks && !!ALL_MARK_TYPE.find((type) => marks[type] === true);
|
||||
};
|
||||
|
||||
export const toggleMark = (editor: Editor, format: MarkType) => {
|
||||
const isActive = isMarkActive(editor, format);
|
||||
|
||||
|
|
@ -17,6 +31,10 @@ export const toggleMark = (editor: Editor, format: MarkType) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const removeAllMark = (editor: Editor) => {
|
||||
ALL_MARK_TYPE.forEach((mark) => Editor.removeMark(editor, mark));
|
||||
};
|
||||
|
||||
export const isBlockActive = (editor: Editor, format: BlockType) => {
|
||||
const [match] = Editor.nodes(editor, {
|
||||
match: (node) => Element.isElement(node) && node.type === format,
|
||||
|
|
@ -140,11 +158,11 @@ export const replaceWithElement = (editor: Editor, selectRange: BaseRange, eleme
|
|||
};
|
||||
|
||||
export const moveCursor = (editor: Editor, withSpace?: boolean) => {
|
||||
// without timeout it works properly when we select autocomplete with Tab or Space
|
||||
// without timeout move cursor doesn't works properly.
|
||||
setTimeout(() => {
|
||||
Transforms.move(editor);
|
||||
if (withSpace) editor.insertText(' ');
|
||||
}, 1);
|
||||
}, 100);
|
||||
};
|
||||
|
||||
interface PointUntilCharOptions {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue