mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 09:39:27 -10:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb9618165a | ||
|
|
b48f0b6071 | ||
|
|
a9b16c3e06 |
No files matched your search
@@ -276,14 +276,23 @@ export const openideaTheme = EditorView.theme({
|
||||
},
|
||||
".cm-openidea-laneDeleted": {
|
||||
position: "absolute",
|
||||
left: "0",
|
||||
top: "-3px",
|
||||
left: "-4px",
|
||||
top: "-6px",
|
||||
width: "12px",
|
||||
height: "12px",
|
||||
cursor: "pointer",
|
||||
zIndex: "1",
|
||||
},
|
||||
".cm-openidea-laneDeleted::after": {
|
||||
content: '""',
|
||||
position: "absolute",
|
||||
left: "4px",
|
||||
top: "3px",
|
||||
width: "0",
|
||||
height: "0",
|
||||
borderTop: "3px solid transparent",
|
||||
borderBottom: "3px solid transparent",
|
||||
borderLeft: "6px solid var(--lane-color)",
|
||||
zIndex: "1",
|
||||
},
|
||||
".cm-foldGutter": { width: "16px" },
|
||||
".cm-foldGutter .cm-gutterElement": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { EditorSelection, EditorState } from "@codemirror/state";
|
||||
import type { LineHunk } from "@/bindings";
|
||||
import { applyRollback, hunkAtLine, hunkKeys, hunksOverlapping, nextHunk, prevHunk, rollbackEdit } from "../hunks";
|
||||
@@ -132,6 +132,38 @@ describe("change lane clicks", () => {
|
||||
setHunkPopupHooks(null);
|
||||
parent.remove();
|
||||
});
|
||||
|
||||
it("opens a deletion from the hit area above its line", async () => {
|
||||
const { EditorView } = await import("@codemirror/view");
|
||||
const { changeLane } = await import("@/editor/core/cm/lanes");
|
||||
const { changeMarkers, setHunkPopupHooks } = await import("../gutter");
|
||||
const opened: string[] = [];
|
||||
setHunkPopupHooks({ open: (_v, hunk) => opened.push(hunk.kind), docChanged: () => {} });
|
||||
const parent = document.createElement("div");
|
||||
document.body.appendChild(parent);
|
||||
const view = new EditorView({
|
||||
parent,
|
||||
state: EditorState.create({
|
||||
doc: "a\nc\n",
|
||||
extensions: [changeLane, changeMarkers({ path: "/p/f.txt" } as Parameters<typeof changeMarkers>[0])],
|
||||
}),
|
||||
});
|
||||
view.dispatch({ effects: setHunksEffect.of([h("deleted", 1, 0, 1, 1, "b\n")]) });
|
||||
const lane = view.dom.querySelector<HTMLElement>(".cm-openidea-lane")!;
|
||||
vi.spyOn(lane, "getBoundingClientRect").mockReturnValue({ left: 100, right: 104, top: 0, bottom: 100 } as DOMRect);
|
||||
const marker = view.dom.querySelector<HTMLElement>(".cm-openidea-laneDeleted")!;
|
||||
vi.spyOn(marker, "getBoundingClientRect").mockReturnValue({ left: 96, top: 14, width: 12, height: 12 } as DOMRect);
|
||||
const previous = view.lineBlockAt(view.state.doc.line(1).from);
|
||||
const deleted = view.lineBlockAt(view.state.doc.line(2).from);
|
||||
vi.spyOn(view, "lineBlockAtHeight").mockImplementation((height) => (height < 20 ? previous : deleted));
|
||||
marker.dispatchEvent(
|
||||
new MouseEvent("mousedown", { bubbles: true, cancelable: true, button: 0, clientX: 96, clientY: 17 }),
|
||||
);
|
||||
expect(opened).toEqual(["deleted"]);
|
||||
view.destroy();
|
||||
setHunkPopupHooks(null);
|
||||
parent.remove();
|
||||
});
|
||||
});
|
||||
|
||||
describe("change markers in folds", () => {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { useEffect, useId, useState } from "react";
|
||||
import type { FileStatus, Stash } from "@/bindings";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { Checkbox, Dialog, Icon, IconButton, Input, T, fileIconName } from "@/ui";
|
||||
import { Checkbox, Dialog, IconButton, Input, T } from "@/ui";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
import { addedThenDeleted, groupOf, remainingOverrides, renamedFromPath } from "./changes";
|
||||
import { runCommitChecks } from "./commitChecks";
|
||||
@@ -12,10 +12,11 @@ import { workflowSettings } from "@/platform/workflowSettings";
|
||||
import { notifyFileOperation } from "@/platform/fileOps";
|
||||
import { confirmDialog, openDialog } from "./dialogs";
|
||||
import { RepoPicker, useBranchInfo } from "./gitMenuDialogs";
|
||||
import { KIND_COLOR, baseName, dirName, effectiveKind, relTo, stripSlash } from "./model";
|
||||
import { baseName, effectiveKind, stripSlash } from "./model";
|
||||
import { logConsole, runOp, saveAll } from "./ops";
|
||||
import { ensureCommitIdentity } from "./commitIdentity";
|
||||
import { showCompareRevisions } from "./operations";
|
||||
import { FileChecklist } from "./shelf";
|
||||
import { currentRepo, loadStashes, refreshNow, useVcs } from "./store";
|
||||
import styles from "./common.module.css";
|
||||
import { tx } from "@/platform/i18n";
|
||||
@@ -216,7 +217,6 @@ export function showRollbackDialog(files: FileStatus[]) {
|
||||
}
|
||||
|
||||
function RollbackDialog({ files, onClose }: { files: FileStatus[]; onClose: () => void }) {
|
||||
const root = useVcs((s) => s.root) ?? "";
|
||||
const [selected, setSelected] = useState(() => new Set(files.map((f) => f.path)));
|
||||
const [deleteAdded, setDeleteAdded] = useState(false);
|
||||
const hasAdded = files.some((f) => f.staged === "added");
|
||||
@@ -256,32 +256,7 @@ function RollbackDialog({ files, onClose }: { files: FileStatus[]; onClose: () =
|
||||
? tx`${selected.size} of ${files.length} file will be reverted to their last committed state. Uncommitted changes are lost.`
|
||||
: tx`${selected.size} of ${files.length} files will be reverted to their last committed state. Uncommitted changes are lost.`}
|
||||
</div>
|
||||
<div className={styles.fileList} role="group" aria-label={tx("Files to roll back")}>
|
||||
{files.map((f) => {
|
||||
const kind = effectiveKind(f) ?? "modified";
|
||||
return (
|
||||
<div key={f.path} className={styles.fileRow}>
|
||||
<Checkbox
|
||||
aria-label={tx`Include ${baseName(f.path)}`}
|
||||
checked={selected.has(f.path)}
|
||||
onChange={(v) =>
|
||||
setSelected((s) => {
|
||||
const n = new Set(s);
|
||||
if (v) n.add(f.path);
|
||||
else n.delete(f.path);
|
||||
return n;
|
||||
})
|
||||
}
|
||||
/>
|
||||
<Icon name={fileIconName(baseName(f.path), f.path)} size={14} />
|
||||
<span className={styles.fileName} style={{ color: KIND_COLOR[kind] }}>
|
||||
{baseName(f.path)}
|
||||
</span>
|
||||
<span className={styles.fileDir}>{dirName(relTo(root, stripSlash(f.path)))}</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<FileChecklist files={files} selected={selected} onChange={setSelected} label="Files to roll back" />
|
||||
<div style={{ height: 12 }} />
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@@ -235,14 +235,19 @@ const laneTheme = EditorView.baseTheme({
|
||||
*/
|
||||
export function laneMouseDown(view: EditorView, event: MouseEvent, path: string): boolean {
|
||||
if (event.button !== 0 || event.shiftKey || event.metaKey || event.ctrlKey || event.altKey) return false;
|
||||
const deletedMarker = event.target instanceof Element ? event.target.closest(".cm-openidea-laneDeleted") : null;
|
||||
const lane = view.dom.querySelector(".cm-openidea-lane");
|
||||
if (!lane) return false;
|
||||
const rect = lane.getBoundingClientRect();
|
||||
if (event.clientX < rect.left - 1 || event.clientX > rect.right + 3) return false;
|
||||
if (event.clientY < rect.top || event.clientY > rect.bottom) return false;
|
||||
const block = view.lineBlockAtHeight(event.clientY - view.documentTop);
|
||||
if (!deletedMarker) {
|
||||
const rect = lane.getBoundingClientRect();
|
||||
if (event.clientX < rect.left - 1 || event.clientX > rect.right + 3) return false;
|
||||
if (event.clientY < rect.top || event.clientY > rect.bottom) return false;
|
||||
}
|
||||
const markerRect = deletedMarker?.getBoundingClientRect();
|
||||
const y = markerRect ? markerRect.top + markerRect.height / 2 + 1 : event.clientY;
|
||||
const block = view.lineBlockAtHeight(y - view.documentTop);
|
||||
const hunk = hunkAtPos(view.state, block.from);
|
||||
if (!hunk) return false;
|
||||
if (!hunk || (deletedMarker && hunk.kind !== "deleted")) return false;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
showHunkPopup(view, hunk, path);
|
||||
|
||||
Reference in new issue
Block a user