дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Find in Files, Go to Line and other navigation into a CSV file on its Data tab moved the caret in the hidden Text editor only. The table now maps the revealed offset to its record and field the way the CSV parser reads the file (quotes, CRLF, blank lines, header row), scrolls to that cell wherever local sorting put it, selects it and takes the focus; a row hidden by a filter is left alone. Fixes #8043
49 рядки
2.0 KiB
TypeScript
49 рядки
2.0 KiB
TypeScript
/** Text / Data tab of each open CSV editor, and a counter of each CSV file's text changes. */
|
|
import { ViewPlugin, type EditorView, type ViewUpdate } from "@codemirror/view";
|
|
import { create } from "zustand";
|
|
import { registerEditorContribution } from "@/editor/api";
|
|
import { isCsvPath } from "./csv";
|
|
|
|
export type CsvMode = "text" | "data";
|
|
|
|
export const useCsvModes = create<Record<string, CsvMode | undefined>>(() => ({}));
|
|
export const useCsvSourceHidden = (tabId: string) => useCsvModes((s) => s[tabId] === "data");
|
|
|
|
/** The last caret a navigation placed in each CSV file's text (Find in Files, Go to Line…). */
|
|
export const useCsvReveals = create<Record<string, { offset: number; seq: number } | undefined>>(() => ({}));
|
|
let revealSeq = 0;
|
|
|
|
/** Bumped when a CSV file's text changes. */
|
|
export const useCsvVersions = create<Record<string, number | undefined>>(() => ({}));
|
|
const bump = (path: string) => useCsvVersions.setState((s) => ({ [path]: (s[path] ?? 0) + 1 }));
|
|
const TEXT_DELAY = 300;
|
|
|
|
export function registerCsvLiveSource(): () => void {
|
|
return registerEditorContribution({
|
|
id: "database.csvLive",
|
|
extensions: (ctx) =>
|
|
!ctx.virtual && isCsvPath(ctx.path)
|
|
? [
|
|
ViewPlugin.fromClass(
|
|
class {
|
|
private timer: ReturnType<typeof setTimeout> | undefined;
|
|
constructor(_view: EditorView) {
|
|
bump(ctx.path);
|
|
}
|
|
update(u: ViewUpdate) {
|
|
if (u.transactions.some((tr) => tr.isUserEvent("select.reveal")))
|
|
useCsvReveals.setState({ [ctx.path]: { offset: u.state.selection.main.head, seq: ++revealSeq } });
|
|
if (!u.docChanged) return;
|
|
clearTimeout(this.timer);
|
|
this.timer = setTimeout(() => bump(ctx.path), TEXT_DELAY);
|
|
}
|
|
destroy() {
|
|
clearTimeout(this.timer);
|
|
}
|
|
},
|
|
),
|
|
]
|
|
: [],
|
|
});
|
|
}
|