Fix mention options positioning

This commit is contained in:
Bojan Mojsilovic 2024-01-08 13:28:46 +01:00
parent 0caa0f29bf
commit 2783819eeb
2 changed files with 17 additions and 1 deletions

View File

@ -280,6 +280,12 @@ const EditBox: Component<{
if (!isMentioning() && e.key === '@') {
mentionCursorPosition = getCaretCoordinates(textArea, textArea.selectionStart);
// Ignore if `@` is a part of a word
if (textArea.selectionStart > 0 && ![' ', '\r\n', '\r', '\n'].includes(textArea.value[textArea.selectionStart-1])) {
return false;
}
setPreQuery('');
setQuery('');
setMentioning(true);

View File

@ -498,6 +498,12 @@ const Messages: Component = () => {
if (!isMentioning() && e.key === '@') {
mentionCursorPosition = getCaretCoordinates(newMessageInput, newMessageInput.selectionStart);
// Ignore if `@` is a part of a word
if (newMessageInput.selectionStart > 0 && ![' ', '\r\n', '\r', '\n'].includes(newMessageInput.value[newMessageInput.selectionStart-1])) {
return false;
}
setPreQuery('');
setQuery('');
setMentioning(true);
@ -733,9 +739,13 @@ const Messages: Component = () => {
const taRect = newMessageInput.getBoundingClientRect();
let newBottom = taRect.height - mentionCursorPosition.top;
let newBottom = taRect.height - mentionCursorPosition.top + 32;
let newLeft = mentionCursorPosition.left;
if (newLeft + mentionOptions.getBoundingClientRect().width > 628) {
newLeft = 628 - mentionOptions.getBoundingClientRect().width;
}
mentionOptions.style.bottom = `${newBottom}px`;
mentionOptions.style.left = `${newLeft}px`;
};