/** Preserve the user's result choice while progressive indexing hides it briefly. */ export class ResultSelection { private scope: string | null = null; private intendedPath: string | null = null; begin(scope: string) { if (scope !== this.scope) { this.scope = scope; this.intendedPath = null; } } choose(path: string) { this.intendedPath = path; } resolve(paths: readonly string[]): number { if (!paths.length) return -1; if (this.intendedPath === null) this.intendedPath = paths[0]; const intended = paths.indexOf(this.intendedPath); // A temporary fallback is presentation, not a new user choice. return intended >= 0 ? intended : 0; } }