chore: merge dev into v2 (#35591)
Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Jay <air@live.ca> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com>
This commit is contained in:
parent
f87998f37f
commit
9e0d3976e1
332 changed files with 24739 additions and 4586 deletions
116
packages/app/src/utils/search-keydown.ts
Normal file
116
packages/app/src/utils/search-keydown.ts
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
const editableSelector = "input, textarea, select, [contenteditable=''], [contenteditable='true']"
|
||||
|
||||
export function handleDocumentSearchKeydown(
|
||||
input: HTMLInputElement | undefined,
|
||||
event: KeyboardEvent,
|
||||
inputValue: string,
|
||||
setInputValue: (value: string) => void,
|
||||
) {
|
||||
if (!input) return false
|
||||
if (event.defaultPrevented || event.isComposing) return false
|
||||
if (event.target === input) return false
|
||||
if (event.target instanceof Element && event.target.closest(editableSelector)) return false
|
||||
|
||||
const action = searchKeyAction(event)
|
||||
if (!action) return false
|
||||
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
input.focus()
|
||||
|
||||
const start = input.selectionStart ?? inputValue.length
|
||||
const end = input.selectionEnd ?? inputValue.length
|
||||
|
||||
if (action.type === "selectAll") {
|
||||
input.setSelectionRange(0, inputValue.length)
|
||||
return true
|
||||
}
|
||||
|
||||
if (action.type === "move") {
|
||||
moveSelection(input, inputValue, action.delta, event.shiftKey)
|
||||
return true
|
||||
}
|
||||
|
||||
if (action.type === "home") {
|
||||
setBoundarySelection(input, start, 0, event.shiftKey)
|
||||
return true
|
||||
}
|
||||
|
||||
if (action.type === "end") {
|
||||
setBoundarySelection(input, start, inputValue.length, event.shiftKey)
|
||||
return true
|
||||
}
|
||||
|
||||
if (action.type === "deleteBackward") {
|
||||
if (start !== end)
|
||||
return updateValue(input, inputValue.slice(0, start) + inputValue.slice(end), start, setInputValue)
|
||||
if (start === 0) return true
|
||||
return updateValue(input, inputValue.slice(0, start - 1) + inputValue.slice(end), start - 1, setInputValue)
|
||||
}
|
||||
|
||||
if (action.type === "deleteForward") {
|
||||
if (start !== end)
|
||||
return updateValue(input, inputValue.slice(0, start) + inputValue.slice(end), start, setInputValue)
|
||||
if (end === inputValue.length) return true
|
||||
return updateValue(input, inputValue.slice(0, start) + inputValue.slice(end + 1), start, setInputValue)
|
||||
}
|
||||
|
||||
return updateValue(
|
||||
input,
|
||||
inputValue.slice(0, start) + action.value + inputValue.slice(end),
|
||||
start + action.value.length,
|
||||
setInputValue,
|
||||
)
|
||||
}
|
||||
|
||||
function searchKeyAction(event: KeyboardEvent) {
|
||||
if ((event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === "a") {
|
||||
return { type: "selectAll" } as const
|
||||
}
|
||||
if (event.ctrlKey || event.metaKey || event.altKey) return undefined
|
||||
if (event.key.length === 1) return { type: "insert", value: event.key } as const
|
||||
if (event.key === "Backspace") return { type: "deleteBackward" } as const
|
||||
if (event.key === "Delete") return { type: "deleteForward" } as const
|
||||
if (event.key === "ArrowLeft") return { type: "move", delta: -1 } as const
|
||||
if (event.key === "ArrowRight") return { type: "move", delta: 1 } as const
|
||||
if (event.key === "Home") return { type: "home" } as const
|
||||
if (event.key === "End") return { type: "end" } as const
|
||||
return undefined
|
||||
}
|
||||
|
||||
function moveSelection(input: HTMLInputElement, inputValue: string, delta: -1 | 1, extend: boolean) {
|
||||
const start = input.selectionStart ?? inputValue.length
|
||||
const end = input.selectionEnd ?? inputValue.length
|
||||
if (!extend && start !== end) {
|
||||
const caret = delta < 0 ? start : end
|
||||
input.setSelectionRange(caret, caret)
|
||||
return
|
||||
}
|
||||
|
||||
if (!extend) {
|
||||
const caret = Math.max(0, Math.min(inputValue.length, start + delta))
|
||||
input.setSelectionRange(caret, caret)
|
||||
return
|
||||
}
|
||||
|
||||
const backward = input.selectionDirection === "backward"
|
||||
const anchor = backward ? end : start
|
||||
const focus = backward ? start : end
|
||||
const next = Math.max(0, Math.min(inputValue.length, focus + delta))
|
||||
input.setSelectionRange(Math.min(anchor, next), Math.max(anchor, next), next < anchor ? "backward" : "forward")
|
||||
}
|
||||
|
||||
function setBoundarySelection(input: HTMLInputElement, anchor: number, focus: number, extend: boolean) {
|
||||
if (!extend) {
|
||||
input.setSelectionRange(focus, focus)
|
||||
return
|
||||
}
|
||||
input.setSelectionRange(Math.min(anchor, focus), Math.max(anchor, focus), focus < anchor ? "backward" : "forward")
|
||||
}
|
||||
|
||||
function updateValue(input: HTMLInputElement, value: string, caret: number, setInputValue: (value: string) => void) {
|
||||
input.value = value
|
||||
setInputValue(value)
|
||||
input.setSelectionRange(caret, caret)
|
||||
return true
|
||||
}
|
||||
|
|
@ -42,6 +42,20 @@ function unwrapNamedError(error: unknown): unknown {
|
|||
return error
|
||||
}
|
||||
|
||||
// Client-synthesized session not-found errors share one constructor and
|
||||
// predicate so the message contract cannot drift between the sync store
|
||||
// (server-session.ts), the route lineage (session-lineage.ts), and the
|
||||
// not-found fallback matching (session.tsx).
|
||||
const sessionNotFoundMessage = (sessionID: string) => `Session not found: ${sessionID}`
|
||||
|
||||
export function sessionNotFoundError(sessionID: string) {
|
||||
return new Error(sessionNotFoundMessage(sessionID))
|
||||
}
|
||||
|
||||
export function isLocalSessionNotFoundError(error: unknown, sessionID: string) {
|
||||
return error instanceof Error && error.message === sessionNotFoundMessage(sessionID)
|
||||
}
|
||||
|
||||
export function isSessionNotFoundError(error: unknown, sessionID: string) {
|
||||
const unwrapped = unwrapNamedError(error)
|
||||
if (typeof unwrapped !== "object" || unwrapped === null) return false
|
||||
|
|
|
|||
|
|
@ -1,13 +1,6 @@
|
|||
import { describe, expect, test } from "bun:test"
|
||||
import { ServerConnection } from "@/context/server"
|
||||
import {
|
||||
legacySessionHref,
|
||||
legacySessionServer,
|
||||
requireServerKey,
|
||||
rootSession,
|
||||
selectSessionLineage,
|
||||
sessionHref,
|
||||
} from "./session-route"
|
||||
import { legacySessionHref, legacySessionServer, requireServerKey, rootSession, sessionHref } from "./session-route"
|
||||
|
||||
describe("session routes", () => {
|
||||
test("uses the unique persisted server for a legacy session route", () => {
|
||||
|
|
@ -75,10 +68,4 @@ describe("session routes", () => {
|
|||
|
||||
expect(rootSession(sessions.child, async (id) => sessions[id]!)).rejects.toThrow("Session parent cycle: child")
|
||||
})
|
||||
|
||||
test("ignores a resolved lineage retained from the previous route", () => {
|
||||
const previous = { session: { id: "A" }, root: { id: "A" } }
|
||||
|
||||
expect(selectSessionLineage("B", undefined, previous)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -27,15 +27,6 @@ export function legacySessionServer(
|
|||
|
||||
type SessionParent = { id: string; parentID?: string }
|
||||
|
||||
export function selectSessionLineage<T extends { session: { id: string } }>(
|
||||
sessionID: string,
|
||||
cached: T | undefined,
|
||||
resolved: T | undefined,
|
||||
) {
|
||||
if (cached?.session.id === sessionID) return cached
|
||||
if (resolved?.session.id === sessionID) return resolved
|
||||
}
|
||||
|
||||
export async function rootSession<T extends SessionParent>(session: T, get: (sessionID: string) => Promise<T>) {
|
||||
const seen = new Set([session.id])
|
||||
let current = session
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue