Text Formatter: Fix position in scrollable input (#2362)
This commit is contained in:
parent
d03755ded0
commit
bb34e6ae5a
@ -248,19 +248,19 @@ const MessageInput: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
const selectionRange = window.getSelection()!.getRangeAt(0);
|
const selectionRange = window.getSelection()!.getRangeAt(0);
|
||||||
const selectionRect = selectionRange.getBoundingClientRect();
|
const selectionRect = selectionRange.getBoundingClientRect();
|
||||||
const inputRect = inputRef.current!.getBoundingClientRect();
|
const scrollerRect = inputRef.current!.closest<HTMLDivElement>(`.${SCROLLER_CLASS}`)!.getBoundingClientRect();
|
||||||
|
|
||||||
let x = (selectionRect.left + selectionRect.width / 2) - inputRect.left;
|
let x = (selectionRect.left + selectionRect.width / 2) - scrollerRect.left;
|
||||||
|
|
||||||
if (x < TEXT_FORMATTER_SAFE_AREA_PX) {
|
if (x < TEXT_FORMATTER_SAFE_AREA_PX) {
|
||||||
x = TEXT_FORMATTER_SAFE_AREA_PX;
|
x = TEXT_FORMATTER_SAFE_AREA_PX;
|
||||||
} else if (x > inputRect.width - TEXT_FORMATTER_SAFE_AREA_PX) {
|
} else if (x > scrollerRect.width - TEXT_FORMATTER_SAFE_AREA_PX) {
|
||||||
x = inputRect.width - TEXT_FORMATTER_SAFE_AREA_PX;
|
x = scrollerRect.width - TEXT_FORMATTER_SAFE_AREA_PX;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTextFormatterAnchorPosition({
|
setTextFormatterAnchorPosition({
|
||||||
x,
|
x,
|
||||||
y: selectionRect.top - inputRect.top,
|
y: selectionRect.top - scrollerRect.top,
|
||||||
});
|
});
|
||||||
|
|
||||||
setSelectedRange(selectionRange);
|
setSelectedRange(selectionRange);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user