Composer: Fix extra div> text in message input (#2429)
This commit is contained in:
parent
d1824caa8a
commit
4c6a9216f6
@ -122,11 +122,12 @@ export default function useMentionTooltip(
|
|||||||
>${getUserFirstOrLastName(user)}</a>`;
|
>${getUserFirstOrLastName(user)}</a>`;
|
||||||
|
|
||||||
const containerEl = document.querySelector<HTMLDivElement>(inputSelector)!;
|
const containerEl = document.querySelector<HTMLDivElement>(inputSelector)!;
|
||||||
|
const fixedHtmlBeforeSelection = cleanWebkitNewLines(htmlBeforeSelection);
|
||||||
|
|
||||||
const atIndex = htmlBeforeSelection.lastIndexOf('@');
|
const atIndex = fixedHtmlBeforeSelection.lastIndexOf('@');
|
||||||
if (atIndex !== -1) {
|
if (atIndex !== -1) {
|
||||||
const newHtml = `${htmlBeforeSelection.substr(0, atIndex)}${insertedHtml} `;
|
const newHtml = `${fixedHtmlBeforeSelection.substr(0, atIndex)}${insertedHtml} `;
|
||||||
const htmlAfterSelection = containerEl.innerHTML.substring(htmlBeforeSelection.length);
|
const htmlAfterSelection = cleanWebkitNewLines(containerEl.innerHTML).substring(fixedHtmlBeforeSelection.length);
|
||||||
onUpdateHtml(`${newHtml}${htmlAfterSelection}`);
|
onUpdateHtml(`${newHtml}${htmlAfterSelection}`);
|
||||||
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
@ -151,6 +152,12 @@ function getUsernameFilter(html: string) {
|
|||||||
return username ? username[0].trim() : undefined;
|
return username ? username[0].trim() : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Webkit replaces the line break with the `<div><br /></div>` or `<div></div>` code.
|
||||||
|
// It is necessary to clean the html to a single form before processing.
|
||||||
|
function cleanWebkitNewLines(html: string) {
|
||||||
|
return html.replace(/<div>(<br>|<br\s?\/>)?<\/div>/gi, '<br>');
|
||||||
|
}
|
||||||
|
|
||||||
function canSuggestInlineBots(html: string) {
|
function canSuggestInlineBots(html: string) {
|
||||||
return html.startsWith('@');
|
return html.startsWith('@');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user