diff --git a/ts/editor-toolbar/identifiable.ts b/ts/editor-toolbar/identifiable.ts index 154895bfc..334222022 100644 --- a/ts/editor-toolbar/identifiable.ts +++ b/ts/editor-toolbar/identifiable.ts @@ -8,11 +8,19 @@ function normalize( values: T[], idOrIndex: string | number ): number { + let normalizedIndex: number; + if (typeof idOrIndex === "string") { - return values.findIndex((value) => value.id === idOrIndex); - } else { - return idOrIndex >= values.length ? -1 : idOrIndex; + normalizedIndex = values.findIndex((value) => value.id === idOrIndex); } + else if (idOrIndex < 0) { + normalizedIndex = values.length + idOrIndex; + } + else { + normalizedIndex = idOrIndex; + } + + return normalizedIndex >= values.length ? -1 : normalizedIndex; } export function search(