diff --git a/CLAUDE.md b/CLAUDE.md index 3a34521..c3d4dab 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -248,9 +248,10 @@ panels**, and a few responsibilities are deliberately split across the AppKit/Sw (`showsBar`). The roll is an `animator()` frame animation, not the blocking `setFrame(_:display:animate:)` (SwiftUI only swapped the content after it); the system frame returns before expanding and goes only after rolling up, since a titled window's shadow tracks a resize. The - bar has **no** shadow: a frameless window's traces the capsule with a dark rim that reads as a border. The content has `minHeight: 0` — the hosting view won't let the window be shorter than the - content's minimum (an expand jumped straight to ~150pt) — so the open note's minimum lives in - `windowWillResize`, which also locks the bar's height. + bar has **no** shadow: a frameless window's traces the capsule with a dark rim that reads as a border. `NotePanel` sets `hosting.sizingOptions = []`, so only the manager sizes a note: left on, the + hosting view resized the window from inside a layout pass when the hover controls raised the content's minimum, and a + bar has so few views that AppKit's limit on layout passes (one per view) aborted the app (issue 22). So the minimums + live in `windowWillResize`, which also locks the bar's height, and the content has `minHeight: 0` to fit a window mid-roll. - **Theming via roles, not raw colors.** `NoteColor.color(_:on:)` resolves a role (title/task/secondary/completed/checkbox) for a `Surface` (`.solid` uses per-theme tuned inks; `.glass` uses adaptive `.primary`/`.secondary`). Views read a resolved `NoteTheme`, never branch diff --git a/Sources/Tic/MCP/MCPTools.swift b/Sources/Tic/MCP/MCPTools.swift index 157e1d1..287e2b0 100644 --- a/Sources/Tic/MCP/MCPTools.swift +++ b/Sources/Tic/MCP/MCPTools.swift @@ -152,7 +152,7 @@ struct MCPTools: Sendable { let rect = CGRect( x: args.double("x") ?? n.frameX, y: args.double("y") ?? n.frameY, - width: max(120, args.double("width") ?? n.frameW), + width: max(NoteLayout.minWidth, args.double("width") ?? n.frameW), height: max(80, args.double("height") ?? n.frameH) ) await window.setFrame(id, rect) diff --git a/Sources/Tic/Views/NoteView.swift b/Sources/Tic/Views/NoteView.swift index 16197f1..7790de4 100644 --- a/Sources/Tic/Views/NoteView.swift +++ b/Sources/Tic/Views/NoteView.swift @@ -8,6 +8,8 @@ enum NoteLayout { static let collapsedHeight: CGFloat = 34 /// The shortest an open note can be resized to (`NoteWindowManager.windowWillResize`). static let minExpandedHeight: CGFloat = 160 + /// The narrowest a note can be: an open note's header controls just fit. + static let minWidth: CGFloat = 156 /// Horizontal inset added per nesting level, so subtasks step to the right of their parent. static let indentStep: CGFloat = 20 /// Horizontal inset of task rows from the note's edges — room for the drag grip and the drop @@ -98,8 +100,8 @@ struct NoteView: View { QuickAddBar(controller: controller, theme: theme) } } - // `minHeight: 0`: the window opens from a bar, and the hosting view won't let it be shorter than the - // content's minimum — it jumped straight to ~150pt. The resize delegate keeps open notes taller. + // `minHeight: 0`: part-way through a roll the window is shorter than the list's ~150pt minimum, and the + // content still has to fit it. The resize delegate keeps open notes taller. .frame(maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading) .onGeometryChange(for: Bool.self) { $0.size.height <= NoteLayout.collapsedHeight + 0.5 } action: { atBarHeight = $0 diff --git a/Sources/Tic/Windows/NotePanel.swift b/Sources/Tic/Windows/NotePanel.swift index 0d9a0d5..a4cf3ba 100644 --- a/Sources/Tic/Windows/NotePanel.swift +++ b/Sources/Tic/Windows/NotePanel.swift @@ -15,7 +15,8 @@ final class NotePanel: NSPanel { init(note: Note, content: AnyView) { self.noteID = note.id - let rect = NSRect(x: note.frameX, y: note.frameY, width: note.frameW, height: note.frameH) + let width = max(note.frameW, NoteLayout.minWidth) + let rect = NSRect(x: note.frameX, y: note.frameY, width: width, height: note.frameH) super.init( contentRect: rect, styleMask: Self.noteStyle, @@ -39,6 +40,10 @@ final class NotePanel: NSPanel { let hosting = NSHostingView(rootView: content) hosting.autoresizingMask = [.width, .height] + // `NoteWindowManager` alone sizes the panel. Left on, the hosting view resizes the window from inside a + // layout pass whenever the content's minimum changes (the hover controls do), and a rolled-up bar has so + // few views that AppKit's limit on layout passes (one per view) aborts the app (issue 22). + hosting.sizingOptions = [] contentView = hosting apply(floatOnTop: note.floatOnTop, showOnAllSpaces: note.showOnAllSpaces) diff --git a/Sources/Tic/Windows/NoteWindowManager.swift b/Sources/Tic/Windows/NoteWindowManager.swift index cd16c87..30da69f 100644 --- a/Sources/Tic/Windows/NoteWindowManager.swift +++ b/Sources/Tic/Windows/NoteWindowManager.swift @@ -304,14 +304,14 @@ final class NoteWindowManager: NSObject, NSWindowDelegate { func windowDidMove(_ notification: Notification) { scheduleFrameSave(notification) } - /// The note's height limits, for user resizes only (the hosting view resets `minSize`, and a roll - /// animation doesn't come through here). A rolled-up bar resizes only sideways, so it can't be dragged - /// into a sliver or a blank note; an open note keeps room for its header and quick-add. + /// The note's size limits, for user resizes only (a roll animation doesn't come through here). A + /// rolled-up bar resizes only sideways, so it can't be dragged into a sliver or a blank note; an open + /// note keeps room for its header and quick-add. func windowWillResize(_ sender: NSWindow, to frameSize: NSSize) -> NSSize { guard let panel = sender as? NotePanel else { return frameSize } let collapsed = controllers[panel.noteID]?.note.isCollapsed == true let height = collapsed ? NoteLayout.collapsedHeight : max(frameSize.height, NoteLayout.minExpandedHeight) - return NSSize(width: frameSize.width, height: height) + return NSSize(width: max(frameSize.width, NoteLayout.minWidth), height: height) } func windowDidResize(_ notification: Notification) { scheduleFrameSave(notification) } diff --git a/Tests/TicTests/NoteWindowManagerTests.swift b/Tests/TicTests/NoteWindowManagerTests.swift index 4cecc58..e3007ff 100644 --- a/Tests/TicTests/NoteWindowManagerTests.swift +++ b/Tests/TicTests/NoteWindowManagerTests.swift @@ -99,6 +99,31 @@ struct NoteWindowManagerTests { #expect(panel.frame.minY == screen.minY + 30) } + @Test("the hover controls never resize a bar: only the manager sizes a note (issue 22)") + @MainActor func hoverLeavesBarSize() async throws { + _ = NSApplication.shared + let db = try AppDatabase.makeInMemory() + let note = Note(isCollapsed: true) + try await db.insert(note) + let manager = NoteWindowManager(appDatabase: db) + let panel = manager.openNote(note, makeKey: false) + defer { panel.close() } + // Narrower than the controls, the worst case: they used to raise the content's minimum width, and the + // hosting view resized the window from inside a layout pass, which AppKit aborts the app for. + panel.setFrame(NSRect(origin: panel.frame.origin, size: NSSize(width: 60, height: bar)), display: true) + try await Task.sleep(for: .milliseconds(100)) + + func trackers(in view: NSView) -> [HoverArea.TrackingView] { + ((view as? HoverArea.TrackingView).map { [$0] } ?? []) + view.subviews.flatMap(trackers) + } + let content = try #require(panel.contentView) + let tracker = try #require(trackers(in: content).first) + tracker.mouseEntered(with: NSEvent()) // the override only reports it; synthetic events can't drive it + try await Task.sleep(for: .milliseconds(350)) // the controls' fade-in + #expect(panel.frame.size == NSSize(width: 60, height: bar)) + #expect(manager.windowWillResize(panel, to: NSSize(width: 40, height: bar)).width == NoteLayout.minWidth) + } + @Test("a rolled-up bar is frameless and keeps its height; expanding brings the system frame back") @MainActor func barHeightLock() async throws { _ = NSApplication.shared @@ -108,8 +133,7 @@ struct NoteWindowManagerTests { let manager = NoteWindowManager(appDatabase: db) let panel = manager.openNote(note, makeKey: false) defer { panel.close() } - // Frameless: no system corners to split from the fill, and no title-bar safe area — the hosting view - // grows the window to the bar's minimum height plus that inset, which bounced a titled bar to ~47pt. + // Frameless: no system corners to split from the fill, and no title-bar safe area. #expect(!panel.styleMask.contains(.titled) && panel.contentView?.safeAreaInsets.top == 0) #expect(!panel.hasShadow) // a frameless window's shadow rims the capsule like a dark border #expect(manager.windowWillResize(panel, to: NSSize(width: 320, height: 200)) == NSSize(width: 320, height: bar))