дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-21 17:10:45 +02:00
Порівняти коміти
4
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
e062aa5d8b | ||
|
|
18e964a9af | ||
|
|
9ac18ed576 | ||
|
|
b1cf69bd05 |
No files matched your search
Створено
@@ -5017,6 +5017,7 @@ dependencies = [
|
||||
"ignore",
|
||||
"notify",
|
||||
"parking_lot",
|
||||
"rayon",
|
||||
"rustix",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@@ -22,6 +22,7 @@ parking_lot.workspace = true
|
||||
zip.workspace = true
|
||||
flate2.workspace = true
|
||||
tar.workspace = true
|
||||
rayon.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile.workspace = true
|
||||
|
||||
@@ -10,6 +10,7 @@ mod rules;
|
||||
mod watch;
|
||||
|
||||
use ide_core::{IdeError, IdeResult};
|
||||
use rayon::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
use std::cmp::Ordering;
|
||||
@@ -133,51 +134,57 @@ pub fn read_dir(dir: &Path, excludes: &[String]) -> IdeResult<Vec<FileEntry>> {
|
||||
let base = gitignore.repo_root().unwrap_or(dir).to_path_buf();
|
||||
let excludes = ExcludeMatcher::new(excludes);
|
||||
|
||||
let mut entries: Vec<(bool, FileEntry)> = Vec::new();
|
||||
for entry in fs::read_dir(dir)? {
|
||||
let entry = match entry {
|
||||
Ok(e) => e,
|
||||
let paths: Vec<PathBuf> = fs::read_dir(dir)?
|
||||
.filter_map(|entry| match entry {
|
||||
Ok(e) => Some(e.path()),
|
||||
Err(e) => {
|
||||
tracing::debug!("read_dir {}: {e}", dir.display());
|
||||
continue;
|
||||
None
|
||||
}
|
||||
};
|
||||
let path = entry.path();
|
||||
let name = entry.file_name().to_string_lossy().into_owned();
|
||||
let Ok(lmeta) = fs::symlink_metadata(&path) else { continue };
|
||||
let (kind, meta, target_kind) = if lmeta.file_type().is_symlink() {
|
||||
match fs::metadata(&path) {
|
||||
Ok(m) => {
|
||||
let target = if m.is_dir() { EntryKind::Dir } else { EntryKind::File };
|
||||
(EntryKind::Symlink, m, Some(target))
|
||||
})
|
||||
.collect();
|
||||
// One stat per entry dominates a large folder (and every stat is a round trip on a network
|
||||
// share): stat in parallel; small folders stay on this thread.
|
||||
let mut entries: Vec<(bool, FileEntry)> = paths
|
||||
.into_par_iter()
|
||||
.with_min_len(256)
|
||||
.filter_map(|path| {
|
||||
let name = path.file_name()?.to_string_lossy().into_owned();
|
||||
let lmeta = fs::symlink_metadata(&path).ok()?;
|
||||
let (kind, meta, target_kind) = if lmeta.file_type().is_symlink() {
|
||||
match fs::metadata(&path) {
|
||||
Ok(m) => {
|
||||
let target = if m.is_dir() { EntryKind::Dir } else { EntryKind::File };
|
||||
(EntryKind::Symlink, m, Some(target))
|
||||
}
|
||||
Err(_) => (EntryKind::Symlink, lmeta, None),
|
||||
}
|
||||
Err(_) => (EntryKind::Symlink, lmeta, None),
|
||||
}
|
||||
} else if lmeta.is_dir() {
|
||||
(EntryKind::Dir, lmeta, None)
|
||||
} else {
|
||||
(EntryKind::File, lmeta, None)
|
||||
};
|
||||
let is_dir = meta.is_dir();
|
||||
let rel = path.strip_prefix(&base).unwrap_or(&path);
|
||||
let excluded = excludes.is_excluded(rel);
|
||||
let ignored = excluded || gitignore.is_ignored(&path, is_dir);
|
||||
entries.push((
|
||||
is_dir,
|
||||
FileEntry {
|
||||
hidden: name.starts_with('.'),
|
||||
size: if is_dir { 0 } else { meta.len() },
|
||||
mtime_ms: mtime_ms(&meta),
|
||||
name,
|
||||
path: path.into(),
|
||||
kind,
|
||||
ignored,
|
||||
excluded,
|
||||
target_kind,
|
||||
},
|
||||
));
|
||||
}
|
||||
entries.sort_by(|(da, a), (db, b)| db.cmp(da).then_with(|| natural_cmp(&a.name, &b.name)));
|
||||
} else if lmeta.is_dir() {
|
||||
(EntryKind::Dir, lmeta, None)
|
||||
} else {
|
||||
(EntryKind::File, lmeta, None)
|
||||
};
|
||||
let is_dir = meta.is_dir();
|
||||
let rel = path.strip_prefix(&base).unwrap_or(&path);
|
||||
let excluded = excludes.is_excluded(rel);
|
||||
let ignored = excluded || gitignore.is_ignored(&path, is_dir);
|
||||
Some((
|
||||
is_dir,
|
||||
FileEntry {
|
||||
hidden: name.starts_with('.'),
|
||||
size: if is_dir { 0 } else { meta.len() },
|
||||
mtime_ms: mtime_ms(&meta),
|
||||
name,
|
||||
path: path.into(),
|
||||
kind,
|
||||
ignored,
|
||||
excluded,
|
||||
target_kind,
|
||||
},
|
||||
))
|
||||
})
|
||||
.collect();
|
||||
entries.par_sort_by(|(da, a), (db, b)| db.cmp(da).then_with(|| natural_cmp(&a.name, &b.name)));
|
||||
Ok(entries.into_iter().map(|(_, e)| e).collect())
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
diff --git a/dist/index.cjs b/dist/index.cjs
|
||||
index b20aa9d84be6ff4b85b126bdd930065277668a26..e677ab06ca9668407e202979e14b75ab7641d6b1 100644
|
||||
--- a/dist/index.cjs
|
||||
+++ b/dist/index.cjs
|
||||
@@ -9675,7 +9675,9 @@ const hideNativeSelection = state.Prec.highest(EditorView.theme({
|
||||
"& :focus": {
|
||||
caretColor: "initial !important",
|
||||
...drawMainRange ? {
|
||||
- "&::selection, & ::selection": {
|
||||
+ // Not `& ::selection` too: a pseudo-class with a universal descendant restyles the
|
||||
+ // whole subtree of every element that gains or loses focus.
|
||||
+ "&::selection": {
|
||||
backgroundColor: "Highlight !important"
|
||||
}
|
||||
} : {}
|
||||
diff --git a/dist/index.js b/dist/index.js
|
||||
index 216f754db06f65f7f17f056b47d8f6fab45067bf..22282993239d836ea1da19af10ccfc61b6480cc5 100644
|
||||
--- a/dist/index.js
|
||||
+++ b/dist/index.js
|
||||
@@ -9670,7 +9670,9 @@ const hideNativeSelection = /*@__PURE__*/Prec.highest(/*@__PURE__*/EditorView.th
|
||||
"& :focus": {
|
||||
caretColor: "initial !important",
|
||||
...drawMainRange ? {
|
||||
- "&::selection, & ::selection": {
|
||||
+ // Not `& ::selection` too: a pseudo-class with a universal descendant restyles the
|
||||
+ // whole subtree of every element that gains or loses focus.
|
||||
+ "&::selection": {
|
||||
backgroundColor: "Highlight !important"
|
||||
}
|
||||
} : {}
|
||||
+34
-25
@@ -323,6 +323,18 @@ const scroll: Scenario = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Runs an action without a default shortcut from a key press: the press is the measured input,
|
||||
* and the action runs in its handler, as from a key binding. Pause is bound to nothing.
|
||||
*/
|
||||
async function runActionOnKey(h: Harness, id: string) {
|
||||
await h.page.evaluate((id) => {
|
||||
const probe = (window as never as { __openideaPerf: { runAction(id: string): Promise<boolean> } }).__openideaPerf;
|
||||
addEventListener("keydown", () => void probe.runAction(id), { capture: true, once: true });
|
||||
}, id);
|
||||
await h.page.keyboard.press("Pause");
|
||||
}
|
||||
|
||||
/**
|
||||
* Git Log with 20,000 commits on branching lanes, loaded page by page as the
|
||||
* backend does (150 ms a page, like `git log`): showing it, walking the
|
||||
@@ -339,12 +351,7 @@ const gitLog: Scenario = {
|
||||
).__openideaPerf.fakeGitLog(20_000, 150),
|
||||
);
|
||||
const showMs = await h.measure(
|
||||
() =>
|
||||
h.page.evaluate(() =>
|
||||
(window as never as { __openideaPerf: { runAction(id: string): Promise<boolean> } }).__openideaPerf.runAction(
|
||||
"vcs.showLog",
|
||||
),
|
||||
),
|
||||
() => runActionOnKey(h, "vcs.showLog"),
|
||||
'[role="listbox"][aria-label="Commits"]',
|
||||
"order flow step 0",
|
||||
);
|
||||
@@ -430,16 +437,13 @@ const resizePanels: Scenario = {
|
||||
await h.page.evaluate(() =>
|
||||
(window as never as { __openideaPerf: { fakeGitLog(n: number): void } }).__openideaPerf.fakeGitLog(2_000),
|
||||
);
|
||||
await h.measure(
|
||||
() =>
|
||||
h.page.evaluate(() =>
|
||||
(window as never as { __openideaPerf: { runAction(id: string): Promise<boolean> } }).__openideaPerf.runAction(
|
||||
"vcs.showLog",
|
||||
),
|
||||
),
|
||||
'[role="listbox"][aria-label="Commits"]',
|
||||
"order flow step 0",
|
||||
await h.page.evaluate(() =>
|
||||
(window as never as { __openideaPerf: { runAction(id: string): Promise<boolean> } }).__openideaPerf.runAction(
|
||||
"vcs.showLog",
|
||||
),
|
||||
);
|
||||
// Set-up, not measured: the splitters are dragged once the log is shown.
|
||||
await h.inPage((p) => p.waitShown('[role="listbox"][aria-label="Commits"]', "order flow step 0", 10_000));
|
||||
const refresh = await h.refreshMs();
|
||||
const drag = async (name: string, dx: number, dy: number) => {
|
||||
const box = (await h.page.getByRole("separator", { name }).boundingBox())!;
|
||||
@@ -560,7 +564,9 @@ const agentTabs: Scenario = {
|
||||
window as never as { __openideaPerf: { runAction(id: string, arg?: unknown): Promise<boolean> } }
|
||||
).__openideaPerf.runAction("agents.openSampleConversations", { tasks: 2, turns: 150 }),
|
||||
);
|
||||
const shown = (n: number) => `[data-editor-focus] span[title="Sample task ${n}"]`;
|
||||
// The conversation shown: its requests end with its task's title.
|
||||
const SHOWN = "[data-editor-focus] [data-message]";
|
||||
const title = (n: number) => `(Sample task ${n})`;
|
||||
// Both conversations get their earlier entries painted in background batches, also the
|
||||
// first one, hidden behind the second as soon as it opened.
|
||||
await h.page.waitForFunction(
|
||||
@@ -575,25 +581,28 @@ const agentTabs: Scenario = {
|
||||
// Rows painted while hidden are laid out the first time their conversation shows.
|
||||
for (const n of [1, 2]) {
|
||||
await h.page.getByRole("tab", { name: `Sample task ${n}` }).click();
|
||||
await h.page.locator(shown(n)).waitFor();
|
||||
await h.page
|
||||
.locator(SHOWN, { hasText: title(n) })
|
||||
.first()
|
||||
.waitFor();
|
||||
await h.page.waitForTimeout(300);
|
||||
}
|
||||
// WebKit restyles a hidden conversation in full when it is shown again (Chromium keeps its
|
||||
// style): what bounds that there is the history's DOM, and rows skipping rendering off screen.
|
||||
const { conversationNodes, rowsAlwaysRendered } = await h.page.evaluate((selector) => {
|
||||
const conversation = document.querySelector(selector)!.closest("[data-editor-focus]")!;
|
||||
const conversation = document.querySelector(selector)!;
|
||||
const rows = [...conversation.querySelector("[data-message]")!.parentElement!.children];
|
||||
return {
|
||||
conversationNodes: conversation.querySelectorAll("*").length,
|
||||
rowsAlwaysRendered: rows.filter((r) => getComputedStyle(r).contentVisibility !== "auto").length,
|
||||
};
|
||||
}, shown(2));
|
||||
}, "[data-editor-focus]");
|
||||
|
||||
const t0 = await h.now();
|
||||
const before = await h.counters();
|
||||
const switches: number[] = [];
|
||||
for (let i = 0; i < 10; i++) {
|
||||
switches.push(await h.measure(() => h.pressAction("navigate.switcher"), shown(i % 2 ? 2 : 1)));
|
||||
switches.push(await h.measure(() => h.pressAction("navigate.switcher"), SHOWN, title(i % 2 ? 2 : 1)));
|
||||
await h.page.waitForTimeout(150);
|
||||
}
|
||||
const work = Harness.delta(before, await h.counters());
|
||||
@@ -602,10 +611,7 @@ const agentTabs: Scenario = {
|
||||
// Scrolling up from the end, a step at a time: how far the text under the pointer moves
|
||||
// beyond the scroll itself.
|
||||
const scrollJumps = await h.page.evaluate(async (selector) => {
|
||||
const stream = document
|
||||
.querySelector(selector)!
|
||||
.closest("[data-editor-focus]")!
|
||||
.querySelector("[data-message]")!.parentElement!;
|
||||
const stream = document.querySelector(selector)!.parentElement!;
|
||||
const frame = () => new Promise(requestAnimationFrame);
|
||||
stream.scrollTop = stream.scrollHeight;
|
||||
await frame();
|
||||
@@ -626,7 +632,7 @@ const agentTabs: Scenario = {
|
||||
}
|
||||
stream.scrollTop = stream.scrollHeight;
|
||||
return jumps;
|
||||
}, shown(2));
|
||||
}, SHOWN);
|
||||
|
||||
const refresh = await h.refreshMs();
|
||||
const box = (await h.page.locator("[data-editor-focus]").boundingBox())!;
|
||||
@@ -732,6 +738,9 @@ const projectTree: Scenario = {
|
||||
async run(h) {
|
||||
const generated = h.page.locator('[role="treeitem"][aria-level="2"]', { hasText: "generated" }).first();
|
||||
await generated.click();
|
||||
// Measure from a settled selection: a key pressed in the click's own frame also pays for that frame.
|
||||
await generated.and(h.page.locator('[aria-selected="true"]')).waitFor();
|
||||
await h.page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
const expandMs = await h.measure(
|
||||
() => h.page.keyboard.press("ArrowRight"),
|
||||
'[role="tree"][aria-label="Project"]',
|
||||
|
||||
Створено
+20
-24
@@ -7,6 +7,9 @@ settings:
|
||||
overrides:
|
||||
mermaid>katex: ^0.18.2
|
||||
|
||||
patchedDependencies:
|
||||
'@codemirror/view': 0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
@@ -61,7 +64,7 @@ importers:
|
||||
version: 6.7.6
|
||||
'@codemirror/view':
|
||||
specifier: ^6.43.14
|
||||
version: 6.43.14
|
||||
version: 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@floating-ui/react-dom':
|
||||
specifier: ^2.1.9
|
||||
version: 2.1.9([email protected]([email protected]))([email protected])
|
||||
@@ -85,7 +88,7 @@ importers:
|
||||
version: 1.2.0
|
||||
'@replit/codemirror-vim':
|
||||
specifier: 6.4.0
|
||||
version: 6.4.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])
|
||||
version: 6.4.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected](patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5))
|
||||
'@tanstack/react-virtual':
|
||||
specifier: ^3.14.21
|
||||
version: 3.14.21([email protected]([email protected]))([email protected])
|
||||
@@ -591,7 +594,6 @@ packages:
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
cpu: [riscv64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@oxc-parser/[email protected]':
|
||||
resolution: {integrity: sha512-JSlhgoK+/g1TGJI5NuADx2+6syhxnQNLCWLXyO5QLFyetomcr/vIxSdiNlmyAv963YXUzCuwAwRG6npZ5xyJ1A==}
|
||||
@@ -1069,7 +1071,6 @@ packages:
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
'@rolldown/[email protected]':
|
||||
resolution: {integrity: sha512-4+Kl8daPV8NDHaD7mfCcc1pRM+Qg7ab8DyMm5FG5WoZgv4h2i3KFN1CybYBNbQqmuYm7ftJLvmMI1eHYJ22S/Q==}
|
||||
@@ -1083,14 +1084,12 @@ packages:
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
cpu: [s390x]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@rolldown/[email protected]':
|
||||
resolution: {integrity: sha512-WxalXzgrLVpKC93xfpaJ3gCXUWzeCr+FRCbDVD2mUAy4L6Vo3lNVz0epUEUpxPWJkLNYUwM4OSIikv36OJ9mLg==}
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@rolldown/[email protected]':
|
||||
resolution: {integrity: sha512-3G3tnAmTpdk9jO3GQtyHXqeFD2SlecfTws/Y3M2mmj9nMBwwuLT4kur8sZKeu7ENUHSpVO3cIsm5A52LEWWwlg==}
|
||||
@@ -1864,7 +1863,6 @@ packages:
|
||||
engines: {node: '>= 12.0.0'}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==}
|
||||
@@ -1878,14 +1876,12 @@ packages:
|
||||
engines: {node: '>= 12.0.0'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==}
|
||||
engines: {node: '>= 12.0.0'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==}
|
||||
@@ -2391,14 +2387,14 @@ snapshots:
|
||||
dependencies:
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/common': 1.5.3
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/common': 1.5.3
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
@@ -2438,7 +2434,7 @@ snapshots:
|
||||
'@codemirror/lang-javascript': 6.2.5
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/common': 1.5.3
|
||||
'@lezer/css': 1.3.9
|
||||
'@lezer/html': 1.3.13
|
||||
@@ -2454,7 +2450,7 @@ snapshots:
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/lint': 6.9.7
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/common': 1.5.3
|
||||
'@lezer/javascript': 1.5.6
|
||||
|
||||
@@ -2464,7 +2460,7 @@ snapshots:
|
||||
'@codemirror/lang-html': 6.4.12
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/common': 1.5.3
|
||||
'@lezer/highlight': 1.2.5
|
||||
'@lezer/lr': 1.4.11
|
||||
@@ -2488,7 +2484,7 @@ snapshots:
|
||||
'@codemirror/lang-html': 6.4.12
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/common': 1.5.3
|
||||
'@lezer/highlight': 1.2.5
|
||||
'@lezer/lr': 1.4.11
|
||||
@@ -2499,7 +2495,7 @@ snapshots:
|
||||
'@codemirror/lang-html': 6.4.12
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/common': 1.5.3
|
||||
'@lezer/markdown': 1.8.0
|
||||
|
||||
@@ -2562,7 +2558,7 @@ snapshots:
|
||||
'@codemirror/autocomplete': 6.20.3
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/common': 1.5.3
|
||||
'@lezer/xml': 1.0.6
|
||||
|
||||
@@ -2606,7 +2602,7 @@ snapshots:
|
||||
dependencies:
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/streamparser': 6.0.0
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/common': 1.5.3
|
||||
'@lezer/highlight': 1.2.5
|
||||
'@lezer/lr': 1.4.11
|
||||
@@ -2619,21 +2615,21 @@ snapshots:
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
crelt: 1.0.7
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@lezer/highlight': 1.2.5
|
||||
style-mod: 4.1.4
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
crelt: 1.0.7
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
@@ -2642,7 +2638,7 @@ snapshots:
|
||||
|
||||
'@codemirror/[email protected]': {}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
'@codemirror/[email protected](patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)':
|
||||
dependencies:
|
||||
'@codemirror/state': 6.7.6
|
||||
crelt: 1.0.7
|
||||
@@ -3105,13 +3101,13 @@ snapshots:
|
||||
|
||||
'@replit/[email protected]': {}
|
||||
|
||||
'@replit/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':
|
||||
'@replit/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected](patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5))':
|
||||
dependencies:
|
||||
'@codemirror/commands': 6.11.1
|
||||
'@codemirror/language': 6.13.1
|
||||
'@codemirror/search': 6.7.2
|
||||
'@codemirror/state': 6.7.6
|
||||
'@codemirror/view': 6.43.14
|
||||
'@codemirror/view': 6.43.14(patch_hash=0ee18e0fe711bd749ccc9f89f3566c74b5e08910f2892e166d207f286b0da0c5)
|
||||
'@replit/codemirror-vim-core': 0.1.0
|
||||
|
||||
'@rolldown/[email protected]':
|
||||
|
||||
@@ -3,3 +3,5 @@ allowBuilds:
|
||||
overrides:
|
||||
# GHSA-238p-pmpm-9mq7 (fixed in 0.18.2); mermaid 12.1 still asks for katex ^0.16.
|
||||
mermaid>katex: ^0.18.2
|
||||
patchedDependencies:
|
||||
"@codemirror/view": patches/@codemirror__view.patch
|
||||
@@ -51,7 +51,9 @@ class CornerInset {
|
||||
|
||||
private measure() {
|
||||
const corner = this.corner;
|
||||
if (!corner) return;
|
||||
// A hidden tab's view is detached and measures 0: keeping the inset spares every line
|
||||
// a restyle when the tab hides and another when it shows again.
|
||||
if (!corner || !this.view.dom.isConnected) return;
|
||||
const width = corner.getBoundingClientRect().width;
|
||||
let inset = width > 0 ? round(width) + CORNER_GAP : 0;
|
||||
// A narrow window or a wide corner: keep at least half of the width for text.
|
||||
|
||||
@@ -20,16 +20,12 @@ import { countColumn, Facet, RangeSetBuilder, type EditorState, type Extension }
|
||||
import { Decoration, EditorView, ViewPlugin, type DecorationSet, type ViewUpdate } from "@codemirror/view";
|
||||
import { getIndentUnit, matchBrackets, syntaxTree } from "@codemirror/language";
|
||||
import { LINE_INSET } from "./lineInset";
|
||||
import { SPACE, spaceWidth } from "./spaceWidth";
|
||||
import { BRACKET_COLORS, LONG_LINE, bracketScanner, type BracketScanner } from "./rainbowBrackets";
|
||||
|
||||
/** How far (px) a guide sits left of its column, so a caret in that column is right of it (IDEA's indent guide shift). */
|
||||
const GUIDE_SHIFT = 2;
|
||||
|
||||
/** One column of indentation: a space in the editor font, as measured by the guides plugin. */
|
||||
const SPACE = "var(--openidea-space, 1ch)";
|
||||
|
||||
const SPACE_SAMPLE = 64;
|
||||
|
||||
/** Number of `--openidea-guide-<n>` rainbow colours; deeper guides repeat them. */
|
||||
export const GUIDE_COLORS = 5;
|
||||
|
||||
@@ -325,37 +321,20 @@ function build(
|
||||
}
|
||||
|
||||
export const indentGuides: Extension = [
|
||||
spaceWidth,
|
||||
ViewPlugin.fromClass(
|
||||
class {
|
||||
decorations: DecorationSet;
|
||||
private probe: HTMLElement;
|
||||
private brackets: BracketCache[] = [];
|
||||
/** Guide variables of each decorated line, by its start: code lens rows above it repeat them. */
|
||||
private lineVars = new Map<number, { images: string; positions: string }>();
|
||||
private scanner: BracketScanner | null;
|
||||
constructor(readonly view: EditorView) {
|
||||
// Inherits the editor font from the scroller, outside the content CodeMirror observes;
|
||||
// the measured width goes on the scroller, where lines and code lens rows pick it up.
|
||||
this.probe = document.createElement("span");
|
||||
this.probe.setAttribute("aria-hidden", "true");
|
||||
this.probe.style.cssText = "position: absolute; top: 0; left: 0; visibility: hidden; white-space: pre";
|
||||
this.probe.textContent = " ".repeat(SPACE_SAMPLE);
|
||||
view.scrollDOM.appendChild(this.probe);
|
||||
const scanner = bracketScanner(view);
|
||||
this.scanner = scanner;
|
||||
this.decorations = build(view, scanner, this.brackets, this.lineVars);
|
||||
this.measure();
|
||||
this.syncLenses();
|
||||
}
|
||||
measure() {
|
||||
this.view.requestMeasure({
|
||||
key: this,
|
||||
read: (view) => this.probe.getBoundingClientRect().width / (view.scaleX || 1) / SPACE_SAMPLE,
|
||||
write: (width, view) => {
|
||||
if (width > 0) view.scrollDOM.style.setProperty("--openidea-space", `${+width.toFixed(3)}px`);
|
||||
},
|
||||
});
|
||||
}
|
||||
/** Gives code lens rows the guides of the line they annotate, once they are in the DOM. */
|
||||
syncLenses() {
|
||||
this.view.requestMeasure({
|
||||
@@ -379,15 +358,12 @@ export const indentGuides: Extension = [
|
||||
});
|
||||
}
|
||||
destroy() {
|
||||
this.probe.remove();
|
||||
this.view.scrollDOM.style.removeProperty("--openidea-space");
|
||||
for (const el of this.view.contentDOM.querySelectorAll<HTMLElement>(".cm-openidea-lens")) {
|
||||
el.style.removeProperty("--openidea-guide-images");
|
||||
el.style.removeProperty("--openidea-guide-positions");
|
||||
}
|
||||
}
|
||||
update(u: ViewUpdate) {
|
||||
if (u.geometryChanged) this.measure();
|
||||
const scanner = bracketScanner(u.view);
|
||||
// A new scanner (rainbow brackets toggled or reconfigured) may colour blocks differently.
|
||||
const bracketsChanged = scanner !== this.scanner;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { registerEditorContribution } from "@/editor/api";
|
||||
import { prewarmEditor } from "./prewarm";
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
it("builds an off-screen editor with embedded contributions only, then removes it", () => {
|
||||
let frame: FrameRequestCallback | undefined;
|
||||
vi.stubGlobal("requestAnimationFrame", (f: FrameRequestCallback) => ((frame = f), 1));
|
||||
const seen: string[] = [];
|
||||
const offEmbedded = registerEditorContribution({
|
||||
id: "test.embedded",
|
||||
embedded: true,
|
||||
extensions: (ctx) => (seen.push(`embedded ${ctx.doc}`), []),
|
||||
});
|
||||
const offFile = registerEditorContribution({
|
||||
id: "test.file",
|
||||
extensions: () => (seen.push("file"), []),
|
||||
});
|
||||
try {
|
||||
prewarmEditor();
|
||||
expect(document.querySelectorAll(".cm-editor")).toHaveLength(1);
|
||||
expect(seen).toEqual(["embedded -1"]);
|
||||
frame!(0);
|
||||
expect(document.querySelector(".cm-editor")).toBeNull();
|
||||
expect(document.body.children).toHaveLength(0);
|
||||
} finally {
|
||||
offEmbedded();
|
||||
offFile();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import { EditorState, type Extension } from "@codemirror/state";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { editorContributions, type EditorDocContext } from "@/editor/api";
|
||||
import { baseExtensions } from "./setup";
|
||||
|
||||
/**
|
||||
* Builds and drops an off-screen editor with the file editors' setup, so the first file opened
|
||||
* does not also pay for compiling the editor code and mounting its stylesheets. The document is
|
||||
* virtual and empty, and only contributions that accept such editors (`embedded`) take part:
|
||||
* nothing reaches a language server or the file system.
|
||||
*/
|
||||
export function prewarmEditor(): void {
|
||||
const host = document.createElement("div");
|
||||
host.setAttribute("aria-hidden", "true");
|
||||
host.style.cssText = "position:fixed;left:-10000px;top:0;width:480px;height:240px;visibility:hidden;contain:strict";
|
||||
document.body.appendChild(host);
|
||||
const ctx: EditorDocContext = {
|
||||
doc: -1,
|
||||
path: "prewarm.txt",
|
||||
language: "plaintext",
|
||||
uiMode: null,
|
||||
readOnly: true,
|
||||
virtual: true,
|
||||
};
|
||||
const contributions: Extension[] = [];
|
||||
for (const c of editorContributions()) {
|
||||
if (!c.embedded) continue;
|
||||
try {
|
||||
contributions.push(c.extensions(ctx));
|
||||
} catch {
|
||||
// Warming is best effort: the real editor reports a failing contribution.
|
||||
}
|
||||
}
|
||||
const view = new EditorView({
|
||||
parent: host,
|
||||
state: EditorState.create({
|
||||
doc: "",
|
||||
extensions: baseExtensions({
|
||||
ctx,
|
||||
settings: undefined,
|
||||
info: undefined,
|
||||
language: null,
|
||||
docLength: 0,
|
||||
indent: { tabSize: 4, insertSpaces: true },
|
||||
wrapOverride: false,
|
||||
contributions,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
// One frame so its measure pass runs too, then nothing of it is left behind.
|
||||
requestAnimationFrame(() => {
|
||||
view.destroy();
|
||||
host.remove();
|
||||
});
|
||||
}
|
||||
@@ -189,7 +189,7 @@ it("indents by the code's character width, so a font size change keeps it in lin
|
||||
const v = open(true, ["class A {", "\t/**", "\t * Books.", "\t */", "\tvoid book() {}", "}"].join("\n"));
|
||||
const body = v.dom.querySelector<HTMLElement>(".cm-openidea-renderedDoc")!;
|
||||
// A tab is a tab size of columns, not one character.
|
||||
expect(body.style.marginLeft).toContain(`${v.state.tabSize} * var(--openidea-doc-char`);
|
||||
expect(body.style.marginLeft).toContain(`${v.state.tabSize} * var(--openidea-space`);
|
||||
});
|
||||
|
||||
it("forgets a flip whose comment is deleted, so the feature turns off again", async () => {
|
||||
|
||||
@@ -61,6 +61,7 @@ import { tx, useI18n } from "@/platform/i18n";
|
||||
import { loadMarkdown, markupToHtml } from "@/editor/lsp/markdown";
|
||||
import { hasContent, renderDoc, type DocComment, type DocStyle, type RenderedDoc } from "./docRender";
|
||||
import { LINE_INSET } from "./lineInset";
|
||||
import { SPACE, spaceWidth } from "./spaceWidth";
|
||||
|
||||
/** The file's default: render its doc comments or not. */
|
||||
export const renderDocComments = Facet.define<boolean, boolean>({
|
||||
@@ -320,9 +321,9 @@ class DocWidget extends WidgetType {
|
||||
const titles = doc.sections.map(sectionTitle);
|
||||
const dom = document.createElement("div");
|
||||
dom.className = "cm-openidea-renderedDoc";
|
||||
// In the code's character width, which `docMetrics` keeps current: the DOM stays
|
||||
// right through a font size change or zoom, which does not draw the widget again.
|
||||
const left = `(${this.indent} * var(--openidea-doc-char, 1ch) + ${LINE_INSET}px)`;
|
||||
// In columns of the code's font (`spaceWidth`): the DOM stays right through a font
|
||||
// size change or zoom, which does not draw the widget again.
|
||||
const left = `(${this.indent} * ${SPACE} + ${LINE_INSET}px)`;
|
||||
dom.style.marginLeft = `calc${left}`;
|
||||
// The content is as wide as its longest line; the comment wraps at the visible width instead.
|
||||
dom.style.maxWidth = `calc(var(--openidea-doc-width, 100%) - ${left} - ${DOC_RIGHT_GAP}px)`;
|
||||
@@ -827,12 +828,10 @@ export function toggleRenderedViewAtCaret(view: EditorView): boolean {
|
||||
const DOC_RIGHT_GAP = 24;
|
||||
|
||||
/**
|
||||
* Publishes on the content the visible width of the text area, `--openidea-doc-width`,
|
||||
* and the code's character width, `--openidea-doc-char`. A block widget is as wide as
|
||||
* the content, which without soft wraps is as wide as the longest line, so a rendered
|
||||
* comment needs the first to wrap where the reader can see, as IDEA's does; it indents
|
||||
* by the second, which a font size change or zoom changes. Horizontal scrolling leaves
|
||||
* both unchanged.
|
||||
* Publishes on the content the visible width of the text area, `--openidea-doc-width`.
|
||||
* A block widget is as wide as the content, which without soft wraps is as wide as the
|
||||
* longest line, so a rendered comment needs it to wrap where the reader can see.
|
||||
* Scrolling leaves it unchanged, so lines are not restyled while scrolling.
|
||||
*/
|
||||
const docMetrics = ViewPlugin.fromClass(
|
||||
class {
|
||||
@@ -845,18 +844,12 @@ const docMetrics = ViewPlugin.fromClass(
|
||||
measure() {
|
||||
this.view.requestMeasure({
|
||||
key: this,
|
||||
read: (view) => ({
|
||||
width: view.scrollDOM.clientWidth - view.contentDOM.offsetLeft,
|
||||
char: view.defaultCharacterWidth,
|
||||
}),
|
||||
write: ({ width, char }, view) => {
|
||||
read: (view) => view.scrollDOM.clientWidth - view.contentDOM.offsetLeft,
|
||||
write: (width, view) => {
|
||||
const style = view.contentDOM.style;
|
||||
const widthValue = `${Math.max(0, Math.floor(width))}px`;
|
||||
if (style.getPropertyValue("--openidea-doc-width") !== widthValue)
|
||||
style.setProperty("--openidea-doc-width", widthValue);
|
||||
const charValue = `${char}px`;
|
||||
if (style.getPropertyValue("--openidea-doc-char") !== charValue)
|
||||
style.setProperty("--openidea-doc-char", charValue);
|
||||
const value = `${Math.max(0, Math.floor(width))}px`;
|
||||
if (style.getPropertyValue("--openidea-doc-width") !== value)
|
||||
style.setProperty("--openidea-doc-width", value);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -947,5 +940,6 @@ export const renderedDocsExtension: Extension = [
|
||||
markdownReady,
|
||||
languageWatcher,
|
||||
docMetrics,
|
||||
spaceWidth,
|
||||
docsTheme,
|
||||
];
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* The editor font's space width, published on the scroller as `--openidea-space`
|
||||
* for anything laid out in columns of indentation (indent guides, code lens rows,
|
||||
* rendered doc comments). A space is measured, not `ch`: in a proportional font it
|
||||
* is narrower than "0". The probe's text is fixed, so the value only changes with
|
||||
* the font, its size or zoom; `defaultCharacterWidth` is sampled from whichever
|
||||
* line is in view and drifts while scrolling, and an inherited variable that
|
||||
* changes restyles every line.
|
||||
*/
|
||||
import { EditorView, ViewPlugin, type ViewUpdate } from "@codemirror/view";
|
||||
|
||||
/** One column of indentation, as a CSS length. */
|
||||
export const SPACE = "var(--openidea-space, 1ch)";
|
||||
|
||||
const SAMPLE = 64;
|
||||
|
||||
/** Shared by every extension that lays out by `SPACE`; CodeMirror installs it once. */
|
||||
export const spaceWidth = ViewPlugin.fromClass(
|
||||
class {
|
||||
private probe: HTMLElement;
|
||||
private written = "";
|
||||
constructor(readonly view: EditorView) {
|
||||
// Inherits the editor font from the scroller, outside the content CodeMirror observes.
|
||||
this.probe = document.createElement("span");
|
||||
this.probe.setAttribute("aria-hidden", "true");
|
||||
this.probe.style.cssText = "position: absolute; top: 0; left: 0; visibility: hidden; white-space: pre";
|
||||
this.probe.textContent = " ".repeat(SAMPLE);
|
||||
view.scrollDOM.appendChild(this.probe);
|
||||
this.measure();
|
||||
}
|
||||
measure() {
|
||||
this.view.requestMeasure({
|
||||
key: this,
|
||||
read: (view) => this.probe.getBoundingClientRect().width / (view.scaleX || 1) / SAMPLE,
|
||||
write: (width, view) => {
|
||||
const value = `${+width.toFixed(3)}px`;
|
||||
if (width <= 0 || value === this.written) return;
|
||||
this.written = value;
|
||||
view.scrollDOM.style.setProperty("--openidea-space", value);
|
||||
},
|
||||
});
|
||||
}
|
||||
update(u: ViewUpdate) {
|
||||
if (u.geometryChanged) this.measure();
|
||||
}
|
||||
destroy() {
|
||||
this.probe.remove();
|
||||
this.view.scrollDOM.style.removeProperty("--openidea-space");
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -61,6 +61,20 @@ export interface Reveal {
|
||||
const KEPT_VIEWS = 8;
|
||||
const keptSlots: EditorSlot[] = [];
|
||||
|
||||
/**
|
||||
* Holds the visible tabs' tooltip layers. A layer added to `document.body` itself on every
|
||||
* tab switch would change which element is the body's last child, and Chromium then
|
||||
* restyles the whole workbench (`:last-child` rules); inside this host it restyles nothing else.
|
||||
*/
|
||||
let tooltipHost: HTMLElement | null = null;
|
||||
function tooltipHostElement(): HTMLElement {
|
||||
if (!tooltipHost?.isConnected) {
|
||||
tooltipHost = document.createElement("div");
|
||||
document.body.appendChild(tooltipHost);
|
||||
}
|
||||
return tooltipHost;
|
||||
}
|
||||
|
||||
export class EditorSlot {
|
||||
private stored: EditorState;
|
||||
private historyTarget: WorkspaceHistoryTarget;
|
||||
@@ -70,7 +84,7 @@ export class EditorSlot {
|
||||
/** The view kept, detached from the document, while the tab is hidden. */
|
||||
private kept: EditorView | null = null;
|
||||
/**
|
||||
* The tab's tooltips (hints, hover, completion…). They live outside the view, in `document.body`,
|
||||
* The tab's tooltips (hints, hover, completion…). They live outside the view, under `document.body`,
|
||||
* so they leave the page with the view when the tab is hidden instead of floating over the next tab.
|
||||
*/
|
||||
private readonly tooltipLayer = typeof document === "undefined" ? null : document.createElement("div");
|
||||
@@ -207,7 +221,7 @@ export class EditorSlot {
|
||||
|
||||
mount(parent: HTMLElement): EditorView {
|
||||
if (this.view) return this.view;
|
||||
if (this.tooltipLayer && !this.tooltipLayer.isConnected) document.body.appendChild(this.tooltipLayer);
|
||||
if (this.tooltipLayer && !this.tooltipLayer.isConnected) tooltipHostElement().appendChild(this.tooltipLayer);
|
||||
const kept = this.kept;
|
||||
let view: EditorView;
|
||||
if (kept) {
|
||||
|
||||
@@ -568,7 +568,8 @@ function EditorTabActions({ paneId, tab }: { paneId: string; tab: Tab }) {
|
||||
anchor={moreRef}
|
||||
placement="bottom-end"
|
||||
aria-label="Tab actions"
|
||||
items={ctrl.tabMenu(paneId, tab)}
|
||||
// Built when shown: every tab render (each open and switch) would otherwise assemble the whole menu.
|
||||
items={open ? ctrl.tabMenu(paneId, tab) : []}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -232,8 +232,10 @@
|
||||
.conversationRow[data-measured] {
|
||||
content-visibility: auto;
|
||||
}
|
||||
/* Keep turns distinct and the work within a turn close to its author. */
|
||||
.stream > * + * {
|
||||
/* Keep turns distinct and the work within a turn close to its author. Not `* + *`: a
|
||||
universal adjacent-sibling rule makes Chromium restyle whole sibling subtrees on every
|
||||
DOM insertion anywhere in the window, which costs every editor scroll frame. */
|
||||
.stream > :where(:not(:first-child)) {
|
||||
margin-top: var(--space-4);
|
||||
}
|
||||
.stream > [data-process] + [data-process] {
|
||||
@@ -336,7 +338,7 @@
|
||||
.agentAuthor > .role {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.agentAuthor + * {
|
||||
:where(.conversationRow[data-author]) > :nth-child(2) {
|
||||
margin-top: calc(var(--space-2) / 2);
|
||||
}
|
||||
.conversationRow > .process,
|
||||
|
||||
@@ -29,7 +29,7 @@ function task(id: string, title: string, cwd: string): AgentTask {
|
||||
}
|
||||
|
||||
/** A turn as agents work: a request, reasoning, a run of tool calls, then a reply with code. */
|
||||
function turn(cwd: string, i: number): AgentEntry[] {
|
||||
function turn(cwd: string, i: number, title: string): AgentEntry[] {
|
||||
const file = (k: number) => `${cwd}/src/orders/Order${(i + k) % 40}.kt`;
|
||||
const tools: AgentEntry[] = Array.from({ length: 10 }, (_, k) => {
|
||||
// Tool titles as agents report them (commands and paths, not UI text).
|
||||
@@ -49,7 +49,8 @@ function turn(cwd: string, i: number): AgentEntry[] {
|
||||
};
|
||||
});
|
||||
// What a user and an agent wrote (conversation content, not UI text).
|
||||
const request = `Turn ${i}: make the order service retry failed payments and cover it with tests`;
|
||||
// Ends with the task's title, so each conversation shown can be told apart.
|
||||
const request = `Turn ${i}: make the order service retry failed payments and cover it with tests (${title})`;
|
||||
const reasoning = `The payment client throws on timeouts; retrying belongs in the service (turn ${i}).`;
|
||||
return [
|
||||
{
|
||||
@@ -94,14 +95,14 @@ function turn(cwd: string, i: number): AgentEntry[] {
|
||||
/** Opens `count` tasks of `turns` turns each (14 entries a turn), the last one shown. */
|
||||
export function openSampleConversations(count: number, turns: number) {
|
||||
const cwd = useProject.getState().project?.root ?? "/";
|
||||
const entries = Array.from({ length: turns }, (_, i) => turn(cwd, i)).flat();
|
||||
const s = useAgents.getState();
|
||||
const tasks = new Map(s.tasks);
|
||||
const all = new Map(s.entries);
|
||||
const ids = Array.from({ length: count }, (_, n) => `sample-${n + 1}`);
|
||||
ids.forEach((id, n) => {
|
||||
tasks.set(id, task(id, `Sample task ${n + 1}`, cwd));
|
||||
all.set(id, entries);
|
||||
const title = `Sample task ${n + 1}`;
|
||||
tasks.set(id, task(id, title, cwd));
|
||||
all.set(id, Array.from({ length: turns }, (_, i) => turn(cwd, i, title)).flat());
|
||||
});
|
||||
useAgents.setState({ tasks, entries: all });
|
||||
for (const id of ids) openTask(id);
|
||||
|
||||
@@ -559,6 +559,7 @@ export function Stream({
|
||||
(row.kind === "entry" && (row.entry.type === "user" || row.entry.type === "agent")) || undefined
|
||||
}
|
||||
data-process={row.kind !== "entry" || row.entry.type !== "user" || undefined}
|
||||
data-author={authorHeaders.has(row.index) || undefined}
|
||||
>
|
||||
{authorHeaders.has(row.index) && (
|
||||
<div className={styles.agentAuthor}>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
flex: none;
|
||||
align-items: center;
|
||||
}
|
||||
.stack > * + * {
|
||||
.stack > :where(:not(:first-child)) {
|
||||
margin-left: calc(var(--overlap) * -1);
|
||||
}
|
||||
.stack > .ringed + .ringed {
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
flex: 1 1 50%;
|
||||
min-width: 0;
|
||||
}
|
||||
.body > * + * {
|
||||
.body > :where(:not(:first-child)) {
|
||||
border-left: 1px solid var(--border);
|
||||
}
|
||||
.hidden {
|
||||
|
||||
@@ -107,6 +107,9 @@ type ResolvedNode = Exclude<MemNode, { kind: "symlink" }>;
|
||||
|
||||
const err = (kind: "notFound" | "alreadyExists" | "invalidInput", message: string) => new IpcError({ kind, message });
|
||||
|
||||
/** Created once: building a collator costs more than sorting a small folder with it. */
|
||||
const naturalOrder = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||
|
||||
/** The tree's own notion (see `isDirEntry`): a folder, or a link to one. */
|
||||
const isFolder = (e: FileEntry) => e.kind === "dir" || (e.kind === "symlink" && e.size === 0);
|
||||
|
||||
@@ -161,13 +164,14 @@ export class MemoryFs implements ProjectFs {
|
||||
const { path, node } = this.resolve(at);
|
||||
if (!node) throw err("notFound", `${path} not found`);
|
||||
if (node.kind !== "dir") throw err("invalidInput", `${at} is not a directory`);
|
||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||
// A child is excluded when its folder is, or when it is itself an excluded path.
|
||||
const inExcluded = [...this.ignored].some((i) => path === i || isInside(path, i));
|
||||
return (
|
||||
this.childrenOf(path)
|
||||
.map((p) => {
|
||||
const c = this.nodes.get(p)!;
|
||||
const name = nameOf(p);
|
||||
const excluded = [...this.ignored].some((i) => p === i || isInside(p, i));
|
||||
const excluded = inExcluded || this.ignored.has(p);
|
||||
if (c.kind === "symlink") {
|
||||
const t = this.resolve(p);
|
||||
return {
|
||||
@@ -195,7 +199,7 @@ export class MemoryFs implements ProjectFs {
|
||||
} satisfies FileEntry;
|
||||
})
|
||||
// Folders first, counting a link to a folder as a folder (the backend's ordering).
|
||||
.sort((a, b) => Number(isFolder(b)) - Number(isFolder(a)) || collator.compare(a.name, b.name))
|
||||
.sort((a, b) => Number(isFolder(b)) - Number(isFolder(a)) || naturalOrder.compare(a.name, b.name))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { useWorkflowSettings } from "@/platform/workflowSettings";
|
||||
import { EmptyState, IconButton, SplitGroup, SplitHandle, SplitPanel, T, Tabs } from "@/ui";
|
||||
import {
|
||||
EmptyState,
|
||||
IconButton,
|
||||
SplitGroup,
|
||||
SplitHandle,
|
||||
SplitPanel,
|
||||
T,
|
||||
Tabs,
|
||||
useFrozenWhileWindowResizes,
|
||||
} from "@/ui";
|
||||
import { copySelectionOnKeyDown } from "@/ui/selectableText";
|
||||
import { spanStyle } from "@/ui/ansi";
|
||||
import clsx from "clsx";
|
||||
@@ -68,6 +77,10 @@ export function GitToolWindow() {
|
||||
const { shown } = useGitTabs();
|
||||
const available = useVcs((s) => s.available);
|
||||
const external = useGitLog((s) => s.logTabs.some((t) => t.id === s.tab && t.readOnly));
|
||||
// The log's rows, graph and branch tree are too much for WebKit to relayout at every step of a
|
||||
// window drag; they follow the window once it stops.
|
||||
const root = useRef<HTMLDivElement>(null);
|
||||
useFrozenWhileWindowResizes(root);
|
||||
if (!available && !external)
|
||||
return (
|
||||
<EmptyState title="Version control is not configured">
|
||||
@@ -76,6 +89,7 @@ export function GitToolWindow() {
|
||||
);
|
||||
return (
|
||||
<div
|
||||
ref={root}
|
||||
className={styles.root}
|
||||
role="tabpanel"
|
||||
id={`openidea-git-panel-${shown}`}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { isIgnoredName } from "./ignoredNames";
|
||||
import { useProject } from "./project";
|
||||
|
||||
const initial = useProject.getState();
|
||||
afterEach(() => useProject.setState(initial, true));
|
||||
|
||||
function withNames(ignoredNames: string[]) {
|
||||
useProject.setState({ settings: { files: { ignoredNames } } } as never);
|
||||
}
|
||||
|
||||
it("matches the defaults by exact name and by wildcard", () => {
|
||||
expect(isIgnoredName(".git")).toBe(true);
|
||||
expect(isIgnoredName("module.pyc")).toBe(true);
|
||||
expect(isIgnoredName("notes.txt~")).toBe(true);
|
||||
expect(isIgnoredName("module.py")).toBe(false);
|
||||
expect(isIgnoredName("pyc")).toBe(false);
|
||||
});
|
||||
|
||||
it("anchors every wildcard and keeps other pattern characters literal", () => {
|
||||
withNames(["*.log", "build?", "a+b.(x)"]);
|
||||
expect(isIgnoredName("server.log")).toBe(true);
|
||||
expect(isIgnoredName("server.log.1")).toBe(false);
|
||||
expect(isIgnoredName("build1")).toBe(true);
|
||||
expect(isIgnoredName("build12")).toBe(false);
|
||||
expect(isIgnoredName("a+b.(x)")).toBe(true);
|
||||
expect(isIgnoredName("aab.x")).toBe(false);
|
||||
});
|
||||
|
||||
it("follows the setting when it changes, and ignores entries with a path", () => {
|
||||
withNames(["dist", "out/*"]);
|
||||
expect(isIgnoredName("dist")).toBe(true);
|
||||
expect(isIgnoredName(".git")).toBe(false);
|
||||
expect(isIgnoredName("out")).toBe(false);
|
||||
withNames([]);
|
||||
expect(isIgnoredName("dist")).toBe(false);
|
||||
});
|
||||
@@ -23,28 +23,40 @@ export const DEFAULT_IGNORED_NAMES: readonly string[] = [
|
||||
"desktop.ini",
|
||||
];
|
||||
|
||||
let cached: { names: readonly string[]; exact: Set<string>; wildcards: RegExp[] } | null = null;
|
||||
interface Compiled {
|
||||
names: readonly string[];
|
||||
exact: Set<string>;
|
||||
suffixes: string[];
|
||||
wildcards: RegExp | null;
|
||||
}
|
||||
|
||||
function compile(names: readonly string[]) {
|
||||
let cached: Compiled | null = null;
|
||||
|
||||
function compile(names: readonly string[]): Compiled {
|
||||
const exact = new Set<string>();
|
||||
const wildcards: RegExp[] = [];
|
||||
const suffixes: string[] = [];
|
||||
const patterns: string[] = [];
|
||||
for (const raw of names) {
|
||||
const n = raw.trim();
|
||||
if (!n || n.includes("/")) continue;
|
||||
if (!/[*?]/.test(n)) exact.add(n);
|
||||
// `*.pyc` (every default pattern): a suffix test, without a regex that retries `.*` at each position.
|
||||
else if (/^\*[^*?]+$/.test(n)) suffixes.push(n.slice(1));
|
||||
else {
|
||||
const body = n
|
||||
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
||||
.replace(/\*/g, ".*")
|
||||
.replace(/\?/g, ".");
|
||||
wildcards.push(new RegExp(`^${body}$`, "s"));
|
||||
patterns.push(body);
|
||||
}
|
||||
}
|
||||
return { names, exact, wildcards };
|
||||
// One alternation: a folder of thousands of entries tests each name once, not once per pattern.
|
||||
const wildcards = patterns.length ? new RegExp(`^(?:${patterns.join("|")})$`, "s") : null;
|
||||
return { names, exact, suffixes, wildcards };
|
||||
}
|
||||
|
||||
export function isIgnoredName(name: string): boolean {
|
||||
const names = useProject.getState().settings?.files?.ignoredNames ?? DEFAULT_IGNORED_NAMES;
|
||||
const m = cached?.names === names ? cached : (cached = compile(names));
|
||||
return m.exact.has(name) || m.wildcards.some((re) => re.test(name));
|
||||
return m.exact.has(name) || m.suffixes.some((s) => name.endsWith(s)) || !!m.wildcards?.test(name);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// @vitest-environment node
|
||||
/**
|
||||
* Selectors that make Chromium restyle whole subtrees on unrelated DOM changes. Blink checks a
|
||||
* selector whose last part is universal (`*`, or only pseudo-classes) against every element, so:
|
||||
*
|
||||
* - `x > * + *` / `x ~ *` flags every parent as having children styled by their siblings, and any
|
||||
* insertion then restyles the next sibling's whole subtree (an editor scroll inserts lines and
|
||||
* gutters every frame);
|
||||
* - `:focus *` / `:hover ::selection` makes every focus or hover change restyle the subtree of the
|
||||
* element it happens on, wherever that element is;
|
||||
* - `x:not(:focus-within) .y` makes WebKit restyle the whole window on every focus change (write the
|
||||
* default style for `x .y` and override it with `x:focus-within .y`).
|
||||
*
|
||||
* Name the element instead (`x > :not(:first-child)`, `x > .item + .item`, `x:focus .label`).
|
||||
*/
|
||||
import { readdirSync, readFileSync } from "node:fs";
|
||||
import { join, resolve } from "node:path";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
const SRC = resolve(import.meta.dirname, "..");
|
||||
|
||||
function stylesheets(dir: string): string[] {
|
||||
return readdirSync(dir, { withFileTypes: true }).flatMap((e) => {
|
||||
const path = join(dir, e.name);
|
||||
if (e.isDirectory()) return stylesheets(path);
|
||||
return e.name.endsWith(".css") ? [path] : [];
|
||||
});
|
||||
}
|
||||
|
||||
/** A compound selector with no type, class, id or attribute: `*`, `:not(…)`, `::selection`. */
|
||||
const UNIVERSAL = String.raw`(?:\*|(?=:))(?::{1,2}[\w-]+(?:\([^)]*\))?)*`;
|
||||
const SIBLING = new RegExp(String.raw`[+~]\s*${UNIVERSAL}\s*$`);
|
||||
const STATE_DESCENDANT = new RegExp(
|
||||
String.raw`:(?:focus|focus-within|focus-visible|hover|active)[^\s>+~]*[\s>]+${UNIVERSAL}\s*$`,
|
||||
);
|
||||
const NEGATED_STATE = /:not\(:(?:focus|focus-within|focus-visible|hover|active)\)[^\s>+~]*[\s>+~]/;
|
||||
|
||||
it("no selector restyles whole subtrees on sibling insertions or focus changes", () => {
|
||||
const costly: string[] = [];
|
||||
for (const path of stylesheets(SRC)) {
|
||||
const css = readFileSync(path, "utf8").replace(/\/\*[\s\S]*?\*\//g, "");
|
||||
for (const prelude of css.matchAll(/([^{};]+)\{/g)) {
|
||||
const text = prelude[1]!.trim();
|
||||
if (text.startsWith("@")) continue;
|
||||
for (const selector of text.split(/,(?![^(]*\))/)) {
|
||||
const s = selector.trim().replace(/:global\(([^)]*)\)/g, "$1");
|
||||
// Combinators inside `:has(…)` relate other elements, not this one's ancestors.
|
||||
const outer = s.replace(/:has\((?:[^()]|\([^()]*\))*\)/g, "");
|
||||
if (SIBLING.test(s) || STATE_DESCENDANT.test(s) || NEGATED_STATE.test(outer))
|
||||
costly.push(`${path.slice(SRC.length + 1)}: ${s}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(costly).toEqual([]);
|
||||
});
|
||||
@@ -58,10 +58,14 @@
|
||||
.active:hover {
|
||||
background: var(--bg-tree-selected);
|
||||
}
|
||||
/* A focusable list that lost focus shows the inactive selection, like IDEA's JList. */
|
||||
.list[tabindex="0"]:not(:focus-within) .active {
|
||||
/* A focusable list shows the inactive selection until it holds focus. Not `:not(:focus-within)`:
|
||||
WebKit then restyles the whole window on every focus change. */
|
||||
.list[tabindex="0"] .active {
|
||||
background: var(--bg-tree-selected-inactive);
|
||||
}
|
||||
.list[tabindex="0"]:focus-within .active {
|
||||
background: var(--bg-tree-selected);
|
||||
}
|
||||
.section {
|
||||
padding: 0 8px;
|
||||
color: var(--fg-muted);
|
||||
|
||||
@@ -2,11 +2,26 @@
|
||||
import { iconMarkupOrFallback, type IconName } from "./icons";
|
||||
import spinnerStyles from "./Spinner.module.css";
|
||||
|
||||
/** Parsed markup, cloned into each node: widgets rebuild the same few icons on every render. */
|
||||
const parsed = new Map<string, HTMLElement>();
|
||||
|
||||
export function iconNode(name: IconName | (string & {}), size = 16, className?: string): HTMLElement {
|
||||
const span = document.createElement("span");
|
||||
span.className = className ? `cm-openidea-icon ${className}` : "cm-openidea-icon";
|
||||
span.setAttribute("aria-hidden", "true");
|
||||
span.innerHTML = iconMarkupOrFallback(name, size);
|
||||
const markup = iconMarkupOrFallback(name, size);
|
||||
// Markup with ids is unique to this node (ids are never shared): nothing to reuse.
|
||||
if (markup.includes('id="')) {
|
||||
span.innerHTML = markup;
|
||||
return span;
|
||||
}
|
||||
let source = parsed.get(markup);
|
||||
if (!source) {
|
||||
source = document.createElement("span");
|
||||
source.innerHTML = markup;
|
||||
parsed.set(markup, source);
|
||||
}
|
||||
span.append(...Array.from(source.childNodes, (n) => n.cloneNode(true)));
|
||||
return span;
|
||||
}
|
||||
|
||||
|
||||
+21
-2
@@ -21,7 +21,7 @@
|
||||
* - Element ids (clip paths) are made unique per instance: WebKit can't resolve
|
||||
* references into `display: none` subtrees, so ids must never be shared.
|
||||
*/
|
||||
import { useId, useMemo, type CSSProperties } from "react";
|
||||
import { useId, useLayoutEffect, useMemo, useRef, type CSSProperties } from "react";
|
||||
import clsx from "clsx";
|
||||
import { create } from "zustand";
|
||||
import styles from "./icons.module.css";
|
||||
@@ -839,6 +839,20 @@ const EMPTY: Prepared = { viewBox: "0 0 16 16", html: "", hasIds: false, mono: t
|
||||
|
||||
const withIds = (p: Prepared, prefix: string) => (p.hasIds ? p.html.replace(/__ID__/g, prefix) : p.html);
|
||||
|
||||
/** Parsed markup by source, cloned into each icon: a tree or list mounts dozens of the same icon
|
||||
* per frame, and parsing `innerHTML` for each one costs more than the rest of the row. */
|
||||
const parsed = new Map<string, SVGSVGElement>();
|
||||
|
||||
function fillIcon(svg: SVGSVGElement, html: string, shared: boolean) {
|
||||
let source = shared ? parsed.get(html) : undefined;
|
||||
if (!source) {
|
||||
source = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||
source.innerHTML = html;
|
||||
if (shared) parsed.set(html, source);
|
||||
}
|
||||
svg.replaceChildren(...Array.from(source.childNodes, (n) => n.cloneNode(true)));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** Largest `data:` image accepted as an icon (an avatar or a status badge a plugin fetched). */
|
||||
@@ -887,11 +901,17 @@ function SvgIcon({ name, size = 16, className, style, label }: IconProps) {
|
||||
const path = iconPath(name);
|
||||
const p = (path && prepare(path, size >= 18)) || prepare(ICONS.file, size >= 18) || EMPTY;
|
||||
const html = useMemo(() => withIds(p, `i${uid.replace(/[^a-zA-Z0-9_-]/g, "")}-`), [p, uid]);
|
||||
const ref = useRef<SVGSVGElement>(null);
|
||||
useLayoutEffect(() => {
|
||||
// Markup with per-instance ids is unique to this icon: nothing to share.
|
||||
if (ref.current) fillIcon(ref.current, html, !p.hasIds);
|
||||
}, [html, p.hasIds]);
|
||||
if (!path && name.startsWith("symbol-")) {
|
||||
return <SymbolBadge kind={name.slice(7)} className={className} style={style} />;
|
||||
}
|
||||
return (
|
||||
<svg
|
||||
ref={ref}
|
||||
className={clsx(styles.icon, p.mono && styles.mono, className)}
|
||||
style={style}
|
||||
width={size}
|
||||
@@ -902,7 +922,6 @@ function SvgIcon({ name, size = 16, className, style, label }: IconProps) {
|
||||
role={label ? "img" : undefined}
|
||||
aria-label={label}
|
||||
focusable="false"
|
||||
dangerouslySetInnerHTML={{ __html: html }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ export { selectableText, copyMenuFor, copyText } from "./selectableText";
|
||||
export { selectReadingPane, useSelectionBoundary } from "./useSelectionBoundary";
|
||||
export { lockDragCursor, type DragCursor } from "./dragCursor";
|
||||
export { useSanitizedField } from "./useSanitizedField";
|
||||
export { useFrozenWhileWindowResizes } from "./useFrozenWhileWindowResizes";
|
||||
export * from "./rowSelection";
|
||||
export * from "./LogPane";
|
||||
export * from "./Chip";
|
||||
@@ -0,0 +1,52 @@
|
||||
import { act, render } from "@testing-library/react";
|
||||
import { useRef } from "react";
|
||||
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
||||
import { WINDOW_RESIZE_SETTLE_MS, useFrozenWhileWindowResizes } from "./useFrozenWhileWindowResizes";
|
||||
|
||||
function Frozen() {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useFrozenWhileWindowResizes(ref);
|
||||
return (
|
||||
<div data-testid="parent">
|
||||
<div ref={ref} data-testid="view" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => vi.useFakeTimers());
|
||||
afterEach(() => vi.useRealTimers());
|
||||
|
||||
it("keeps the view at its size while the window resizes and releases it once the drag pauses", () => {
|
||||
const { getByTestId } = render(<Frozen />);
|
||||
const view = getByTestId("view");
|
||||
const parent = getByTestId("parent");
|
||||
view.getBoundingClientRect = () => ({ width: 300, height: 120 }) as DOMRect;
|
||||
|
||||
act(() => void window.dispatchEvent(new Event("resize")));
|
||||
expect(view.style.width).toBe("300px");
|
||||
expect(view.style.height).toBe("120px");
|
||||
expect(view.style.flexGrow).toBe("0");
|
||||
expect(parent.style.overflow).toBe("hidden");
|
||||
|
||||
// Still dragging: the size taken at the start stays.
|
||||
view.getBoundingClientRect = () => ({ width: 200, height: 80 }) as DOMRect;
|
||||
act(() => vi.advanceTimersByTime(WINDOW_RESIZE_SETTLE_MS - 1));
|
||||
act(() => void window.dispatchEvent(new Event("resize")));
|
||||
act(() => vi.advanceTimersByTime(WINDOW_RESIZE_SETTLE_MS - 1));
|
||||
expect(view.style.width).toBe("300px");
|
||||
|
||||
act(() => vi.advanceTimersByTime(1));
|
||||
expect(view.style.width).toBe("");
|
||||
expect(view.style.height).toBe("");
|
||||
expect(view.style.flex).toBe("");
|
||||
expect(parent.style.overflow).toBe("");
|
||||
});
|
||||
|
||||
it("releases the view when it unmounts mid-drag", () => {
|
||||
const { getByTestId, unmount } = render(<Frozen />);
|
||||
const parent = getByTestId("parent");
|
||||
act(() => void window.dispatchEvent(new Event("resize")));
|
||||
expect(parent.style.overflow).toBe("hidden");
|
||||
unmount();
|
||||
expect(parent.style.overflow).toBe("");
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import { useEffect, type RefObject } from "react";
|
||||
|
||||
/** How long the window must keep its size before a frozen element follows it. */
|
||||
export const WINDOW_RESIZE_SETTLE_MS = 150;
|
||||
|
||||
/**
|
||||
* While the window is being resized, keeps the element at the size it had when the drag started,
|
||||
* on its own layer and clipped by its parent, then lets it take the new size once the drag pauses.
|
||||
* For dense views that WebKit cannot lay out and paint at every step of a live resize: their pixels
|
||||
* are moved instead of redrawn, so the rest of the window keeps up with the pointer.
|
||||
*/
|
||||
export function useFrozenWhileWindowResizes(ref: RefObject<HTMLElement | null>): void {
|
||||
useEffect(() => {
|
||||
let frozen: { el: HTMLElement; parent: HTMLElement | null; parentOverflow: string } | null = null;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
const release = () => {
|
||||
clearTimeout(timer);
|
||||
if (!frozen) return;
|
||||
const { el, parent, parentOverflow } = frozen;
|
||||
for (const p of ["width", "height", "flex", "will-change"]) el.style.removeProperty(p);
|
||||
if (parent) parent.style.overflow = parentOverflow;
|
||||
frozen = null;
|
||||
};
|
||||
const onResize = () => {
|
||||
const el = ref.current;
|
||||
if (!frozen && el?.isConnected) {
|
||||
const { width, height } = el.getBoundingClientRect();
|
||||
const parent = el.parentElement;
|
||||
frozen = { el, parent, parentOverflow: parent?.style.overflow ?? "" };
|
||||
el.style.setProperty("width", `${width}px`, "important");
|
||||
el.style.setProperty("height", `${height}px`, "important");
|
||||
el.style.setProperty("flex", "none", "important");
|
||||
el.style.setProperty("will-change", "transform");
|
||||
if (parent) parent.style.overflow = "hidden";
|
||||
}
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(release, WINDOW_RESIZE_SETTLE_MS);
|
||||
};
|
||||
window.addEventListener("resize", onResize);
|
||||
return () => {
|
||||
window.removeEventListener("resize", onResize);
|
||||
release();
|
||||
};
|
||||
}, [ref]);
|
||||
}
|
||||
@@ -58,8 +58,23 @@ export function mountWindowRoot(View: ComponentType, { prefetchLazy = false }: {
|
||||
function App() {
|
||||
useEffect(() => {
|
||||
hideSplash();
|
||||
if (!prefetchLazy) return;
|
||||
// The first file opened would otherwise also build the editor setup cold.
|
||||
const warm = () => {
|
||||
if (!document.querySelector(".cm-editor"))
|
||||
void import("./editor/core/cm/prewarm").then((m) => m.prewarmEditor());
|
||||
};
|
||||
const idle =
|
||||
typeof requestIdleCallback === "function"
|
||||
? requestIdleCallback(warm, { timeout: 2000 })
|
||||
: window.setTimeout(warm, 500);
|
||||
// Views split out of the start-up bundle load in the background once the UI is up.
|
||||
if (prefetchLazy) return prefetchLazyComponents();
|
||||
const stopPrefetch = prefetchLazyComponents();
|
||||
return () => {
|
||||
if (typeof cancelIdleCallback === "function") cancelIdleCallback(idle);
|
||||
else window.clearTimeout(idle);
|
||||
stopPrefetch();
|
||||
};
|
||||
}, []);
|
||||
return <View />;
|
||||
}
|
||||
|
||||
Reference in new issue
Заблокувати користувача