fix(mobile): support Hermes collection sorting
Reuses the focused compatibility approach from closed PR #3923 and covers the remaining hardware-keyboard reverse iteration. Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
9c65560b35
commit
32b749d07e
8 files changed
+72
-22
No files matched your search
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { copySorted } from "./Array.ts";
|
||||
|
||||
describe("array copies", () => {
|
||||
it("sorts a copy without mutating the source", () => {
|
||||
const source = [3, 1, 2];
|
||||
|
||||
expect(copySorted(source, (left: number, right: number) => left - right)).toEqual([1, 2, 3]);
|
||||
expect(source).toEqual([3, 1, 2]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
export function copySorted<T>(
|
||||
values: ReadonlyArray<T>,
|
||||
compareFn?: (left: T, right: T) => number,
|
||||
): T[] {
|
||||
return [...values].sort(compareFn);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
type ProviderOptionDescriptor,
|
||||
type ProviderOptionSelection,
|
||||
} from "@t3tools/contracts";
|
||||
import { copySorted } from "./Array.ts";
|
||||
|
||||
const DEFAULT_PROVIDER_DRIVER_KIND = ProviderDriverKind.make("codex");
|
||||
|
||||
@@ -80,12 +81,21 @@ export function getModelSelectionBooleanOptionValue(
|
||||
function canonicalModelSelectionOptions(
|
||||
modelSelection: ModelSelection,
|
||||
): ReadonlyArray<readonly [id: string, value: string | boolean]> {
|
||||
return (modelSelection.options ?? [])
|
||||
.map((selection) => [selection.id, selection.value] as const)
|
||||
.toSorted(([leftId, leftValue], [rightId, rightValue]) => {
|
||||
return copySorted(
|
||||
(modelSelection.options ?? []).map(
|
||||
(selection): readonly [id: string, value: string | boolean] => [
|
||||
selection.id,
|
||||
selection.value,
|
||||
],
|
||||
),
|
||||
(
|
||||
[leftId, leftValue]: readonly [id: string, value: string | boolean],
|
||||
[rightId, rightValue]: readonly [id: string, value: string | boolean],
|
||||
) => {
|
||||
const idOrder = leftId.localeCompare(rightId);
|
||||
return idOrder !== 0 ? idOrder : String(leftValue).localeCompare(String(rightValue));
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user