`, whose line endings are spaces. +const PARAGRAPH_END = + /^<\/?(?:p|div|details|summary|table|thead|tbody|tr|td|th|ul|ol|li|dl|dt|dd|h[1-6]|hr|pre|blockquote|section|article|address|aside|dialog|fieldset|figcaption|figure|footer|form|header|hgroup|main|menu|nav|search)(?=[\s/>]|$)/i; +const PARAGRAPH_START = /^
]|$)/i; + const ANCHOR_TAG = /^<\/?a[\s/>]/i; /** Replacements for the anchor tags still ahead, and how many emitted links are open. */ @@ -196,8 +201,14 @@ export function markdownHtmlContent( anchorMarkdown(tags.map((tag) => tag[0]).filter((tag) => ANCHOR_TAG.test(tag))); let result = ""; let end = 0; + let inParagraph = false; + const textTo = (to?: number) => { + const text = content.slice(end, to); + return inParagraph ? text.replace(/[ \t]*\r?\n[ \t]*/g, " ") : text; + }; for (const match of tags) { - const text = content.slice(end, match.index); + const text = textTo(match.index); + if (PARAGRAPH_END.test(match[0])) inParagraph = PARAGRAPH_START.test(match[0]); result += anchors.open > 0 ? escapeLinkLabel(text) : text; const replacement = htmlTagMarkdown(match[0], anchors, options); if (replacement === "[" && bangBefore(result, result.length)) @@ -208,7 +219,7 @@ export function markdownHtmlContent( : replacement; end = match.index + match[0].length; } - const text = content.slice(end); + const text = textTo(); return result + (anchors.open > 0 ? escapeLinkLabel(text) : text); } @@ -224,7 +235,7 @@ function htmlTagMarkdown( else if (replacement) anchors.open -= 1; return replacement; } - if (/^\none\ntwo\n
\n\nthree\nfour").trim()).toMatch( + /^one two\s+three\nfour$/, + ); + expect(markdownWithHtml("\n
\nlead\n")).toMatch(/one\ntwo/);
+ });
+
it("collects HTML and Markdown screenshots while leaving inline and fenced code literal", () => {
const markdown =
'```html\n \n `\nkept\n\n \none\ntwo\n three\nfour \none\ntwo\n three\nfour five ` in a link destination is no raw paragraph, and the ones after it stay Markdown.
+ expect(wordsHtml("[a](http://x/ )\nb\n\nc\nd", { breaks: true })).toContain(
+ ' c ` start tag's element, in order. */
+ readonly paragraphs: Element[];
}
/**
@@ -176,6 +178,7 @@ interface Tokenized {
function tokenize(html: string, offsetOf: (byte: number) => number): Tokenized {
const root: Root = { type: "root", children: [] };
const positioned: Element[] = [];
+ const paragraphs: Element[] = [];
const stack: Array ` Words writes for Markdown. */
+const rawParagraphs = new WeakSet ` in the source reaches the tag only where Words passes raw HTML on.
+ const marked = markdown.replace(/ )/gi, "$& data-raw-paragraph");
+ if (marked !== markdown && paragraphs.some(breaksLines)) {
+ const markedParagraphs = render(marked).paragraphs;
+ // The attribute can change how Words reads its line (a ` ` in a link destination stops
+ // being a link); then the paragraphs no longer pair up, and none are marked.
+ if (markedParagraphs.length === paragraphs.length) {
+ for (const [index, paragraph] of paragraphs.entries()) {
+ if (markedParagraphs[index]!.properties.dataRawParagraph !== undefined) {
+ rawParagraphs.add(paragraph);
+ }
+ }
+ }
+ }
+ if (!/data-sourcepos/i.test(markdown)) return root;
const generated = new Map
\n```\n\nUse `
` here.\n\n
\n\n\n\n
';
diff --git a/apps/server/src/auth/RpcAuthorization.ts b/apps/server/src/auth/RpcAuthorization.ts
index cb16baa0bd..dec70125e9 100644
--- a/apps/server/src/auth/RpcAuthorization.ts
+++ b/apps/server/src/auth/RpcAuthorization.ts
@@ -9,7 +9,7 @@ import {
AuthAccessWriteScope,
ServerSettingsPatch,
ProviderInstanceMutation,
- requiredScopesForServerSettingsPatch,
+ requiredScopesForServerSettingsUpdate,
requiredScopesForProjectMutation,
ProjectMutation,
SecretRequestAnswerInput,
@@ -290,15 +290,6 @@ const SettingsUpdate = Schema.Struct({
// Middleware receives the payload already decoded, so it is checked against the decoded shape.
const decodeSettingsUpdate = Schema.decodeUnknownSync(Schema.toType(SettingsUpdate));
-const requiredScopesForSettingsUpdate = (payload: unknown) => {
- const input = decodeSettingsUpdate(payload);
- const scopes = requiredScopesForServerSettingsPatch(input.patch);
- if (input.providerInstanceMutation === undefined) return scopes;
- return Object.values(input.patch).every((value) => value === undefined)
- ? [AuthProvidersManageScope]
- : [...new Set([...scopes, AuthProvidersManageScope])];
-};
-
const decodeProjectMutation = Schema.decodeUnknownSync(ProjectMutation);
const decodeAssetCreateUrlInput = Schema.decodeUnknownSync(AssetCreateUrlInput);
const decodeSecretRequestAnswer = Schema.decodeUnknownSync(SecretRequestAnswerInput);
@@ -347,7 +338,9 @@ const requiredScopesForRpcCall = (
: AuthOrchestrationReadScope,
];
}
- if (method === WS_METHODS.serverUpdateSettings) return requiredScopesForSettingsUpdate(payload);
+ if (method === WS_METHODS.serverUpdateSettings) {
+ return requiredScopesForServerSettingsUpdate(decodeSettingsUpdate(payload));
+ }
// These send the credential they are given to a URL the caller names, as a saved setting would.
if (
(method === WS_METHODS.deviceSimlockIdentity ||
diff --git a/apps/web/src/browser/ServerBrowserSurface.tsx b/apps/web/src/browser/ServerBrowserSurface.tsx
index 298d76d707..68f04874ee 100644
--- a/apps/web/src/browser/ServerBrowserSurface.tsx
+++ b/apps/web/src/browser/ServerBrowserSurface.tsx
@@ -48,6 +48,7 @@ import { m } from "~/i18n/messages";
import { cn } from "~/lib/utils";
import { refreshPreviewStreamAccess, usePreviewStreamAccess } from "~/state/previewStream";
import { observeResize } from "~/lib/observeResize";
+import { isImeKeyDown } from "../lib/imeKeyDown";
export interface ServerBrowserHandle {
readonly navigate: (url: string) => void;
@@ -819,8 +820,7 @@ export function ServerBrowserSurface(props: {
if (controlRef.current?.controller !== "you") return;
keySentRef.current = false;
if (
- event.nativeEvent.isComposing ||
- event.keyCode === 229 ||
+ isImeKeyDown(event.nativeEvent) ||
event.key === "Process" ||
event.key === "Unidentified"
) {
diff --git a/apps/web/src/components/AddProjectToMachineDialog.tsx b/apps/web/src/components/AddProjectToMachineDialog.tsx
index 7ffba4e6dc..d735b68edb 100644
--- a/apps/web/src/components/AddProjectToMachineDialog.tsx
+++ b/apps/web/src/components/AddProjectToMachineDialog.tsx
@@ -61,6 +61,7 @@ import { Label } from "./ui/label";
import { MiddleTruncate } from "./ui/middle-truncate";
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "./ui/select";
import { Toggle, ToggleGroup } from "./ui/toggle-group";
+import { clearSearchOnEscape } from "./settings/searchFieldEscape";
interface AddProjectToMachineRequest {
readonly projectRef: ScopedProjectRef;
@@ -405,7 +406,8 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe
{canSearchFiles && (allIgnoredFiles.data?.truncated || fileQuery.length > 0) ? (
{
if (event.key === "Enter") event.preventDefault();
+ clearSearchOnEscape(event, fileQuery, () => setFileQuery(""));
}}
spellCheck={false}
autoComplete="off"
diff --git a/apps/web/src/components/AppRouteModal.tsx b/apps/web/src/components/AppRouteModal.tsx
index 01cee50dfb..810323cbd3 100644
--- a/apps/web/src/components/AppRouteModal.tsx
+++ b/apps/web/src/components/AppRouteModal.tsx
@@ -151,8 +151,14 @@ export function AppRouteModal({ label, children }: { label: string; children: Re
open={shown}
// Portaled layers outside this tree (toasts, confirm dialogs) are not backdrop presses.
disablePointerDismissal
- onOpenChange={(nextOpen) => {
+ onOpenChange={(nextOpen, details) => {
if (nextOpen) return;
+ // A control inside used this Escape. A drag hears it at the document, so let it through.
+ if (details.reason === "escape-key" && details.event.defaultPrevented) {
+ details.cancel();
+ details.allowPropagation();
+ return;
+ }
// Closing unmounts a focused field without a blur, so commit-on-blur rows would
// drop what was typed. Blur first so they commit.
blurFocusedWithin(popupRef.current);
diff --git a/apps/web/src/components/AppSidebarLayout.browser.test.tsx b/apps/web/src/components/AppSidebarLayout.browser.test.tsx
index 67ca0dc04c..5e38e2760f 100644
--- a/apps/web/src/components/AppSidebarLayout.browser.test.tsx
+++ b/apps/web/src/components/AppSidebarLayout.browser.test.tsx
@@ -9,6 +9,7 @@ vi.mock(import("../state/server"), async (original) => {
const { compileResolvedKeybindingsConfig } = await import("@onicode/shared/keybindings");
const keybindings = compileResolvedKeybindingsConfig([
{ key: "mod+b", command: "sidebar.toggle", when: "!terminalFocus" },
+ { key: "f6", command: "workspace.focusNext" },
]);
return { ...actual, primaryServerKeybindingsAtom: Atom.make(keybindings) };
});
@@ -69,3 +70,29 @@ describe("pull requests Escape", () => {
await vi.waitFor(() => expect(screen.router?.state.location.pathname).toBe("/"));
});
});
+
+describe("workspace focus F6", () => {
+ it("leaves a keydown an IME composition owns to the input", async () => {
+ await using screen = await render(
+
\n\n
',
);
+ // A bare raw paragraph looks like a Markdown one in Words' HTML.
+ expect(
+ wordsHtml("`<p>
\nkept
\nsix
\nd",
+ "",
+ ];
+ expect(
+ starts(`${stopped.join("\n")}1. ${"z".repeat(LARGE_MARKDOWN_CHUNK_MAX_CHARS)}\n\nafter\n`),
+ ).toEqual(["