Improve loads of fancy things in relation to the mouse pointer
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import AppKit
|
||||
import HelderCore
|
||||
@testable import HelderUI
|
||||
import Testing
|
||||
|
||||
@MainActor
|
||||
@Suite struct CodeEditorShowDiffTests {
|
||||
/// Line 2 is a blank added line, line 3 a changed one; lines 1 and 4 are unchanged.
|
||||
private func open(offersShowDiff: Bool = true) -> (CodeEditorController, NSWindow) {
|
||||
let controller = CodeEditorController()
|
||||
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 700, height: 400), styleMask: [.titled],
|
||||
backing: .buffered, defer: false)
|
||||
window.contentView = controller.scrollView
|
||||
let marks = [2: CodeLineMark(tint: true, tone: .added), 3: CodeLineMark(tint: true, tone: .added)]
|
||||
controller.apply(CodeEditorConfiguration(documentID: "a.php", path: "a.php", text: "one\n\nthree\nfour", revision: 1,
|
||||
language: nil, isEditable: true, wrap: false, tabSize: 4, marksKey: "m", makeMarks: { marks },
|
||||
offersShowDiff: offersShowDiff, knownSymbols: [], symbolsVersion: 0, flash: nil, focusRequest: 0,
|
||||
selectAllRequest: 0, fontScale: 1, isShown: true))
|
||||
window.displayIfNeeded()
|
||||
return (controller, window)
|
||||
}
|
||||
|
||||
/// A window point inside the first row of `line`, `x` points from the text view's left edge.
|
||||
private func point(line: Int, x: CGFloat, in controller: CodeEditorController) -> NSPoint {
|
||||
var rect: NSRect?
|
||||
controller.forEachRow(in: controller.textView.bounds) { row in
|
||||
if row.line == line, rect == nil { rect = row.rect }
|
||||
}
|
||||
let row = rect ?? .zero
|
||||
return controller.textView.convert(NSPoint(x: x, y: row.midY), to: nil)
|
||||
}
|
||||
|
||||
@Test func aBlankAddedLineOffersShowDiff() {
|
||||
let (controller, window) = open()
|
||||
#expect(controller.showDiffLine(atWindowPoint: point(line: 2, x: 40, in: controller)) == 2)
|
||||
withExtendedLifetime(window) {}
|
||||
}
|
||||
|
||||
@Test func theSpaceAfterTheLastGlyphCounts() {
|
||||
let (controller, window) = open()
|
||||
#expect(controller.showDiffLine(atWindowPoint: point(line: 3, x: 500, in: controller)) == 3)
|
||||
withExtendedLifetime(window) {}
|
||||
}
|
||||
|
||||
@Test func anUnchangedLineOffersNothing() {
|
||||
let (controller, window) = open()
|
||||
#expect(controller.showDiffLine(atWindowPoint: point(line: 1, x: 10, in: controller)) == nil)
|
||||
#expect(controller.showDiffLine(atWindowPoint: point(line: 4, x: 500, in: controller)) == nil)
|
||||
withExtendedLifetime(window) {}
|
||||
}
|
||||
|
||||
@Test func aFileWithoutShowDiffOffersNothingOnAMarkedLine() {
|
||||
let (controller, window) = open(offersShowDiff: false)
|
||||
#expect(controller.showDiffLine(atWindowPoint: point(line: 3, x: 10, in: controller)) == nil)
|
||||
withExtendedLifetime(window) {}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,17 @@ import Testing
|
||||
let view = EditorPresentation(path: "a.php", requested: nil, diff: makeDiff(original: "a", updated: "b"))
|
||||
#expect(view.mode == .actual)
|
||||
#expect(view.barButtons == [.diff])
|
||||
#expect(view.opensDiffOnClick)
|
||||
#expect(view.offersShowDiff)
|
||||
}
|
||||
|
||||
@Test func anUnchangedFileOffersNoShowDiff() {
|
||||
#expect(!EditorPresentation(path: "a.php", requested: nil, diff: nil).offersShowDiff)
|
||||
}
|
||||
|
||||
@Test func showDiffNeedsActualInThePane() {
|
||||
let view = EditorPresentation(path: "README.md", requested: .preview, diff: makeDiff(original: "a", updated: "b"))
|
||||
#expect(view.paneMode == .preview)
|
||||
#expect(!view.offersShowDiff)
|
||||
}
|
||||
|
||||
@Test func unchangedMarkdownOffersOnlyPreview() {
|
||||
@@ -55,11 +65,11 @@ import Testing
|
||||
#expect(view.paneMode == .actual)
|
||||
}
|
||||
|
||||
@Test func anAddedFileHasNoClickToDiff() {
|
||||
@Test func anAddedFileOffersNoShowDiff() {
|
||||
let diff = makeDiff(original: "", updated: "b", isAddedFile: true)
|
||||
let actual = EditorPresentation(path: "a.php", requested: .actual, diff: diff)
|
||||
#expect(actual.placeholder == nil)
|
||||
#expect(!actual.opensDiffOnClick)
|
||||
#expect(!actual.offersShowDiff)
|
||||
#expect(actual.status == .added)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import Testing
|
||||
window.contentView = controller.scrollView
|
||||
controller.apply(CodeEditorConfiguration(documentID: "notes.md", path: "notes.md", text: Self.text, revision: 1,
|
||||
language: nil, isEditable: true, wrap: wrap, tabSize: 4, marksKey: "", makeMarks: { [:] },
|
||||
opensDiffOnClick: false, knownSymbols: [], symbolsVersion: 0, flash: nil, focusRequest: 0,
|
||||
offersShowDiff: false, knownSymbols: [], symbolsVersion: 0, flash: nil, focusRequest: 0,
|
||||
selectAllRequest: 0, fontScale: 1, isShown: true))
|
||||
return (controller, window)
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ import Testing
|
||||
#expect(h.store.mode(for: "README.md") == .preview)
|
||||
}
|
||||
|
||||
@Test func aClickOnAMarkedLineOpensTheDiffOnHeadVersusDiskAtThatLine() {
|
||||
@Test func showDiffOnAMarkedLineOpensTheDiffOnHeadVersusDiskAtThatLine() {
|
||||
let h = EditorHarness(files: ["a.php": "new"])
|
||||
h.git.change("a.php", makeDiff(original: "old", updated: "new"))
|
||||
h.store.open("a.php", OpenOptions(side: .unstaged))
|
||||
@@ -553,16 +553,29 @@ import Testing
|
||||
#expect(h.store.passOnSelectionRequest(anchor: .zero) == nil)
|
||||
}
|
||||
|
||||
@Test func theRightClickMenuIsPassOnThenCopyReference() {
|
||||
@Test func theRightClickMenuIsPassOnThenCopyReferenceWithoutAHeader() {
|
||||
let h = EditorHarness(files: ["src/a.php": "x"])
|
||||
let menu = h.store.contextMenuRequest(reference: AgentReference(path: "src/a.php", startLine: 42), code: nil, anchor: .zero)
|
||||
#expect(menu.header == "src/a.php:42")
|
||||
#expect(menu.header == "")
|
||||
#expect(menu.entries == [
|
||||
.action(.passOnReference("src/a.php:42", code: nil), label: "Pass on reference"),
|
||||
.action(.copyReference("src/a.php:42"), label: "Copy reference"),
|
||||
])
|
||||
}
|
||||
|
||||
@Test func aMarkedLineAddsShowDiffBelowASeparator() {
|
||||
let h = EditorHarness(files: ["src/a.php": "x"])
|
||||
let menu = h.store.contextMenuRequest(reference: AgentReference(path: "src/a.php", startLine: 42), code: nil,
|
||||
showDiffLine: 42, anchor: .zero)
|
||||
#expect(menu.header == "")
|
||||
#expect(menu.entries == [
|
||||
.action(.passOnReference("src/a.php:42", code: nil), label: "Pass on reference"),
|
||||
.action(.copyReference("src/a.php:42"), label: "Copy reference"),
|
||||
.separator,
|
||||
.action(.showDiff("src/a.php", line: 42), label: "Show diff"),
|
||||
])
|
||||
}
|
||||
|
||||
@Test func anEmptyNotePassesTheBareReference() {
|
||||
#expect(PassOn.compose(note: " ", reference: "src/a.php:42") == "src/a.php:42")
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ import Testing
|
||||
#expect(menuLabels(folderMenu) == ["Pass on reference", "Copy reference", "New file", "New folder",
|
||||
"Rename folder", "Show in Finder", "Delete folder"])
|
||||
#expect(menuLabels(rootMenu) == ["New file", "Show in Finder"])
|
||||
#expect(folderMenu.header == "src/")
|
||||
#expect(folderMenu.header.isEmpty)
|
||||
#expect(rootMenu.header == "console/")
|
||||
#expect(ExplorerStore.target(for: TreeRow(path: "src", kind: .directory, depth: 0)) == .directory(path: "src"))
|
||||
}
|
||||
|
||||
@@ -19,10 +19,16 @@ import Testing
|
||||
@Test func passOnOpenDiffAndRenameAreGrey() {
|
||||
#expect(ContextMenuOverlay.tint(for: .passOnReference("a.php", code: nil)) == .rename)
|
||||
#expect(ContextMenuOverlay.tint(for: .passOnFileName("a.php")) == .rename)
|
||||
#expect(ContextMenuOverlay.tint(for: .bouwen("x")) == .rename)
|
||||
#expect(ContextMenuOverlay.tint(for: .openDiff("a.php")) == .rename)
|
||||
#expect(ContextMenuOverlay.tint(for: .showDiff("a.php", line: 3)) == .rename)
|
||||
#expect(ContextMenuOverlay.tint(for: .rename("a.php", isDirectory: false)) == .rename)
|
||||
}
|
||||
|
||||
@Test func showDiffWearsTheOpenDiffIcon() {
|
||||
#expect(ContextMenuOverlay.symbol(for: .showDiff("a.php", line: 3)) == ContextMenuOverlay.symbol(for: .openDiff("a.php")))
|
||||
}
|
||||
|
||||
@Test func copyReferenceKeepsThePlainIconThatTurnsAmberOnHighlight() {
|
||||
#expect(ContextMenuOverlay.tint(for: .copyReference("a.php")) == .plain)
|
||||
#expect(MenuIconTint.plain.color == nil)
|
||||
|
||||
@@ -391,6 +391,14 @@ import Testing
|
||||
#expect(harness.toastTitles == ["Passed to agent"])
|
||||
}
|
||||
|
||||
@Test func bouwenInsertsTheCommandIntoTheAgent() async {
|
||||
let harness = WorkspaceHarness()
|
||||
await harness.start()
|
||||
await harness.perform(.context(.bouwen("2026-10-02-001-x")))
|
||||
#expect(harness.agent.sent == [BracketedPaste.wrap("/bouwen 2026-10-02-001-x", composerHasText: false)])
|
||||
#expect(harness.toastTitles == ["Passed to agent"])
|
||||
}
|
||||
|
||||
@Test func aDirtyTabAsksBeforeItCloses() async {
|
||||
let harness = WorkspaceHarness(contents: ["a.php": "one"])
|
||||
await harness.start()
|
||||
@@ -576,6 +584,14 @@ import Testing
|
||||
#expect(editor?.mode(for: "a.md") == .preview)
|
||||
}
|
||||
|
||||
@Test func showDiffOpensTheDiffOfTheOpenFileAtThatLine() async {
|
||||
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false)]), contents: ["a.php": "b"])
|
||||
await harness.start()
|
||||
harness.model.open("a.php")
|
||||
await harness.perform(.context(.showDiff("a.php", line: 3)))
|
||||
#expect(harness.model.overlay.current == .diff(DiffOverlayRequest(path: "a.php", side: nil, focusLine: 3)))
|
||||
}
|
||||
|
||||
@Test func theRecentProjectListLeavesOutTheOpenProject() async {
|
||||
let harness = WorkspaceHarness(recents: [RecentProject(path: "/elsewhere", name: "elsewhere")])
|
||||
await harness.start()
|
||||
|
||||
Reference in New Issue
Block a user