Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 8662f341d7 fix(settings): change the local data directory without an open project
The Caches settings were trusted-only, so the welcome window could neither
show the current location nor apply a custom directory. The directory is an
app-wide setting: reading it now runs everywhere, and changing it runs
outside Restricted Mode. The Linux GTK file chooser and the global hotkey
probe had the same gate and failed in the welcome window too.

Fixes #6886
2026-11-30 11:15:30 +08:00
Bert Verhelstтаbertyhell 69cec11761 ci: run the release jobs that read secrets in the release environment (#6873)
The signing keys and tokens are repository secrets, readable by any workflow on any branch, and secrets: inherit hands them all to the called release workflows. The jobs that read a secret other than GITHUB_TOKEN now name environment: release (plugins, plugin-keys, build, server-signatures, mirror, cask). secrets: inherit stays until the secrets move into the environment, so releases build and sign as before; the environment is created on first use with no rules. Refs #6701.

Co-authored-by: bertyhell <[email protected]>
2026-11-30 10:52:02 +08:00
l0ng-ai 6c76cfd316 fix(editor): keep the run gutter from loading the editor preferences (#6912)
runGutter, which the Language smoke loads, imported gutterIconsOn from cm/prefs, pulling about 40 editor modules into the smoke inputs and failing scripts/smoke-paths.test.ts on main. The gutter icon groups and the per-editor appearance override move to cm/localAppearance, which prefs re-exports; the gutter providers import it directly and language-smoke.yml lists the new file.
2026-11-30 10:51:33 +08:00
audichuang 66496221b9 fix(ci): run Language smoke for every language when ide-http changes (#6905)
Since #6893 ide-tools depends on ide-http on macOS, so ide-http is an input of the Language smoke, but the Changes step still listed it as unused and scripts/smoke-paths.test.ts failed on main. Removes ide-http from that list.

Co-authored-by: audichuang <[email protected]>
2026-11-30 10:49:13 +08:00
l0ng-ai e9f3aef5ae fix(markdown): keep the preview painted while scrolling (#6908)
Trackpad scrolling in the Markdown preview could leave a large part of it blank until the next scroll. The preview moves itself on each wheel event with scrollBy, and in WebKit a run of scrollBy calls can leave the compositor at an older, never-painted offset than the page's. Setting scrollTop/scrollLeft keeps them in step; the source editor's large wheel jumps and the diff divider's wheel did the same and now set offsets too.

A fenced code block overflowing by a pixel no longer counts as a vertical scroller, and a nested scroller keeps the wheel only while it can still move in that direction, so scrolling no longer stops over code blocks.
2026-11-30 10:31:45 +08:00
24 змінених файлів з 204 додано та 104 видалено

No files matched your search

+1
Переглянути файл
@@ -21,6 +21,7 @@ concurrency:
jobs:
mirror:
environment: release
runs-on: ubuntu-latest
timeout-minutes: 120
env:
+1
Переглянути файл
@@ -23,6 +23,7 @@ concurrency:
jobs:
cask:
environment: release
runs-on: ubuntu-latest
timeout-minutes: 30
env:
+3 -2
Переглянути файл
@@ -34,6 +34,7 @@ on:
- "src/editor/relatedProviders.ts"
- "src/editor/core/cm/cornerInset.ts"
- "src/editor/core/cm/iconArea.ts"
- "src/editor/core/cm/localAppearance.ts"
- "src/editor/lsp/availability.ts"
- "src/editor/lsp/diagnostics.ts"
- "src/editor/lsp/files.ts"
@@ -106,9 +107,9 @@ jobs:
# SDKs, build tools, the project model, Find Usages candidates, debug stream traces):
# cargo metadata, ide-host's direct deps ide-search/ide-streams and the deps of
# ide-lsp/dap/run/sdk/tools.
unused='^crates/(ide-agent|ide-analysis|ide-android|ide-cli|ide-clipboard|ide-coverage|ide-db|ide-docker|ide-fonts|ide-github|ide-http|ide-mcp|ide-notebook|ide-profiler|ide-scaffold|ide-spell|ide-ssh|ide-vcs|ide-web)/'
unused='^crates/(ide-agent|ide-analysis|ide-android|ide-cli|ide-clipboard|ide-coverage|ide-db|ide-docker|ide-fonts|ide-github|ide-mcp|ide-notebook|ide-profiler|ide-scaffold|ide-spell|ide-ssh|ide-vcs|ide-web)/'
# The workflow's paths, less those handled per language below.
smoke='^(crates/|Cargo\.(toml|lock)$|src/features/(run|debugger|build|build-tools)/|src/platform/|src/workbench/|src/ui/|src/editor/(api|navigationProviders|refactorProviders|relatedProviders|core/cm/(cornerInset|iconArea)|lsp/(availability|diagnostics|files|hint|lsp|positions|snippet))\.ts$|src/bindings\.ts$|src/styles/tokens\.css$|src/test/setup\.ts$|src-tauri/icons/128x128\.png$|smoke/|vite\.config\.ts$|tsconfig\.json$|package\.json$|pnpm-(lock|workspace)\.yaml$|patches/|\.github/workflows/language-smoke\.yml$|\.github/tool-versions\.env$)'
smoke='^(crates/|Cargo\.(toml|lock)$|src/features/(run|debugger|build|build-tools)/|src/platform/|src/workbench/|src/ui/|src/editor/(api|navigationProviders|refactorProviders|relatedProviders|core/cm/(cornerInset|iconArea|localAppearance)|lsp/(availability|diagnostics|files|hint|lsp|positions|snippet))\.ts$|src/bindings\.ts$|src/styles/tokens\.css$|src/test/setup\.ts$|src-tauri/icons/128x128\.png$|smoke/|vite\.config\.ts$|tsconfig\.json$|package\.json$|pnpm-(lock|workspace)\.yaml$|patches/|\.github/workflows/language-smoke\.yml$|\.github/tool-versions\.env$)'
langs=""
while read -r f; do
case "$f" in
+3
Переглянути файл
@@ -19,6 +19,7 @@ env:
jobs:
plugin-keys:
permissions: {}
environment: release
runs-on: ubuntu-latest
outputs:
keys: ${{ steps.keys.outputs.keys }}
@@ -43,6 +44,7 @@ jobs:
contents: write
needs: plugin-keys
name: Build (${{ matrix.name }})
environment: release
env:
OPENIDEA_OFFICIAL_PLUGIN_KEYS: ${{ needs.plugin-keys.outputs.keys }}
strategy:
@@ -227,6 +229,7 @@ jobs:
permissions:
contents: write
needs: server
environment: release
runs-on: ubuntu-latest
steps:
- name: Signing configured
+3
Переглянути файл
@@ -20,6 +20,8 @@ env:
TAG: ${{ github.event.inputs.tag || github.ref_name }}
COMMUNITY_PLUGINS_INDEX: https://github.com/l0ng-ai/openidea-plugins/releases/download/index/index.json
# The jobs that read a signing key or token, here and in the workflows called below, run in
# the `release` environment, which holds those secrets.
jobs:
# Creates (or reuses) one draft release that every platform build uploads into.
create-release:
@@ -96,6 +98,7 @@ jobs:
contents: write
needs: create-release
name: Official plugins
environment: release
runs-on: ubuntu-22.04
env:
SIGNING_KEY: ${{ secrets.PLUGIN_SIGNING_KEY }}
+1 -1
Переглянути файл
@@ -414,7 +414,7 @@ pub fn register(dispatcher: &mut Dispatcher, shell: Arc<WebShellState>) {
});
// Caches & LSP & Web & Workspace & HTTP helpers already available through ide-host dependencies.
dispatcher.add("caches_local_data_info", TrustClass::Trusted, |c| async move {
dispatcher.add("caches_local_data_info", TrustClass::Always, |c| async move {
let current = c.host.local_data_dir.to_string_lossy().into_owned();
Ok(LocalDataInfo {
default_dir: current.clone(),
+5 -3
Переглянути файл
@@ -48,7 +48,8 @@ pub struct LocalDataInfo {
pub env_override: bool,
}
#[desktop_command(trust = trusted)]
/// Read-only, and the welcome window shows it too: no project needed.
#[desktop_command(trust = always)]
#[tauri::command]
#[specta::specta]
pub fn caches_local_data_info(app: AppHandle, state: State<'_, AppState>) -> IdeResult<LocalDataInfo> {
@@ -65,8 +66,9 @@ pub fn caches_local_data_info(app: AppHandle, state: State<'_, AppState>) -> Ide
/// Stores (`Some`) or clears (`None`, an empty string counts) the custom
/// local-data root; with `migrate`, the current tree moves at the next start.
/// Returns the directory that takes effect after a restart. The caller
/// restarts the IDE (see `app_restart`).
#[desktop_command(trust = trusted)]
/// restarts the IDE (see `app_restart`). An app-wide setting, so it works from
/// the welcome window too; a Restricted Mode project window can't change it.
#[desktop_command(trust = outside_restricted)]
#[tauri::command]
#[specta::specta]
pub fn caches_set_local_data_dir(
+4 -3
Переглянути файл
@@ -33,8 +33,9 @@ pub struct GtkPickOptions {
}
/// True when the plugin's dialogs can't be shown here: Linux with no portal service on the session
/// bus (running or activatable) and no `zenity`.
#[desktop_command(trust = trusted)]
/// bus (running or activatable) and no `zenity`. Every window picks files (the welcome
/// window opens projects with it), so no trust check.
#[desktop_command(trust = always)]
#[tauri::command]
#[specta::specta]
pub async fn file_dialog_needs_gtk() -> bool {
@@ -51,7 +52,7 @@ pub async fn file_dialog_needs_gtk() -> bool {
}
/// Shows a GTK file chooser attached to `window`. `None` when the user cancels.
#[desktop_command(trust = trusted)]
#[desktop_command(trust = always)]
#[tauri::command]
#[specta::specta]
pub async fn gtk_pick_paths(window: tauri::Window, options: GtkPickOptions) -> IdeResult<Option<Vec<IpcPath>>> {
+1 -1
Переглянути файл
@@ -11,7 +11,7 @@ use ide_core::IdeResult;
/// Reports which of `combos` (single-stroke `Alt+Shift+R`-style bindings) are
/// already registered to another app. Empty everywhere but Windows.
#[desktop_command(trust = trusted)]
#[desktop_command(trust = always)]
#[tauri::command]
#[specta::specta]
pub fn system_probe_hotkeys(combos: Vec<String>) -> IdeResult<Vec<String>> {
+5 -5
Переглянути файл
@@ -103,9 +103,9 @@ build_compile_file trusted project_host bin
build_model trusted project_host bindings async
build_run trusted project_host bindings async
build_sync trusted project_host bindings async
caches_local_data_info trusted desktop bindings sync
caches_local_data_info always desktop bindings sync
caches_schedule_invalidation always desktop bindings sync
caches_set_local_data_dir trusted desktop bindings sync
caches_set_local_data_dir outside_restricted desktop bindings sync
cancel_request always project_host bindings sync
cancel_task always project_host bindings sync
clear_caches always desktop bindings async
@@ -307,7 +307,7 @@ docker_snapshot trusted project_host bin
docker_volume_sizes trusted project_host bindings async
end_process trusted desktop bindings async
env_reload always project_host bindings async
file_dialog_needs_gtk trusted desktop bindings async
file_dialog_needs_gtk always desktop bindings async
find_dirs always project_host bindings async
find_files always project_host bindings async
find_files_named always project_host bindings async
@@ -359,7 +359,7 @@ gradle_dependencies trusted project_host bin
gradle_link_projects trusted project_host bindings async
gradle_published_catalog trusted project_host bindings async
gradle_unlink_projects trusted project_host bindings async
gtk_pick_paths trusted desktop bindings async
gtk_pick_paths always desktop bindings async
history_content always project_host bindings async
history_list always project_host bindings async
history_list_dir always project_host bindings async
@@ -749,7 +749,7 @@ syntax_node_at always project_host bin
syntax_structural_ranges always project_host bindings async
syntax_support always project_host bindings sync
system_font_families always desktop bindings async
system_probe_hotkeys trusted desktop bindings sync
system_probe_hotkeys always desktop bindings sync
term_attach always project_host bindings async
term_available_shells always project_host bindings sync
term_default_shell always project_host bindings sync
+5 -2
Переглянути файл
@@ -329,6 +329,7 @@ export const commands = {
* Returns the refreshed model; a failed build is reported in its `syncError`.
*/
buildSync: (tool: BuildTool, request: RequestId, offline: boolean, profiles: string[], buildDir: string | null, onProgress: Channel<SyncProgress>) => typedError<BuildModel, IdeError>(__TAURI_INVOKE("build_sync", { tool, request, offline, profiles, buildDir, onProgress })),
/** Read-only, and the welcome window shows it too: no project needed. */
cachesLocalDataInfo: () => typedError<LocalDataInfo, IdeError>(__TAURI_INVOKE("caches_local_data_info")),
/** Schedules the invalidation for the next start (`None` cancels a pending one). */
cachesScheduleInvalidation: (options: {
@@ -343,7 +344,8 @@ export const commands = {
* Stores (`Some`) or clears (`None`, an empty string counts) the custom
* local-data root; with `migrate`, the current tree moves at the next start.
* Returns the directory that takes effect after a restart. The caller
* restarts the IDE (see `app_restart`).
* restarts the IDE (see `app_restart`). An app-wide setting, so it works from
* the welcome window too; a Restricted Mode project window can't change it.
*/
cachesSetLocalDataDir: (path: string | null, migrate: boolean) => typedError<string, IdeError>(__TAURI_INVOKE("caches_set_local_data_dir", { path, migrate })),
cancelRequest: (id: RequestId) => __TAURI_INVOKE<void>("cancel_request", { id }),
@@ -782,7 +784,8 @@ export const commands = {
envReload: () => typedError<EnvReloaded, IdeError>(__TAURI_INVOKE("env_reload")),
/**
* True when the plugin's dialogs can't be shown here: Linux with no portal service on the session
* bus (running or activatable) and no `zenity`.
* bus (running or activatable) and no `zenity`. Every window picks files (the welcome
* window opens projects with it), so no trust check.
*/
fileDialogNeedsGtk: () => __TAURI_INVOKE<boolean>("file_dialog_needs_gtk"),
/** Folders holding indexed files, for `@` references. */
+53
Переглянути файл
@@ -0,0 +1,53 @@
/**
* Gutter icon groups and an editor's local appearance overrides, apart from the editor
* preferences so gutter providers can read them without loading the editor setup.
*/
import { StateEffect, StateField, type EditorState } from "@codemirror/state";
import { editorPrefs, type EditorExtras } from "@/platform/editorSettings";
/**
* Gutter icon groups of Settings › Editor › General › Gutter Icons. A hidden group sets
* `cm-openidea-hideGutter-<id>` on the editor (the theme hides the bookmark, color and
* script/compose run columns by it); the icon area's run and inheritance icons read the
* setting themselves.
*/
export const GUTTER_ICON_GROUPS = [
{ id: "run" },
{ id: "bookmarks" },
{ id: "inheritors" },
{ id: "supers" },
{ id: "colors" },
] as const;
export type GutterIconGroup = (typeof GUTTER_ICON_GROUPS)[number]["id"];
/** The four IDEA decoration switches that can be overridden on one editor. */
export interface EffectiveAppearance {
lineNumbers: boolean;
whitespaces: boolean;
gutterIcons: boolean;
indentGuides: boolean;
}
export type LocalAppearanceKey = keyof EffectiveAppearance;
export type LocalAppearanceOverride = Partial<EffectiveAppearance>;
/** Per-editor decoration overrides live in EditorState, outside the reconfigurable compartments. */
export const setLocalAppearance = StateEffect.define<LocalAppearanceOverride | null>();
export const localAppearanceField = StateField.define<LocalAppearanceOverride | null>({
create: () => null,
update(value, tr) {
for (const effect of tr.effects) if (effect.is(setLocalAppearance)) value = effect.value;
return value;
},
});
/** Gutter providers use the editor's effective value, including a local override. */
export function gutterIconsOn(
state: EditorState | undefined,
group?: GutterIconGroup,
prefs: Pick<EditorExtras, "showGutterIcons" | "gutterIconsDisabled"> = editorPrefs(),
): boolean {
const local = state?.field(localAppearanceField, false)?.gutterIcons;
return (local ?? prefs.showGutterIcons) && (!group || !prefs.gutterIconsDisabled.includes(group));
}
+11 -47
Переглянути файл
@@ -72,6 +72,17 @@ import { LINE_INSET } from "./lineInset";
import { codeLensPositions } from "./codeLens";
import { stickyMove } from "./stickySelection";
import { wheelZoomStep } from "@/platform/wheelZoom";
export {
GUTTER_ICON_GROUPS,
gutterIconsOn,
localAppearanceField,
setLocalAppearance,
type EffectiveAppearance,
type GutterIconGroup,
type LocalAppearanceKey,
type LocalAppearanceOverride,
} from "./localAppearance";
import { GUTTER_ICON_GROUPS, type EffectiveAppearance, type LocalAppearanceOverride } from "./localAppearance";
// --- soft wraps ---------------------------------------------------------------
@@ -586,22 +597,6 @@ const noSurround = EditorView.inputHandler.of((view, from, to, text) => {
return true;
});
/**
* Gutter icon groups of Settings › Editor › General › Gutter Icons. A hidden group sets
* `cm-openidea-hideGutter-<id>` on the editor (the theme hides the bookmark, color and
* script/compose run columns by it); the icon area's run and inheritance icons read the
* setting themselves.
*/
export const GUTTER_ICON_GROUPS = [
{ id: "run" },
{ id: "bookmarks" },
{ id: "inheritors" },
{ id: "supers" },
{ id: "colors" },
] as const;
export type GutterIconGroup = (typeof GUTTER_ICON_GROUPS)[number]["id"];
/**
* Languages whose outer parser is `@lezer/html`, plus JSX / TSX, where
* simultaneous `<tag></tag>` editing works from the syntax tree. Angular
@@ -619,37 +614,6 @@ const LINKED_TAG_LANGUAGES = new Set([
"javascriptreact",
]);
/** The four IDEA decoration switches that can be overridden on one editor. */
export interface EffectiveAppearance {
lineNumbers: boolean;
whitespaces: boolean;
gutterIcons: boolean;
indentGuides: boolean;
}
export type LocalAppearanceKey = keyof EffectiveAppearance;
export type LocalAppearanceOverride = Partial<EffectiveAppearance>;
/** Per-editor decoration overrides live in EditorState, outside the reconfigurable compartments. */
export const setLocalAppearance = StateEffect.define<LocalAppearanceOverride | null>();
export const localAppearanceField = StateField.define<LocalAppearanceOverride | null>({
create: () => null,
update(value, tr) {
for (const effect of tr.effects) if (effect.is(setLocalAppearance)) value = effect.value;
return value;
},
});
/** Gutter providers use the editor's effective value, including a local override. */
export function gutterIconsOn(
state: EditorState | undefined,
group?: GutterIconGroup,
prefs: Pick<EditorExtras, "showGutterIcons" | "gutterIconsDisabled"> = editorPrefs(),
): boolean {
const local = state?.field(localAppearanceField, false)?.gutterIcons;
return (local ?? prefs.showGutterIcons) && (!group || !prefs.gutterIconsDisabled.includes(group));
}
/** Editor settings values after applying this editor's optional local overrides. */
export function effectiveAppearance(
prefs: EditorExtras,
+1 -1
Переглянути файл
@@ -18,7 +18,7 @@
import { RangeSet, StateEffect, StateField, type EditorState, type Extension, type Text } from "@codemirror/state";
import { EditorView, GutterMarker, ViewPlugin, type ViewUpdate } from "@codemirror/view";
import { iconAreaSource, mapLineStart } from "@/editor/core/cm/iconArea";
import { gutterIconsOn, localAppearanceField } from "@/editor/core/cm/prefs";
import { gutterIconsOn, localAppearanceField } from "@/editor/core/cm/localAppearance";
import { isLibrarySource, shownAgain, type EditorDocContext } from "@/editor/api";
import { docOf, debounce, isUnavailable, lspRequest } from "@/editor/lsp/lsp";
import { featureBackoff, onServerSettled } from "@/editor/lsp/availability";
+1 -1
Переглянути файл
@@ -15,7 +15,7 @@ import {
} from "@/editor/api";
import { onServerSettled } from "@/editor/lsp/availability";
import { comparePos } from "@/editor/lsp/positions";
import { gutterIconsOn, localAppearanceField } from "@/editor/core/cm/prefs";
import { gutterIconsOn, localAppearanceField } from "@/editor/core/cm/localAppearance";
import { editorPrefs } from "@/platform/editorSettings";
import { call, commands, type DocumentColor } from "@/platform/ipc";
import { useProject } from "@/platform/project";
+1 -1
Переглянути файл
@@ -7,7 +7,7 @@
import { RangeSet, StateEffect, StateField, type Extension } from "@codemirror/state";
import { EditorView, GutterMarker, ViewPlugin, type ViewUpdate } from "@codemirror/view";
import { iconAreaSource, rangeToOffsets, registerEditorContribution } from "@/editor/api";
import { gutterIconsOn, localAppearanceField } from "@/editor/core/cm/prefs";
import { gutterIconsOn, localAppearanceField } from "@/editor/core/cm/localAppearance";
import { useProject } from "@/platform/project";
import type { FileMarkers, IndexedMarker, Location } from "@/platform/ipc";
import { markerIcon } from "./lineMarkerGutter";
+1 -1
Переглянути файл
@@ -7,7 +7,7 @@
import { RangeSet, StateEffect, StateField, type EditorState, type Extension } from "@codemirror/state";
import { EditorView, GutterMarker, ViewPlugin, type ViewUpdate } from "@codemirror/view";
import { iconAreaSource, mapLineStart, type EditorDocContext } from "@/editor/api";
import { gutterIconsOn } from "@/editor/core/cm/prefs";
import { gutterIconsOn } from "@/editor/core/cm/localAppearance";
import { useProject } from "@/platform/project";
import { isVirtualUri } from "@/platform/virtualDocs";
import { shortcutLabel } from "@/platform/keymap";
+1 -1
Переглянути файл
@@ -6,7 +6,7 @@
import { RangeSet, StateEffect, StateField, type EditorState, type Extension } from "@codemirror/state";
import { EditorView, GutterMarker, ViewPlugin, type ViewUpdate } from "@codemirror/view";
import { iconAreaSource, mapLineStart, type EditorDocContext } from "@/editor/api";
import { gutterIconsOn } from "@/editor/core/cm/prefs";
import { gutterIconsOn } from "@/editor/core/cm/localAppearance";
import { executeAction } from "@/platform/actions";
import { useProject } from "@/platform/project";
import { gutterIconMarkup, showContextMenu, type MenuItem } from "@/ui";
+38 -22
Переглянути файл
@@ -207,6 +207,9 @@ describe("synchronized navigation scrolling", () => {
});
describe("wheel over a pane that cannot scroll further", () => {
const movedBy = new WeakMap<Element, ReturnType<typeof vi.fn>>();
const moved = (view: EditorView) => movedBy.get(view.scrollDOM)!;
let wheeling = false;
// Lines deleted at the end: the left pane is long, the right one fits without scrolling.
// `lead` lines come above those in the left pane only.
function panes(sync = true, { left = 200, right = 25, lead = 0 } = {}) {
@@ -220,9 +223,17 @@ describe("wheel over a pane that cannot scroll further", () => {
const scrollDOM = dom.appendChild(document.createElement("div"));
Object.defineProperty(scrollDOM, "scrollHeight", { value: lines * LINE });
Object.defineProperty(scrollDOM, "clientHeight", { value: 500 });
scrollDOM.scrollBy = vi.fn((_x: number, y: number) => {
scrollDOM.scrollTop = Math.max(0, Math.min(scrollDOM.scrollTop + y, lines * LINE - 500));
}) as unknown as typeof scrollDOM.scrollBy;
// A scroll made while handling a wheel is recorded as the distance asked for; any is clamped to the pane.
const moved = vi.fn();
let top = 0;
Object.defineProperty(scrollDOM, "scrollTop", {
get: () => top,
set: (to: number) => {
if (wheeling) moved(0, to - top);
top = Math.max(0, Math.min(to, lines * LINE - 500));
},
});
movedBy.set(scrollDOM, moved);
return {
dom,
scrollDOM,
@@ -243,7 +254,12 @@ describe("wheel over a pane that cannot scroll further", () => {
controller.attach({ a, b, chunks: Chunk.build(a.state.doc, b.state.doc) } as unknown as MergeView);
const wheel = (el: Element, deltaY: number, deltaMode = 0, init: WheelEventInit = {}) => {
const e = new WheelEvent("wheel", { deltaY, deltaMode, cancelable: true, ...init });
el.dispatchEvent(e);
wheeling = true;
try {
el.dispatchEvent(e);
} finally {
wheeling = false;
}
return e.defaultPrevented;
};
return { a, b, controller, wheel, divider: root.querySelector(".cm-diffDivider")! };
@@ -254,13 +270,13 @@ describe("wheel over a pane that cannot scroll further", () => {
const p = panes();
try {
expect(p.wheel(p.b.scrollDOM, 120)).toBe(false);
expect(p.a.scrollDOM.scrollBy).toHaveBeenLastCalledWith(0, 120);
expect(moved(p.a)).toHaveBeenLastCalledWith(0, 120);
p.wheel(p.divider, 80);
expect(p.a.scrollDOM.scrollBy).toHaveBeenLastCalledWith(0, 80);
expect(moved(p.a)).toHaveBeenLastCalledWith(0, 80);
// The left pane can still scroll down itself: nothing is passed on.
vi.mocked(p.b.scrollDOM.scrollBy).mockClear();
moved(p.b).mockClear();
p.wheel(p.a.scrollDOM, 120);
expect(p.b.scrollDOM.scrollBy).not.toHaveBeenCalled();
expect(moved(p.b)).not.toHaveBeenCalled();
} finally {
p.controller.destroy();
frame.mockRestore();
@@ -272,7 +288,7 @@ describe("wheel over a pane that cannot scroll further", () => {
const p = panes(true, { left: 25, right: 200 });
try {
expect(p.wheel(p.a.scrollDOM, 120)).toBe(false);
expect(p.b.scrollDOM.scrollBy).toHaveBeenLastCalledWith(0, 120);
expect(moved(p.b)).toHaveBeenLastCalledWith(0, 120);
p.b.scrollDOM.dispatchEvent(new Event("scroll"));
expect(p.b.scrollDOM.scrollTop).toBe(120);
} finally {
@@ -290,11 +306,11 @@ describe("wheel over a pane that cannot scroll further", () => {
expect(p.a.scrollDOM.scrollTop).toBe(3000);
// The right pane can't scroll at all: the left one comes back by the wheel's own distance.
expect(p.wheel(p.b.scrollDOM, -3, WheelEvent.DOM_DELTA_LINE)).toBe(false);
expect(p.a.scrollDOM.scrollBy).toHaveBeenLastCalledWith(0, -3 * LINE);
expect(moved(p.a)).toHaveBeenLastCalledWith(0, -3 * LINE);
p.a.scrollDOM.dispatchEvent(new Event("scroll"));
expect(p.a.scrollDOM.scrollTop).toBe(3000 - 3 * LINE);
p.wheel(p.divider, -80);
expect(p.a.scrollDOM.scrollBy).toHaveBeenLastCalledWith(0, -80);
expect(moved(p.a)).toHaveBeenLastCalledWith(0, -80);
p.a.scrollDOM.dispatchEvent(new Event("scroll"));
expect(p.a.scrollDOM.scrollTop).toBe(3000 - 3 * LINE - 80);
} finally {
@@ -311,9 +327,9 @@ describe("wheel over a pane that cannot scroll further", () => {
p.a.scrollDOM.dispatchEvent(new Event("scroll"));
p.a.scrollDOM.scrollTop = 2000;
p.a.scrollDOM.dispatchEvent(new Event("scroll"));
vi.mocked(p.a.scrollDOM.scrollBy).mockClear();
moved(p.a).mockClear();
expect(p.wheel(p.b.scrollDOM, -120)).toBe(false);
expect(p.a.scrollDOM.scrollBy).toHaveBeenLastCalledWith(0, -120);
expect(moved(p.a)).toHaveBeenLastCalledWith(0, -120);
} finally {
p.controller.destroy();
frame.mockRestore();
@@ -334,12 +350,12 @@ describe("wheel over a pane that cannot scroll further", () => {
p.b.scrollDOM.dispatchEvent(new Event("scroll"));
p.a.scrollDOM.dispatchEvent(new Event("scroll"));
expect(p.a.scrollDOM.scrollTop).toBeCloseTo(p.b.scrollDOM.scrollTop);
vi.mocked(p.a.scrollDOM.scrollBy).mockClear();
moved(p.a).mockClear();
expect(p.wheel(p.b.scrollDOM, -120)).toBe(false);
// Elsewhere again, by something other than a wheel passed on.
p.a.scrollDOM.scrollTop = 3000;
expect(p.wheel(p.b.scrollDOM, -120)).toBe(false);
expect(p.a.scrollDOM.scrollBy).not.toHaveBeenCalled();
expect(moved(p.a)).not.toHaveBeenCalled();
} finally {
p.controller.destroy();
frame.mockRestore();
@@ -360,7 +376,7 @@ describe("wheel over a pane that cannot scroll further", () => {
}
// The pointer moves to the left pane, which can still scroll: the wheel is its own.
expect(p.wheel(p.a.scrollDOM, 120)).toBe(false);
expect(p.b.scrollDOM.scrollBy).not.toHaveBeenCalled();
expect(moved(p.b)).not.toHaveBeenCalled();
expect(p.a.scrollDOM.scrollTop).toBe(mapped + 480);
} finally {
p.controller.destroy();
@@ -380,7 +396,7 @@ describe("wheel over a pane that cannot scroll further", () => {
expect(p.a.scrollDOM.scrollTop).toBe(mapped + 100);
// A wheel longer than what is left: the left pane stops where the right one will map it.
p.wheel(p.b.scrollDOM, -120);
expect(p.a.scrollDOM.scrollBy).toHaveBeenLastCalledWith(0, -220);
expect(moved(p.a)).toHaveBeenLastCalledWith(0, -220);
p.b.scrollDOM.scrollTop -= 120; // the native scroll
p.b.scrollDOM.dispatchEvent(new Event("scroll"));
p.a.scrollDOM.dispatchEvent(new Event("scroll"));
@@ -399,8 +415,8 @@ describe("wheel over a pane that cannot scroll further", () => {
try {
for (let i = 0; i < 3; i++) expect(p.wheel(p.b.scrollDOM, 120)).toBe(false);
expect(p.wheel(p.divider, 120)).toBe(true);
expect(p.b.scrollDOM.scrollBy).toHaveBeenLastCalledWith(0, 120);
expect(p.a.scrollDOM.scrollBy).not.toHaveBeenCalled();
expect(moved(p.b)).toHaveBeenLastCalledWith(0, 120);
expect(moved(p.a)).not.toHaveBeenCalled();
} finally {
p.controller.destroy();
frame.mockRestore();
@@ -417,7 +433,7 @@ describe("wheel over a pane that cannot scroll further", () => {
expect(p.b.scrollDOM.scrollLeft).toBe(40);
expect(p.a.scrollDOM.scrollLeft).toBe(40);
p.wheel(p.b.scrollDOM, 120, 0, { shiftKey: true });
expect(p.a.scrollDOM.scrollBy).not.toHaveBeenCalled();
expect(moved(p.a)).not.toHaveBeenCalled();
} finally {
p.controller.destroy();
frame.mockRestore();
@@ -429,7 +445,7 @@ describe("wheel over a pane that cannot scroll further", () => {
const p = panes();
try {
expect(p.wheel(p.b.scrollDOM, 120, 0, { deltaX: 10 })).toBe(false);
expect(p.a.scrollDOM.scrollBy).toHaveBeenLastCalledWith(0, 120);
expect(moved(p.a)).toHaveBeenLastCalledWith(0, 120);
p.a.scrollDOM.dispatchEvent(new Event("scroll"));
p.b.scrollDOM.scrollLeft = 10; // the native horizontal scroll
p.b.scrollDOM.dispatchEvent(new Event("scroll"));
@@ -530,7 +546,7 @@ describe("wheel over a pane that cannot scroll further", () => {
p.wheel(p.b.scrollDOM, 120);
p.a.scrollDOM.scrollTop = 3000;
p.wheel(p.b.scrollDOM, -120);
expect(p.a.scrollDOM.scrollBy).not.toHaveBeenCalled();
expect(moved(p.a)).not.toHaveBeenCalled();
} finally {
p.controller.destroy();
frame.mockRestore();
+5 -2
Переглянути файл
@@ -503,7 +503,10 @@ export class UnalignedPanes implements DiffPanes {
this.interruptScroll();
this.leadWheel("b");
this.passOn("b", e);
mv.b.scrollDOM.scrollBy(e.deltaX, e.deltaY);
// Offsets rather than scrollBy, which can leave WebKit's compositor at a stale, unpainted offset.
const scroller = mv.b.scrollDOM;
scroller.scrollLeft += e.deltaX;
scroller.scrollTop += e.deltaY;
};
this.divider.addEventListener("wheel", onWheel, { passive: false });
this.cleanup.push(() => this.divider.removeEventListener("wheel", onWheel));
@@ -616,7 +619,7 @@ export class UnalignedPanes implements DiffPanes {
const room = dy > 0 ? el.scrollHeight - el.clientHeight - el.scrollTop : el.scrollTop;
const scroll = (by: number, dir: number) => {
const before = other.scrollTop;
other.scrollBy(0, by);
other.scrollTop += by;
if (other.scrollTop !== before) this.passed[to] = { top: other.scrollTop, dir };
};
const passed = this.passed[to];
+10 -3
Переглянути файл
@@ -865,17 +865,24 @@ function MarkdownPreview({ path, tabId, sync }: { path: string; tabId: string; s
const max = root.scrollHeight - root.clientHeight;
if (max <= root.clientHeight || (e.deltaY > 0 ? root.scrollTop >= max : root.scrollTop <= 0)) return;
for (let el = e.target instanceof Element ? e.target : null; el && el !== root; el = el.parentElement) {
if (el.scrollHeight <= el.clientHeight && (!e.deltaX || el.scrollWidth <= el.clientWidth)) continue;
// A code block's last line can overflow it by a pixel; that doesn't make it a vertical scroller.
const vertical =
el.scrollHeight - el.clientHeight > 1 &&
(e.deltaY > 0 ? el.scrollTop + el.clientHeight < el.scrollHeight - 1 : el.scrollTop > 0);
if (!vertical && (!e.deltaX || el.scrollWidth <= el.clientWidth)) continue;
const style = getComputedStyle(el);
if (
(el.scrollHeight > el.clientHeight && /^(auto|scroll)$/.test(style.overflowY)) ||
(vertical && /^(auto|scroll)$/.test(style.overflowY)) ||
(e.deltaX && el.scrollWidth > el.clientWidth && /^(auto|scroll)$/.test(style.overflowX))
)
return;
}
// WebKit decides on the first wheel event whether it can scroll ahead of paint for the entire gesture.
e.preventDefault();
root.scrollBy(e.deltaX, e.deltaY);
// Set the offsets rather than scrollBy: WebKit's compositor can fall behind a run of
// scrollBy calls and show a stale offset whose content was never painted.
root.scrollLeft += e.deltaX;
root.scrollTop += e.deltaY;
};
root.addEventListener("wheel", onPreviewWheel, { passive: false });
root.addEventListener("wheel", onWheel, { capture: true, passive: false });
+11 -3
Переглянути файл
@@ -95,8 +95,13 @@ describe("Markdown source scroll", () => {
vi.spyOn(view, "viewportLineBlocks", "get").mockReturnValue([block]);
const measure = vi.spyOn(view, "requestMeasure").mockImplementation(() => {});
const lineAtHeight = vi.spyOn(view, "lineBlockAtHeight").mockReturnValue(block);
const scrollBy = vi.fn();
Object.defineProperty(view.scrollDOM, "scrollBy", { value: scrollBy });
const scrolled: [string, number][] = [];
for (const side of ["scrollTop", "scrollLeft"] as const)
Object.defineProperty(view.scrollDOM, side, {
configurable: true,
get: () => 0,
set: (v: number) => scrolled.push([side, v]),
});
const dispose = installMarkdownSourceScroll(view.dom);
const wheel = (init: WheelEventInit) =>
view.contentDOM.dispatchEvent(new WheelEvent("wheel", { bubbles: true, cancelable: true, ...init }));
@@ -106,7 +111,10 @@ describe("Markdown source scroll", () => {
expect(wheel({ deltaY: 100, ctrlKey: true })).toBe(true);
expect(wheel({ deltaX: 100, deltaY: 10 })).toBe(true);
expect(wheel({ deltaX: 3, deltaY: 100 })).toBe(false);
expect(scrollBy).toHaveBeenCalledExactlyOnceWith(3, 100);
expect(scrolled).toEqual([
["scrollLeft", 3],
["scrollTop", 100],
]);
expect(measure).toHaveBeenCalledTimes(1);
expect(lineAtHeight).toHaveBeenCalledExactlyOnceWith(100);
} finally {
+3 -1
Переглянути файл
@@ -230,7 +230,9 @@ export function installMarkdownSourceScroll(root: HTMLElement): () => void {
// A native jump can expose a virtual gap before CodeMirror redraws. Move and measure together.
event.preventDefault();
scroller.scrollBy(event.deltaX, target - current);
// Offsets rather than scrollBy, which can leave WebKit's compositor at a stale offset.
scroller.scrollLeft += event.deltaX;
scroller.scrollTop = target;
view.requestMeasure();
view.lineBlockAtHeight(nextTop);
};
+36 -4
Переглянути файл
@@ -81,7 +81,7 @@ describe("preview-only scroll position", () => {
second.unmount();
});
it("handles a long preview gesture from its first pixel and leaves nested scrolling native", () => {
it("handles a long preview gesture from its first pixel and leaves nested scrolling native while it can move", () => {
open(mdCtx);
act(() => useMarkdownModes.setState((s) => ({ byTab: { ...s.byTab, t: "preview" } })));
render(
@@ -96,10 +96,36 @@ describe("preview-only scroll position", () => {
});
const scrollBy = vi.fn();
preview.scrollBy = scrollBy;
const scrolled: [number, number][] = [];
let left = 0;
let top = 0;
Object.defineProperties(preview, {
scrollLeft: { configurable: true, get: () => left, set: (v: number) => void (left = v) },
scrollTop: {
configurable: true,
get: () => top,
set: (v: number) => {
scrolled.push([left, v]);
top = v;
},
},
});
const nested = document.createElement("pre");
nested.style.overflowY = "auto";
Object.defineProperties(nested, { clientHeight: { value: 30 }, scrollHeight: { value: 120 } });
preview.appendChild(nested);
const snug = document.createElement("pre");
snug.style.overflowY = "auto";
Object.defineProperties(snug, { clientHeight: { value: 75 }, scrollHeight: { value: 76 } });
preview.appendChild(snug);
const scrolledDown = document.createElement("pre");
scrolledDown.style.overflowY = "auto";
Object.defineProperties(scrolledDown, {
clientHeight: { value: 30 },
scrollHeight: { value: 120 },
scrollTop: { value: 90 },
});
preview.appendChild(scrolledDown);
const wheel = (target: Element, init: WheelEventInit) =>
target.dispatchEvent(
new WheelEvent("wheel", {
@@ -108,17 +134,23 @@ describe("preview-only scroll position", () => {
...init,
}),
);
expect(wheel(preview, { deltaY: 1 })).toBe(false);
expect(wheel(preview, { deltaY: -300 })).toBe(true);
expect(wheel(preview, { deltaY: 1 })).toBe(false);
expect(wheel(preview, { deltaY: 300, deltaMode: 1 })).toBe(true);
expect(wheel(preview, { deltaY: 300, deltaX: 400 })).toBe(true);
expect(wheel(nested, { deltaY: 300 })).toBe(true);
expect(wheel(preview, { deltaY: 300, deltaX: 1 })).toBe(false);
expect(wheel(snug, { deltaY: 10 })).toBe(false);
expect(wheel(scrolledDown, { deltaY: 10 })).toBe(false);
expect(wheel(scrolledDown, { deltaY: -10 })).toBe(true);
Object.defineProperty(preview, "scrollHeight", { value: 650 });
expect(wheel(preview, { deltaY: 1 })).toBe(true);
expect(scrollBy.mock.calls).toEqual([
expect(scrollBy).not.toHaveBeenCalled();
expect(scrolled).toEqual([
[0, 1],
[1, 300],
[1, 301],
[1, 311],
[1, 321],
]);
});