mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: fixed search input cursor position issue
This commit is contained in:
parent
b2a6a87b10
commit
95cce9a553
1 changed files with 17 additions and 0 deletions
|
@ -137,6 +137,22 @@ export const SearchMenu = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fixInputCursorPosition = () => {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const searchInput = searchInputRef.current;
|
||||||
|
const isFocus = document.activeElement === searchInput;
|
||||||
|
// if input is not focus and input instance is not exist return
|
||||||
|
if (!searchInput || !isFocus) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const cursorPosition = searchInput.selectionStart;
|
||||||
|
const textLength = searchInput.value.length!;
|
||||||
|
if (cursorPosition !== textLength) {
|
||||||
|
searchInput.setSelectionRange(textLength, textLength);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAppState((state) => {
|
setAppState((state) => {
|
||||||
return {
|
return {
|
||||||
|
@ -282,6 +298,7 @@ export const SearchMenu = () => {
|
||||||
if (event.key === KEYS.ARROW_UP) {
|
if (event.key === KEYS.ARROW_UP) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
stableState.goToPreviousItem();
|
stableState.goToPreviousItem();
|
||||||
|
fixInputCursorPosition();
|
||||||
} else if (event.key === KEYS.ARROW_DOWN) {
|
} else if (event.key === KEYS.ARROW_DOWN) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
stableState.goToNextItem();
|
stableState.goToNextItem();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue