getStringFromNode: Add parent/nextSibling for fewer newlines
This commit is contained in:
parent
b6445a6af0
commit
3f399b1329
3 changed files with 30 additions and 10 deletions
|
@ -741,8 +741,14 @@ export class Message extends React.PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private canRenderStickerLikeEmoji(): boolean {
|
private canRenderStickerLikeEmoji(): boolean {
|
||||||
const { text, quote, storyReplyContext, attachments, previews } =
|
const {
|
||||||
this.props;
|
attachments,
|
||||||
|
bodyRanges,
|
||||||
|
previews,
|
||||||
|
quote,
|
||||||
|
storyReplyContext,
|
||||||
|
text,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
return Boolean(
|
return Boolean(
|
||||||
text &&
|
text &&
|
||||||
|
@ -751,6 +757,7 @@ export class Message extends React.PureComponent<Props, State> {
|
||||||
!quote &&
|
!quote &&
|
||||||
!storyReplyContext &&
|
!storyReplyContext &&
|
||||||
(!attachments || !attachments.length) &&
|
(!attachments || !attachments.length) &&
|
||||||
|
(!bodyRanges || !bodyRanges.length) &&
|
||||||
(!previews || !previews.length)
|
(!previews || !previews.length)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,8 @@ export function MessageBodyReadMore({
|
||||||
BUFFER
|
BUFFER
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const disableJumbomoji = bodyRanges?.length ? true : undefined;
|
||||||
|
|
||||||
const onIncreaseTextLength = hasReadMore
|
const onIncreaseTextLength = hasReadMore
|
||||||
? () => {
|
? () => {
|
||||||
messageExpanded(id, maxLength + INCREMENT_COUNT);
|
messageExpanded(id, maxLength + INCREMENT_COUNT);
|
||||||
|
@ -68,6 +70,7 @@ export function MessageBodyReadMore({
|
||||||
<MessageBody
|
<MessageBody
|
||||||
bodyRanges={bodyRanges}
|
bodyRanges={bodyRanges}
|
||||||
direction={direction}
|
direction={direction}
|
||||||
|
disableJumbomoji={disableJumbomoji}
|
||||||
disableLinks={disableLinks}
|
disableLinks={disableLinks}
|
||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
isSpoilerExpanded={isSpoilerExpanded}
|
isSpoilerExpanded={isSpoilerExpanded}
|
||||||
|
|
|
@ -56,7 +56,11 @@ export function createEventHandler({
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStringFromNode(node: Node): string {
|
function getStringFromNode(
|
||||||
|
node: Node,
|
||||||
|
parent?: Node,
|
||||||
|
nextSibling?: Node
|
||||||
|
): string {
|
||||||
if (node.nodeType === Node.TEXT_NODE) {
|
if (node.nodeType === Node.TEXT_NODE) {
|
||||||
if (node.textContent === QUILL_EMBED_GUARD) {
|
if (node.textContent === QUILL_EMBED_GUARD) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -75,20 +79,26 @@ function getStringFromNode(node: Node): string {
|
||||||
) {
|
) {
|
||||||
return element.ariaLabel || '';
|
return element.ariaLabel || '';
|
||||||
}
|
}
|
||||||
if (element.nodeName === 'BR') {
|
if (nextSibling && element.nodeName === 'BR') {
|
||||||
return '\n';
|
return '\n';
|
||||||
}
|
}
|
||||||
if (element.childNodes.length === 0) {
|
const childCount = element.childNodes.length;
|
||||||
|
if (childCount === 0) {
|
||||||
return element.textContent || '';
|
return element.textContent || '';
|
||||||
}
|
}
|
||||||
let result = '';
|
let result = '';
|
||||||
for (const child of element.childNodes) {
|
for (let i = 0; i < childCount; i += 1) {
|
||||||
result += getStringFromNode(child);
|
const child = element.childNodes[i];
|
||||||
|
const nextChild = element.childNodes[i + 1];
|
||||||
|
result += getStringFromNode(child, node, nextChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
element.nodeName === 'P' ||
|
parent &&
|
||||||
element.nodeName === 'DIV' ||
|
parent.childNodes.length > 1 &&
|
||||||
element.nodeName === 'TIME'
|
(element.nodeName === 'P' ||
|
||||||
|
element.nodeName === 'DIV' ||
|
||||||
|
element.nodeName === 'TIME')
|
||||||
) {
|
) {
|
||||||
if (result.length > 0 && !result.endsWith('\n\n')) {
|
if (result.length > 0 && !result.endsWith('\n\n')) {
|
||||||
result += '\n';
|
result += '\n';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue