mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix zindex to account for group boundaries (#2065)
This commit is contained in:
parent
ea020f2c50
commit
d07099aadd
10 changed files with 1287 additions and 416 deletions
36
src/utils.ts
36
src/utils.ts
|
@ -254,3 +254,39 @@ export const muteFSAbortError = (error?: Error) => {
|
|||
}
|
||||
throw error;
|
||||
};
|
||||
|
||||
export const findIndex = <T>(
|
||||
array: readonly T[],
|
||||
cb: (element: T, index: number, array: readonly T[]) => boolean,
|
||||
fromIndex: number = 0,
|
||||
) => {
|
||||
if (fromIndex < 0) {
|
||||
fromIndex = array.length + fromIndex;
|
||||
}
|
||||
fromIndex = Math.min(array.length, Math.max(fromIndex, 0));
|
||||
let i = fromIndex - 1;
|
||||
while (++i < array.length) {
|
||||
if (cb(array[i], i, array)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
export const findLastIndex = <T>(
|
||||
array: readonly T[],
|
||||
cb: (element: T, index: number, array: readonly T[]) => boolean,
|
||||
fromIndex: number = array.length - 1,
|
||||
) => {
|
||||
if (fromIndex < 0) {
|
||||
fromIndex = array.length + fromIndex;
|
||||
}
|
||||
fromIndex = Math.min(array.length - 1, Math.max(fromIndex, 0));
|
||||
let i = fromIndex + 1;
|
||||
while (--i > -1) {
|
||||
if (cb(array[i], i, array)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue