Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): restore the composer inset for text docs (PRD-8510) (#4075)
serafin-garciafe4eab9021d0
diff --git a/.changeset/text-doc-composer-inset.md b/.changeset/text-doc-composer-inset.mdnew file mode 100644index 000000000..e0363b63c--- /dev/null+++ b/.changeset/text-doc-composer-inset.md@@ -0,0 +1,11 @@+---+"@inkeep/open-knowledge": patch+---++The Ask AI composer no longer covers the last lines of a code file.++Opening a `.ts`, `.json`, `.txt`, or any other editable non-markdown file put its final lines underneath the floating composer card, and no amount of scrolling brought them clear. Markdown files were unaffected, in both the visual editor and source mode, so the gap only showed up in code.++Every editor surface reserves the composer's height at the bottom of the document, and a shared rule grants that space. A later rule zeroes the padding on every CodeMirror surface, and each full-page CodeMirror editor is expected to restore it. Markdown source mode did. The code editor was added without one, so it kept the reset and reserved nothing.++The space is now reserved for code files too. It collapses to nothing when the composer is closed, so a file with no composer open still uses the full height of the window. Typing at the very end of a long code file does not scroll the caret clear on its own yet, the way it does in the visual editor, but the last lines can now be scrolled to.diff --git a/packages/app/package.json b/packages/app/package.jsonindex 9c93020fa..709ae3e8e 100644--- a/packages/app/package.json+++ b/packages/app/package.json@@ -29,7 +29,7 @@"measure:stress": "bash scripts/measure-stress.sh","measure:sweep": "bash scripts/measure-sweep.sh","perf:compare": "bash scripts/perf-compare.sh",- "test:e2e": "playwright test tests/stress/ux-interactions.e2e.ts tests/stress/file-tree-create.e2e.ts tests/stress/file-tree-drag-to-root.e2e.ts tests/stress/file-tree-deselect-to-root.e2e.ts tests/stress/file-tree-collapse-spaced-folder.e2e.ts tests/stress/sidebar-file-list-fills.e2e.ts tests/stress/file-tree-sticky-collapse.e2e.ts tests/stress/file-tree-fractional-zoom.e2e.ts tests/stress/create-then-rename-editable.e2e.ts tests/stress/find-replace.e2e.ts tests/stress/editor-tabs.e2e.ts tests/stress/crdt-stress.e2e.ts tests/stress/slash-command.e2e.ts tests/stress/paste-fidelity.e2e.ts tests/stress/fr-7a-disconnect-source-mode.e2e.ts tests/stress/docs-open.e2e.ts tests/stress/frozen-table-headers.e2e.ts tests/stress/asset-embed.e2e.ts tests/stress/asset-embed-advanced.e2e.ts tests/stress/asset-click-dispatch.e2e.ts tests/stress/handoff.e2e.ts tests/stress/multi-agent-presence.e2e.ts tests/stress/editor-mode-persistence.e2e.ts tests/stress/lint-config-toggle.e2e.ts tests/stress/plugin-enable-notice.e2e.ts tests/stress/schema-edit-fields-view.e2e.ts tests/stress/sidebar-search-pill.e2e.ts tests/stress/navigation-history.e2e.ts tests/stress/command-palette-semantic.e2e.ts tests/stress/agent-activity-panel.e2e.ts tests/stress/drop-pipeline-auto-open.e2e.ts tests/stress/command-palette-flicker.e2e.ts tests/stress/cm6-list-hanging-indent.e2e.ts tests/stress/ng7-rapid-nav-coherence.e2e.ts tests/stress/reveal-on-activate.e2e.ts tests/stress/selection-indicator.e2e.ts tests/stress/new-file-cross-doc-bleed.e2e.ts tests/stress/new-item-shortcut-fast-path.e2e.ts tests/stress/editor-mode-flip-cross-doc-bleed.e2e.ts tests/stress/editor-area-viewport-resize.e2e.ts tests/stress/qa-sidebar-responsive.e2e.ts tests/stress/prd-6955-reassertion-repro.e2e.ts tests/stress/prd-6955-reassertion-wedge.e2e.ts tests/stress/prd-6914-repro.e2e.ts tests/stress/showall-lazy-tree.e2e.ts tests/stress/tabs-component-strip.e2e.ts tests/stress/source-find-scroll.e2e.ts tests/stress/harness-app-warmth.e2e.ts tests/stress/qa-canary-authoring-both-modes.e2e.ts tests/stress/qa-canary-live-typing.e2e.ts tests/stress/keystroke-cadence-danger-space.e2e.ts tests/stress/jsx-unregistered-backspace-delete.e2e.ts tests/stress/jsx-unregistered-ime-concurrent.e2e.ts tests/stress/jsx-backspace-delete.e2e.ts tests/stress/link-authoring-bytes.e2e.ts tests/stress/link-authoring-apex.e2e.ts tests/stress/command-palette-parity.e2e.ts tests/stress/settings-search.e2e.ts tests/stress/okf-generated-index-settings.e2e.ts tests/stress/okf-recommended-skill-install.e2e.ts tests/stress/chip-popover-positioning.e2e.ts tests/stress/docs-open-scroll-restore.e2e.ts tests/stress/file-tree-decoration-chip-strip-repro.e2e.ts tests/stress/grip-click-nodeselect.e2e.ts tests/stress/jsx-halo-semantics.e2e.ts tests/stress/jsx-image-body-click.e2e.ts tests/stress/jsx-prop-panel-placeholder.e2e.ts tests/stress/jsx-range-encompass-halo.e2e.ts tests/stress/jsx-wildcard-convert.e2e.ts tests/stress/markdown-lint.e2e.ts tests/stress/frontmatter-schema-badge.e2e.ts tests/stress/frontmatter-glob-picker.e2e.ts tests/stress/unified-problems.e2e.ts tests/stress/mid-type-recovery.e2e.ts tests/stress/observer-a-multi-client.e2e.ts tests/stress/outline-toolbar-occlusion.e2e.ts tests/stress/selection-surface-pane-clip.e2e.ts tests/stress/quiet-tree-hidden-doc.e2e.ts tests/stress/raw-mdx-fallback-onblur-upgrade.e2e.ts tests/stress/rename-noext-probe.e2e.ts tests/stress/show-ok-folders.e2e.ts tests/stress/source-polish.e2e.ts tests/stress/warm-skeleton-scroll-restore.e2e.ts tests/stress/props-toggle-scroll-preserve.e2e.ts tests/stress/yjs-no-dual-import.e2e.ts tests/stress/graph-panel-surfaces.e2e.ts tests/stress/asset-embed-real-fidelity.e2e.ts tests/stress/image-invalid-placeholder.e2e.ts tests/stress/local-target-audit.e2e.ts tests/stress/rename-content-preservation.e2e.ts tests/stress/rename-consolidation.e2e.ts tests/stress/outline-active-heading.e2e.ts tests/stress/outline-navigation.e2e.ts tests/stress/prd-7627-default-swatch.e2e.ts tests/stress/clipboard-dollar-math-source-fallback.e2e.ts tests/stress/source-mode-undo-keymap.e2e.ts tests/stress/source-undo-mode-flip.e2e.ts tests/stress/timeline-recovered-restore.e2e.ts tests/stress/blank-line-preservation.e2e.ts tests/stress/landing-helpers.e2e.ts tests/stress/agent-follow-scroll.e2e.ts tests/stress/mode-switch-landing.e2e.ts tests/stress/mode-switch-ordinal-divergence.e2e.ts tests/stress/comment-annotation-visibility.e2e.ts tests/stress/comment-opens-in-panel.e2e.ts tests/stress/qa-miles-edge-blanks.e2e.ts tests/stress/prop-upload.e2e.ts tests/stress/slash-command-auto-open.e2e.ts tests/stress/clipboard-relative-url-source-fallback.e2e.ts tests/stress/editor-split-view.e2e.ts tests/stress/language-load-failure.e2e.ts tests/stress/language-first-paint.e2e.ts tests/stress/user-text-direction.e2e.ts tests/stress/pseudolocale.e2e.ts tests/stress/language-picker.e2e.ts tests/stress/zh-hans-coverage-sweep.e2e.ts tests/stress/preview-tab-promotion.e2e.ts tests/stress/cv-paint-lock-click.e2e.ts tests/stress/cv-auto-paint-lock-click.e2e.ts tests/stress/history-traversal-preview-tab.e2e.ts tests/stress/tab-close-scroll-restore.e2e.ts tests/stress/skills-sidebar-open.e2e.ts tests/stress/trailing-affordance.e2e.ts",+ "test:e2e": "playwright test tests/stress/ux-interactions.e2e.ts tests/stress/file-tree-create.e2e.ts tests/stress/file-tree-drag-to-root.e2e.ts tests/stress/file-tree-deselect-to-root.e2e.ts tests/stress/file-tree-collapse-spaced-folder.e2e.ts tests/stress/sidebar-file-list-fills.e2e.ts tests/stress/file-tree-sticky-collapse.e2e.ts tests/stress/file-tree-fractional-zoom.e2e.ts tests/stress/create-then-rename-editable.e2e.ts tests/stress/find-replace.e2e.ts tests/stress/editor-tabs.e2e.ts tests/stress/crdt-stress.e2e.ts tests/stress/slash-command.e2e.ts tests/stress/paste-fidelity.e2e.ts tests/stress/fr-7a-disconnect-source-mode.e2e.ts tests/stress/docs-open.e2e.ts tests/stress/frozen-table-headers.e2e.ts tests/stress/asset-embed.e2e.ts tests/stress/asset-embed-advanced.e2e.ts tests/stress/asset-click-dispatch.e2e.ts tests/stress/handoff.e2e.ts tests/stress/multi-agent-presence.e2e.ts tests/stress/editor-mode-persistence.e2e.ts tests/stress/lint-config-toggle.e2e.ts tests/stress/plugin-enable-notice.e2e.ts tests/stress/schema-edit-fields-view.e2e.ts tests/stress/sidebar-search-pill.e2e.ts tests/stress/navigation-history.e2e.ts tests/stress/command-palette-semantic.e2e.ts tests/stress/agent-activity-panel.e2e.ts tests/stress/drop-pipeline-auto-open.e2e.ts tests/stress/command-palette-flicker.e2e.ts tests/stress/cm6-list-hanging-indent.e2e.ts tests/stress/ng7-rapid-nav-coherence.e2e.ts tests/stress/reveal-on-activate.e2e.ts tests/stress/selection-indicator.e2e.ts tests/stress/new-file-cross-doc-bleed.e2e.ts tests/stress/new-item-shortcut-fast-path.e2e.ts tests/stress/editor-mode-flip-cross-doc-bleed.e2e.ts tests/stress/editor-area-viewport-resize.e2e.ts tests/stress/qa-sidebar-responsive.e2e.ts tests/stress/prd-6955-reassertion-repro.e2e.ts tests/stress/prd-6955-reassertion-wedge.e2e.ts tests/stress/prd-6914-repro.e2e.ts tests/stress/showall-lazy-tree.e2e.ts tests/stress/tabs-component-strip.e2e.ts tests/stress/source-find-scroll.e2e.ts tests/stress/harness-app-warmth.e2e.ts tests/stress/qa-canary-authoring-both-modes.e2e.ts tests/stress/qa-canary-live-typing.e2e.ts tests/stress/keystroke-cadence-danger-space.e2e.ts tests/stress/jsx-unregistered-backspace-delete.e2e.ts tests/stress/jsx-unregistered-ime-concurrent.e2e.ts tests/stress/jsx-backspace-delete.e2e.ts tests/stress/link-authoring-bytes.e2e.ts tests/stress/link-authoring-apex.e2e.ts tests/stress/command-palette-parity.e2e.ts tests/stress/settings-search.e2e.ts tests/stress/okf-generated-index-settings.e2e.ts tests/stress/okf-recommended-skill-install.e2e.ts tests/stress/chip-popover-positioning.e2e.ts tests/stress/docs-open-scroll-restore.e2e.ts tests/stress/file-tree-decoration-chip-strip-repro.e2e.ts tests/stress/grip-click-nodeselect.e2e.ts tests/stress/jsx-halo-semantics.e2e.ts tests/stress/jsx-image-body-click.e2e.ts tests/stress/jsx-prop-panel-placeholder.e2e.ts tests/stress/jsx-range-encompass-halo.e2e.ts tests/stress/jsx-wildcard-convert.e2e.ts tests/stress/markdown-lint.e2e.ts tests/stress/frontmatter-schema-badge.e2e.ts tests/stress/frontmatter-glob-picker.e2e.ts tests/stress/unified-problems.e2e.ts tests/stress/mid-type-recovery.e2e.ts tests/stress/observer-a-multi-client.e2e.ts tests/stress/outline-toolbar-occlusion.e2e.ts tests/stress/selection-surface-pane-clip.e2e.ts tests/stress/quiet-tree-hidden-doc.e2e.ts tests/stress/raw-mdx-fallback-onblur-upgrade.e2e.ts tests/stress/rename-noext-probe.e2e.ts tests/stress/show-ok-folders.e2e.ts tests/stress/source-polish.e2e.ts tests/stress/warm-skeleton-scroll-restore.e2e.ts tests/stress/props-toggle-scroll-preserve.e2e.ts tests/stress/yjs-no-dual-import.e2e.ts tests/stress/graph-panel-surfaces.e2e.ts tests/stress/asset-embed-real-fidelity.e2e.ts tests/stress/image-invalid-placeholder.e2e.ts tests/stress/local-target-audit.e2e.ts tests/stress/rename-content-preservation.e2e.ts tests/stress/rename-consolidation.e2e.ts tests/stress/outline-active-heading.e2e.ts tests/stress/outline-navigation.e2e.ts tests/stress/prd-7627-default-swatch.e2e.ts tests/stress/clipboard-dollar-math-source-fallback.e2e.ts tests/stress/source-mode-undo-keymap.e2e.ts tests/stress/source-undo-mode-flip.e2e.ts tests/stress/timeline-recovered-restore.e2e.ts tests/stress/blank-line-preservation.e2e.ts tests/stress/landing-helpers.e2e.ts tests/stress/agent-follow-scroll.e2e.ts tests/stress/mode-switch-landing.e2e.ts tests/stress/mode-switch-ordinal-divergence.e2e.ts tests/stress/comment-annotation-visibility.e2e.ts tests/stress/comment-opens-in-panel.e2e.ts tests/stress/qa-miles-edge-blanks.e2e.ts tests/stress/prop-upload.e2e.ts tests/stress/slash-command-auto-open.e2e.ts tests/stress/clipboard-relative-url-source-fallback.e2e.ts tests/stress/editor-split-view.e2e.ts tests/stress/language-load-failure.e2e.ts tests/stress/language-first-paint.e2e.ts tests/stress/user-text-direction.e2e.ts tests/stress/pseudolocale.e2e.ts tests/stress/language-picker.e2e.ts tests/stress/zh-hans-coverage-sweep.e2e.ts tests/stress/preview-tab-promotion.e2e.ts tests/stress/cv-paint-lock-click.e2e.ts tests/stress/cv-auto-paint-lock-click.e2e.ts tests/stress/history-traversal-preview-tab.e2e.ts tests/stress/tab-close-scroll-restore.e2e.ts tests/stress/skills-sidebar-open.e2e.ts tests/stress/trailing-affordance.e2e.ts tests/stress/text-doc-composer-inset.e2e.ts","test:e2e:install-browsers": "playwright install chromium webkit firefox","test:visual": "playwright test --config playwright.visual.config.ts","test:visual:update": "playwright test --config playwright.visual.config.ts --update-snapshots",diff --git a/packages/app/src/components/MermaidDocEditor.dom.test.tsx b/packages/app/src/components/MermaidDocEditor.dom.test.tsxnew file mode 100644index 000000000..5a620f60a--- /dev/null+++ b/packages/app/src/components/MermaidDocEditor.dom.test.tsx@@ -0,0 +1,48 @@+import type { HocuspocusProvider } from '@hocuspocus/provider';+import * as actualLinguiMacro from '@lingui/react/macro';+import { cleanup, render } from '@testing-library/react';+import { afterEach, describe, expect, test, vi } from 'vitest';+import { Awareness } from 'y-protocols/awareness';+import * as Y from 'yjs';+import { FULL_PAGE_CM_HOST_SELECTORS } from '@/globals-css.test-helper';+import { renderLinguiTemplate } from '@/test-utils/lingui-mock';++vi.doMock('@lingui/react/macro', () => ({+ ...actualLinguiMacro,+ useLingui: () => ({ t: renderLinguiTemplate }),+}));++vi.doMock('next-themes', () => ({+ useTheme: () => ({ resolvedTheme: 'light' }),+}));++vi.doMock('@/editor/components/Mermaid', () => ({+ MermaidView: () => <div data-testid="mermaid-view" />,+}));++const { MermaidDocEditor } = await import('./MermaidDocEditor');++afterEach(cleanup);++describe('MermaidDocEditor host contract', () => {+ test('renders the host attribute used by the composer-inset selector', () => {+ const document = new Y.Doc();+ const awareness = new Awareness(document);+ const provider = {+ document,+ awareness,+ on() {},+ off() {},+ } as unknown as HocuspocusProvider;++ const { container, unmount } = render(+ <MermaidDocEditor docName="diagram.mmd" provider={provider} isSourceMode={false} />,+ );++ expect(container.querySelector(FULL_PAGE_CM_HOST_SELECTORS.mermaidDocEditor)).not.toBeNull();++ unmount();+ awareness.destroy();+ document.destroy();+ });+});diff --git a/packages/app/src/editor/SourceEditor.dom.test.tsx b/packages/app/src/editor/SourceEditor.dom.test.tsxindex 264d51588..6d6827c10 100644--- a/packages/app/src/editor/SourceEditor.dom.test.tsx+++ b/packages/app/src/editor/SourceEditor.dom.test.tsx@@ -14,6 +14,7 @@ import {type OutlineNavDetail,} from '@/components/OutlinePanel';import { LINT_NAV_EVENT, type LintNavDetail } from '@/components/ProblemsPanel';+import { FULL_PAGE_CM_HOST_SELECTORS } from '@/globals-css.test-helper';import { ConfigContext, type ConfigContextValue } from '@/lib/config-context';import { evictCmEditor } from './editor-cache';import type { LandingHandle } from './landing-controller';@@ -133,6 +134,25 @@ function setPlatform(platform: string): void {});}+describe('SourceEditor host contract', () => {+ afterEach(() => {+ cleanup();+ for (const docName of mountedDocNames) {+ evictCmEditor(docName);+ }+ mountedDocNames.clear();+ });++ test('renders the host class used by the composer-inset selector', async () => {+ const { provider, ytext } = makeProvider('source-composer-inset-host');+ const { container } = render(<Harness provider={provider} ytext={ytext} wordWrap={true} />);++ await findCmContent(container);++ expect(container.querySelector(FULL_PAGE_CM_HOST_SELECTORS.sourceEditor)).not.toBeNull();+ });+});+describe('SourceEditor word-wrap preference wiring', () => {beforeEach(() => {composerOpenRequests = 0;diff --git a/packages/app/src/globals-css.test-helper.test.ts b/packages/app/src/globals-css.test-helper.test.tsnew file mode 100644index 000000000..63d90874c--- /dev/null+++ b/packages/app/src/globals-css.test-helper.test.ts@@ -0,0 +1,29 @@+import { describe, expect, test } from 'vitest';+import { blankComments } from './globals-css.test-helper';++describe('globals.css comment stripping', () => {+ test('a `/*` inside a quoted at-rule argument does not open a comment', () => {+ const css = '@source "../node_modules/streamdown/dist/*.js";\n.target { padding: 0 }\n/* x */';+ expect(+ blankComments(css).includes('.target { padding: 0 }'),+ 'the naive `replace(/\\/\\*[\\s\\S]*?\\*\\//g, "")` opens a comment at the `/*` inside the ' ++ '@source string and closes it at the next real `*/`, deleting everything between. ' ++ 'globals.css carries that exact at-rule, so a naive strip silently discards about half ' ++ 'the stylesheet and every rule lookup against it goes vacuous instead of red',+ ).toBe(true);+ });++ test('real comments are blanked without moving any other byte', () => {+ const css = '.a { color: red } /* note */ .b { color: blue }';+ const blanked = blankComments(css);+ expect(blanked.length).toBe(css.length);+ expect(blanked.includes('note')).toBe(false);+ expect(blanked.startsWith('.a { color: red }')).toBe(true);+ expect(blanked.endsWith('.b { color: blue }')).toBe(true);+ });++ test('line numbers survive a multi-line comment', () => {+ const css = '.a {}\n/* one\n two */\n.b {}';+ expect(blankComments(css).split('\n').length).toBe(css.split('\n').length);+ });+});diff --git a/packages/app/src/globals-css.test-helper.ts b/packages/app/src/globals-css.test-helper.tsnew file mode 100644index 000000000..095a8c968--- /dev/null+++ b/packages/app/src/globals-css.test-helper.ts@@ -0,0 +1,54 @@+import { readFileSync } from 'node:fs';+import { join } from 'node:path';++const GLOBALS_CSS_PATH = join(import.meta.dirname, 'globals.css');++export const FULL_PAGE_CM_HOST_SELECTORS = {+ mermaidDocEditor: '[data-mermaid-doc-editor]',+ sourceEditor: '.source-editor',+ textDocEditor: '[data-text-doc-editor]',+} as const;++export function blankComments(css: string): string {+ let out = '';+ let quote: string | null = null;+ let i = 0;+ while (i < css.length) {+ const ch = css[i];+ if (quote) {+ if (ch === '\\') {+ out += css.slice(i, i + 2);+ i += 2;+ continue;+ }+ out += ch;+ if (ch === quote) quote = null;+ i++;+ continue;+ }+ if (ch === '"' || ch === "'") {+ quote = ch;+ out += ch;+ i++;+ continue;+ }+ if (ch === '/' && css[i + 1] === '*') {+ const end = css.indexOf('*/', i + 2);+ const stop = end === -1 ? css.length : end + 2;+ out += css.slice(i, stop).replace(/[^\n]/g, ' ');+ i = stop;+ continue;+ }+ out += ch;+ i++;+ }+ return out;+}++export function readGlobalsCssRaw(): string {+ return readFileSync(GLOBALS_CSS_PATH, 'utf-8');+}++export function readGlobalsCssWithoutComments(): string {+ return blankComments(readGlobalsCssRaw());+}diff --git a/packages/app/src/globals.composer-inset-cascade.test.ts b/packages/app/src/globals.composer-inset-cascade.test.tsnew file mode 100644index 000000000..bfeac7514--- /dev/null+++ b/packages/app/src/globals.composer-inset-cascade.test.ts@@ -0,0 +1,174 @@+import { readdirSync, readFileSync } from 'node:fs';+import { join, relative, sep } from 'node:path';+import { describe, expect, test } from 'vitest';+import {+ FULL_PAGE_CM_HOST_SELECTORS,+ readGlobalsCssWithoutComments,+} from './globals-css.test-helper';++const SRC_ROOT = import.meta.dirname;++const RESET_PRELUDE = '.cm-editor .cm-content';++const INSET_VALUE = 'var(--ask-composer-height';++type InsetKind = 'content' | 'host';++interface FullPageCmSurface {+ component: string;+ hostSelector: string;+ insetKind: InsetKind;+}++const FULL_PAGE_CM_SURFACES: readonly FullPageCmSurface[] = [+ {+ component: 'components/TextDocEditor.tsx',+ hostSelector: FULL_PAGE_CM_HOST_SELECTORS.textDocEditor,+ insetKind: 'content',+ },+ {+ component: 'editor/SourceEditor.tsx',+ hostSelector: FULL_PAGE_CM_HOST_SELECTORS.sourceEditor,+ insetKind: 'content',+ },+ {+ component: 'components/MermaidDocEditor.tsx',+ hostSelector: FULL_PAGE_CM_HOST_SELECTORS.mermaidDocEditor,+ insetKind: 'host',+ },+];++const FULL_PAGE_CM_THEME = /EditorView\.theme\(\s*\{[\s\S]{0,120}?height:\s*'100%'/;++function listSourceFiles(dir: string): string[] {+ return readdirSync(dir, { recursive: true, withFileTypes: true })+ .filter(+ (entry) =>+ entry.isFile() &&+ /\.tsx?$/.test(entry.name) &&+ !/\.(test|test-helper|dom\.test)\.tsx?$/.test(entry.name),+ )+ .map((entry) => join(entry.parentPath, entry.name))+ .filter((file) => !relative(dir, file).split(sep).includes('locales'));+}++function mountsFullPageCodeMirror(absPath: string): boolean {+ return FULL_PAGE_CM_THEME.test(readFileSync(absPath, 'utf-8'));+}++function ruleOffsets(css: string, prelude: string): number[] {+ const escaped = prelude.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const pattern = new RegExp(`(^|[,{}])\\s*${escaped}\\s*(,|\\{)`, 'g');+ const offsets: number[] = [];+ for (let m = pattern.exec(css); m !== null; m = pattern.exec(css)) offsets.push(m.index);+ return offsets;+}++function declarationBlockAt(css: string, offset: number): string {+ const open = css.indexOf('{', offset);+ if (open === -1) return '';+ let depth = 0;+ for (let i = open; i < css.length; i++) {+ if (css[i] === '{') depth++;+ else if (css[i] === '}') {+ depth--;+ if (depth === 0) return css.slice(open + 1, i);+ }+ }+ return '';+}++function composerInsetOffset(css: string, prelude: string): number | null {+ for (const offset of ruleOffsets(css, prelude)) {+ if (declarationBlockAt(css, offset).includes(INSET_VALUE)) return offset;+ }+ return null;+}++describe('full-page CodeMirror surfaces reserve the Ask AI composer height', () => {+ const css = readGlobalsCssWithoutComments();++ test('the padding reset that every full-page CM surface has to undo is still there', () => {+ const resetOffsets = ruleOffsets(css, RESET_PRELUDE);+ expect(+ resetOffsets.length,+ `no \`${RESET_PRELUDE}\` rule in globals.css. Every assertion below is about ` ++ 'surviving that reset, so its absence makes this whole file vacuous rather than green',+ ).toBeGreaterThan(0);+ const zeroing = resetOffsets.some((offset) =>+ /padding:\s*0/.test(declarationBlockAt(css, offset)),+ );+ expect(+ zeroing,+ `\`${RESET_PRELUDE}\` no longer zeroes padding. If the reset stopped applying, the ` ++ 'per-surface restores below are dead weight and the shared ' ++ '`.editor-doc-scroll :is(.ProseMirror, .cm-content)` inset reaches these surfaces directly',+ ).toBe(true);+ });++ test.each(+ FULL_PAGE_CM_SURFACES,+ )('$component reserves the composer height and wins the tie against the reset', ({+ component,+ hostSelector,+ insetKind,+ }) => {+ const prelude = insetKind === 'content' ? `${hostSelector} .cm-content` : hostSelector;+ const insetOffset = composerInsetOffset(css, prelude);+ expect(+ insetOffset,+ `${component} mounts a full-page CodeMirror but no \`${prelude}\` rule in globals.css ` ++ `sets \`padding-bottom: ${INSET_VALUE}…)\`. Its last lines sit under the floating Ask AI ` ++ 'composer with no way to scroll them clear, which is the bug this registry exists to stop',+ ).not.toBeNull();+ if (insetKind !== 'content' || insetOffset === null) return;+ const resetOffset = Math.max(...ruleOffsets(css, RESET_PRELUDE));+ expect(+ insetOffset,+ `\`${prelude}\` ties \`${RESET_PRELUDE}\` on specificity (0,2,0), so document order breaks ` ++ 'the tie. Declared before the reset it loses and the inset silently collapses to 0',+ ).toBeGreaterThan(resetOffset);+ });++ test.each(FULL_PAGE_CM_SURFACES)('$component reserves exactly one composer height', ({+ hostSelector,+ }) => {+ const insetOffsets = [+ composerInsetOffset(css, hostSelector),+ composerInsetOffset(css, `${hostSelector} .cm-content`),+ ].filter((offset) => offset !== null);+ expect(+ insetOffsets,+ `\`${hostSelector}\` must reserve the composer height on EITHER its host OR its ` ++ '`.cm-content`, never both. Zero leaves the last lines under the composer; two reserves ' ++ 'double the gap and make the last line float a full card above it',+ ).toHaveLength(1);+ });++ test('no other component mounts a full-page CodeMirror without an entry here', () => {+ const registered = new Set(+ FULL_PAGE_CM_SURFACES.map((surface) => join(SRC_ROOT, surface.component)),+ );+ const unregistered = listSourceFiles(SRC_ROOT)+ .filter((file) => !registered.has(file))+ .filter(mountsFullPageCodeMirror)+ .map((file) => file.slice(SRC_ROOT.length + 1));+ expect(+ unregistered,+ 'these components match the full-page CodeMirror syntax detector (`EditorView.theme(...)` ' ++ "with `height: '100%'`) but are not registered above, so nothing checks that they reserve " ++ 'the composer height. Add each to FULL_PAGE_CM_SURFACES with the host selector its ' ++ 'globals.css inset rule uses, or tighten the detector if the match is not a full-page surface',+ ).toEqual([]);+ });++ test('the registry is not silently empty', () => {+ expect(FULL_PAGE_CM_SURFACES.length).toBeGreaterThan(0);+ const found = listSourceFiles(SRC_ROOT).filter(mountsFullPageCodeMirror);+ expect(+ found.length,+ 'the full-page CodeMirror detector matched nothing at all, so the completeness test above ' ++ 'passes by finding nothing rather than by finding everything registered',+ ).toBe(FULL_PAGE_CM_SURFACES.length);+ });+});diff --git a/packages/app/src/globals.css b/packages/app/src/globals.cssindex 5dfbb252b..f0f85527d 100644--- a/packages/app/src/globals.css+++ b/packages/app/src/globals.css@@ -1064,9 +1064,10 @@padding-bottom: calc(var(--ask-composer-height, 0px) + var(--ok-trailing-zone, 0px));}-/* Standalone Mermaid docs render OUTSIDE `.editor-doc-scroll` — a diagram +- source pane, not a ProseMirror/CM scroll surface — so the inset above never- reaches them. Reserve the composer height on the whole editor so a full-page+/* Standalone Mermaid docs render inside `.editor-doc-scroll` like every other+ pool branch, but the host itself is a diagram + source pane rather than a+ `.ProseMirror` / `.cm-content` element, so the inset above never selects it.+ Reserve the composer height on the whole editor so a full-pagepanzoom diagram (which does not scroll) and the source pane's last lines clearthe floating card. The var is 0 when the composer is collapsed/hidden, so thespace is reclaimed with no class to fall out of sync. */@@ -2755,14 +2756,27 @@ body[data-editor-tab-dragging] * {padding: 0;}-/* Restore the floating Ask AI composer's bottom inset for full-page source mode.+/* Restore the floating Ask AI composer's bottom inset for two full-page+ CodeMirror surfaces: markdown source mode (`.source-editor`) and editable text+ docs (`[data-text-doc-editor]`, the `.ts` / `.json` / `.txt` editor).The `padding: 0` reset above ties on specificity with the shared`.editor-doc-scroll :is(.ProseMirror, .cm-content)` inset rule and, being- later, zeroes it — so those surfaces' last lines would sit under the composer- while WYSIWYG clears. Scoped to `.source-editor` (not `.cm-editor`) so nested- code-block CM inside the WYSIWYG body is never padded; declared after the- reset so it wins the tie. */-.source-editor .cm-content {+ later, zeroes it, so those surfaces' last lines would sit under the composer+ while WYSIWYG clears. Both hosts scroll inside CodeMirror's own `.cm-scroller`+ (each sets `height: 100%` on the editor), so the room has to come from padding+ the CONTENT: padding the host would shrink the editor box, cutting the gutter+ and the scrollbar off above the composer instead of running them behind it.+ `[data-mermaid-doc-editor]` takes the host route because the same wrapper also+ hosts its non-scrolling diagram pane. Its source mode knowingly ends the+ gutter and scrollbar above the composer, preserving one inset across that+ diagram-first surface's mode switch. Scoped to these two hosts (not+ `.cm-editor`) so nested code-block CM inside the WYSIWYG body is never padded,+ and declared after the reset so it wins the tie. A full-page CM surface needs+ EITHER this content restore OR a host-level `padding-bottom` like+ `[data-mermaid-doc-editor]` above, never both, or it reserves two composer+ heights and the last line floats a card above the composer. */+.source-editor .cm-content,+[data-text-doc-editor] .cm-content {padding-bottom: var(--ask-composer-height, 0px);}diff --git a/packages/app/src/globals.cv-paint-lock.test.ts b/packages/app/src/globals.cv-paint-lock.test.tsindex 7a090a01e..798c3e07f 100644--- a/packages/app/src/globals.cv-paint-lock.test.ts+++ b/packages/app/src/globals.cv-paint-lock.test.ts@@ -1,10 +1,9 @@import { readdirSync, readFileSync } from 'node:fs';import { join } from 'node:path';import { describe, expect, test } from 'vitest';+import { blankComments, readGlobalsCssWithoutComments } from './globals-css.test-helper';-const RAW_CSS = readFileSync(join(__dirname, 'globals.css'), 'utf8');--const CSS = RAW_CSS.replace(/\/\*[\s\S]*?\*\//g, '');+const CSS = readGlobalsCssWithoutComments();interface RuleBlock {selector: string;@@ -103,7 +102,7 @@ describe('globals.css content-visibility paint-lock deferral contract', () => {const content = readFileSync(filePath, 'utf8');const isCss = entry.name.endsWith('.css');const hit = isCss- ? CV_HIDDEN.test(content.replace(/\/\*[\s\S]*?\*\//g, ''))+ ? CV_HIDDEN.test(blankComments(content)): TAILWIND_CV_HIDDEN.test(content) ||STYLE_PROP_CV_HIDDEN.test(content) ||SET_PROPERTY_CV_HIDDEN.test(content);diff --git a/packages/app/src/globals.pointer-marker.test.ts b/packages/app/src/globals.pointer-marker.test.tsindex 27f727f9a..dc5526239 100644--- a/packages/app/src/globals.pointer-marker.test.ts+++ b/packages/app/src/globals.pointer-marker.test.ts@@ -1,9 +1,7 @@-import { readFileSync } from 'node:fs';-import { join } from 'node:path';import { describe, expect, test } from 'vitest';+import { readGlobalsCssWithoutComments } from './globals-css.test-helper';-const RAW_CSS = readFileSync(join(__dirname, 'globals.css'), 'utf8');-const CSS = RAW_CSS.replace(/\/\*[\s\S]*?\*\//g, '');+const CSS = readGlobalsCssWithoutComments();function markerDeclarations(): string {const block = CSS.match(/(?:^|[}\s])\.ok-pointer-marker\s*\{([^{}]*)\}/);diff --git a/packages/app/src/globals.suggestion-clip-cascade.test.ts b/packages/app/src/globals.suggestion-clip-cascade.test.tsindex 56e373f5b..9740f8d43 100644--- a/packages/app/src/globals.suggestion-clip-cascade.test.ts+++ b/packages/app/src/globals.suggestion-clip-cascade.test.ts@@ -1,16 +1,12 @@-import { readFileSync } from 'node:fs';-import { dirname, resolve } from 'node:path';-import { fileURLToPath } from 'node:url';import { describe, expect, test } from 'vitest';--const GLOBALS_CSS = resolve(dirname(fileURLToPath(import.meta.url)), 'globals.css');+import { blankComments, readGlobalsCssRaw } from './globals-css.test-helper';const SHRINK_SELECTOR = '[data-suggestion-popup][data-suggestion-clipped] *';const LAYERS_BEFORE_UTILITIES = ['theme', 'base', 'components'];function enclosingLayer(source: string, selector: string): string | null {- const css = source.replace(/\/\*[\s\S]*?\*\//g, (block) => ' '.repeat(block.length));+ const css = blankComments(source);const prelude = new RegExp(`${selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*\\{`);const found = prelude.exec(css);if (!found) throw new Error(`cascade-position: no rule with prelude ${selector} in globals.css`);@@ -38,7 +34,7 @@ function enclosingLayer(source: string, selector: string): string | null {describe('suggestion picker shrink rule cascade position', () => {test('sits in a layer that Tailwind utilities can override', () => {- const css = readFileSync(GLOBALS_CSS, 'utf8');+ const css = readGlobalsCssRaw();const layer = enclosingLayer(css, SHRINK_SELECTOR);expect(layer,diff --git a/packages/app/tests/stress/text-doc-composer-inset.e2e.ts b/packages/app/tests/stress/text-doc-composer-inset.e2e.tsnew file mode 100644index 000000000..95657e552--- /dev/null+++ b/packages/app/tests/stress/text-doc-composer-inset.e2e.ts@@ -0,0 +1,96 @@+import { randomUUID } from 'node:crypto';+import { writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { expect, test } from './_helpers';++const TEXT_DOC = '[data-text-doc-editor]';+const CM_CONTENT = `${TEXT_DOC} .cm-content`;+const CM_SCROLLER = `${TEXT_DOC} .cm-scroller`;+const COMPOSER = '[data-testid="bottom-composer"]';+const COMPOSER_CARD = `${COMPOSER} > div`;++const LINE_COUNT = 400;++test.describe('editable text doc reserves the Ask AI composer height', () => {+ test('the last line of a code file scrolls clear of the composer card', async ({+ page,+ workerServer,+ }) => {+ const docName = `composer-inset-${randomUUID().slice(0, 8)}.ts`;+ const lastLine = `export const lastLineSentinel = ${LINE_COUNT - 1};`;+ const body = Array.from(+ { length: LINE_COUNT - 1 },+ (_, index) => `export const l${index} = ${index};`,+ )+ .concat(lastLine)+ .join('\n');+ writeFileSync(join(workerServer.contentDir, docName), `${body}\n`, 'utf-8');++ await page.goto(`/#/${docName}`);+ await expect(page.locator(CM_CONTENT).first()).toBeVisible({ timeout: 20_000 });+ await expect(page.locator(COMPOSER_CARD).first()).toBeVisible({ timeout: 20_000 });++ await expect+ .poll(+ () =>+ page.evaluate(() =>+ Number.parseFloat(+ getComputedStyle(document.documentElement).getPropertyValue(+ '--ask-composer-height',+ ) || '0',+ ),+ ),+ {+ message:+ 'the composer never published --ask-composer-height, so every assertion below would ' ++ 'compare 0 against 0 and pass whether or not the inset rule exists',+ timeout: 20_000,+ },+ )+ .toBeGreaterThan(0);++ await expect+ .poll(+ () =>+ page.evaluate((contentSel) => {+ const content = document.querySelector(contentSel);+ if (!(content instanceof HTMLElement)) throw new Error('no painted .cm-content');+ const composerHeight = Number.parseFloat(+ getComputedStyle(document.documentElement).getPropertyValue('--ask-composer-height'),+ );+ return Number.parseFloat(getComputedStyle(content).paddingBottom) - composerHeight;+ }, CM_CONTENT),+ {+ message:+ 'the compiled stylesheet gives `[data-text-doc-editor] .cm-content` no bottom inset ' ++ 'matching the composer. `.cm-editor .cm-content { padding: 0 }` ties the shared ' ++ '`.editor-doc-scroll` inset on specificity and wins on document order, so a code file ' ++ 'paints its last lines under the floating Ask AI card. Only this tier reads the ' ++ 'compiled CSS, so a source-text guard cannot see a regression here',+ timeout: 10_000,+ },+ )+ .toBeCloseTo(0, 0);++ await page.evaluate((scrollerSel) => {+ const scroller = document.querySelector(scrollerSel);+ if (!(scroller instanceof HTMLElement)) throw new Error('no painted .cm-scroller');+ scroller.scrollTop = scroller.scrollHeight;+ }, CM_SCROLLER);++ const lastLineBox = await page+ .locator(`${CM_CONTENT} .cm-line`)+ .filter({ hasText: 'lastLineSentinel' })+ .first()+ .boundingBox();+ const cardBox = await page.locator(COMPOSER_CARD).first().boundingBox();+ if (!lastLineBox || !cardBox) throw new Error('last line or composer card is not painted');++ expect(+ lastLineBox.y + lastLineBox.height,+ 'with the scroller pinned to the bottom the final line still paints below the top of the ' ++ 'Ask AI card, so it is unreachable however far the user scrolls. The inset has to be ' ++ 'tall enough to lift the document floor past the card, not merely non-zero',+ ).toBeLessThanOrEqual(cardBox.y);+ });+});diff --git a/turbo.json b/turbo.jsonindex 8058d8332..160af2c79 100644--- a/turbo.json+++ b/turbo.json@@ -66,6 +66,7 @@"src/**/*.ts","src/**/*.tsx","src/**/*.json",+ "src/**/*.css","tests/contract/**/*.ts","vitest.config.ts","vite.dedupe.ts",@@ -168,6 +169,7 @@"inputs": ["src/**/*.ts","src/**/*.tsx",+ "src/**/*.css","tests/**/*.ts","tests/**/*.tsx","scripts/**",@@ -190,6 +192,7 @@"inputs": ["src/**/*.ts","src/**/*.tsx",+ "src/**/*.css","tests/**/*.ts","tests/**/*.tsx","scripts/**",@@ -212,6 +215,7 @@"inputs": ["src/**/*.ts","src/**/*.tsx",+ "src/**/*.css","tests/**/*.ts","tests/**/*.tsx","scripts/**",@@ -234,6 +238,7 @@"inputs": ["src/**/*.ts","src/**/*.tsx",+ "src/**/*.css","tests/**/*.ts","tests/**/*.tsx","scripts/**",