Text Formatter: Add button and hotkey for spoiler
This commit is contained in:
parent
22401f5490
commit
76c98116b8
@ -294,6 +294,8 @@ export function buildMtpMessageEntity(entity: ApiMessageEntity): GramJs.TypeMess
|
|||||||
length,
|
length,
|
||||||
userId: new GramJs.InputUser({ userId: BigInt(userId!), accessHash: user!.accessHash! }),
|
userId: new GramJs.InputUser({ userId: BigInt(userId!), accessHash: user!.accessHash! }),
|
||||||
});
|
});
|
||||||
|
case ApiMessageEntityTypes.Spoiler:
|
||||||
|
return new GramJs.MessageEntitySpoiler({ offset, length });
|
||||||
default:
|
default:
|
||||||
return new GramJs.MessageEntityUnknown({ offset, length });
|
return new GramJs.MessageEntityUnknown({ offset, length });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -499,6 +499,8 @@ function processEntityAsHtml(
|
|||||||
data-entity-type="${entity.type}"
|
data-entity-type="${entity.type}"
|
||||||
dir="auto"
|
dir="auto"
|
||||||
>${renderedContent}</a>`;
|
>${renderedContent}</a>`;
|
||||||
|
case ApiMessageEntityTypes.Spoiler:
|
||||||
|
return `||${renderedContent}||`;
|
||||||
default:
|
default:
|
||||||
return renderedContent;
|
return renderedContent;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -253,6 +253,12 @@ const TextFormatter: FC<OwnProps> = ({
|
|||||||
selectedRange, selectedTextFormats.strikethrough,
|
selectedRange, selectedTextFormats.strikethrough,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const handleSpoilerText = useCallback(() => {
|
||||||
|
const text = getSelectedText();
|
||||||
|
document.execCommand('insertHTML', false, `||${text}||`);
|
||||||
|
onClose();
|
||||||
|
}, [getSelectedText, onClose]);
|
||||||
|
|
||||||
const handleMonospaceText = useCallback(() => {
|
const handleMonospaceText = useCallback(() => {
|
||||||
if (selectedTextFormats.monospace) {
|
if (selectedTextFormats.monospace) {
|
||||||
const element = getSelectedElement();
|
const element = getSelectedElement();
|
||||||
@ -314,6 +320,7 @@ const TextFormatter: FC<OwnProps> = ({
|
|||||||
i: handleItalicText,
|
i: handleItalicText,
|
||||||
m: handleMonospaceText,
|
m: handleMonospaceText,
|
||||||
s: handleStrikethroughText,
|
s: handleStrikethroughText,
|
||||||
|
p: handleSpoilerText,
|
||||||
};
|
};
|
||||||
|
|
||||||
const handler = HANDLERS_BY_KEY[getKeyFromEvent(e)];
|
const handler = HANDLERS_BY_KEY[getKeyFromEvent(e)];
|
||||||
@ -330,9 +337,8 @@ const TextFormatter: FC<OwnProps> = ({
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
handler();
|
handler();
|
||||||
}, [
|
}, [
|
||||||
handleBoldText, handleItalicText, handleUnderlineText,
|
openLinkControl, handleBoldText, handleUnderlineText, handleItalicText, handleMonospaceText,
|
||||||
handleMonospaceText, handleStrikethroughText,
|
handleStrikethroughText, handleSpoilerText,
|
||||||
openLinkControl,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -380,6 +386,13 @@ const TextFormatter: FC<OwnProps> = ({
|
|||||||
onKeyDown={handleContainerKeyDown}
|
onKeyDown={handleContainerKeyDown}
|
||||||
>
|
>
|
||||||
<div className="TextFormatter-buttons">
|
<div className="TextFormatter-buttons">
|
||||||
|
<Button
|
||||||
|
color="translucent"
|
||||||
|
ariaLabel="Spoiler text"
|
||||||
|
onClick={handleSpoilerText}
|
||||||
|
>
|
||||||
|
<i className="icon-eye-closed" />
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
color="translucent"
|
color="translucent"
|
||||||
ariaLabel="Bold text"
|
ariaLabel="Bold text"
|
||||||
|
|||||||
@ -96,6 +96,10 @@ function parseMarkdown(html: string) {
|
|||||||
/(^|\s)(?!<code[^<]*|<\/)[~]{2}([^~\n]+)[~]{2}(?![^<]*<\/code>)(\s|$)/g,
|
/(^|\s)(?!<code[^<]*|<\/)[~]{2}([^~\n]+)[~]{2}(?![^<]*<\/code>)(\s|$)/g,
|
||||||
'$1<s>$2</s>$3',
|
'$1<s>$2</s>$3',
|
||||||
);
|
);
|
||||||
|
parsedHtml = parsedHtml.replace(
|
||||||
|
/(^|\s)(?!<code[^<]*|<\/)[|]{2}([^|\n]+)[|]{2}(?![^<]*<\/code>)(\s|$)/g,
|
||||||
|
`$1<span data-entity-type="${ApiMessageEntityTypes.Spoiler}">$2</span>$3`,
|
||||||
|
);
|
||||||
|
|
||||||
return parsedHtml;
|
return parsedHtml;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user