Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Sources/ZoomItMacCore/Overlay/ZoomCanvasView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ final class ZoomCanvasView: NSView {
switch interactionMode {
case .typing:
let wasDrawing = isDrawingMode
exitDrawingMode(restoreCursor: false)
exitDrawingMode(
restoreCursor: false,
clearBlankScreen: Self.clearsBlankScreenWhenLeavingDrawing(for: interactionMode)
)
// When coming from drawing, the pen dot is already tracked in
// pointerViewPoint; exitDrawingMode warps the system cursor, so
// don't re-read the mouse. Otherwise sync to the real cursor so
Expand Down Expand Up @@ -502,6 +505,10 @@ final class ZoomCanvasView: NSView {
return .penColor
}

static func clearsBlankScreenWhenLeavingDrawing(for mode: AppMode) -> Bool {
mode != .typing
}

private func drawTypingCaret(in context: CGContext, source: CGRect) {
guard let caret = annotationController.typingCaret() else { return }
let color = annotationController.currentStyle.color.nsColor
Expand Down Expand Up @@ -559,12 +566,14 @@ final class ZoomCanvasView: NSView {
updateLiveZoomInteractivity()
}

private func exitDrawingMode(restoreCursor: Bool = true) {
private func exitDrawingMode(restoreCursor: Bool = true, clearBlankScreen: Bool = true) {
guard isDrawingMode else { return }
isDrawingMode = false
isStroking = false
activeStrokeTool = nil
blankScreen = nil
if clearBlankScreen {
blankScreen = nil
}
stopDrawingRightClickMonitor()
// Keep the zoom anchored where it was while drawing. The physical mouse
// moved around the screen while drawing, so warp the (hidden) system
Expand Down Expand Up @@ -960,4 +969,4 @@ final class ZoomCanvasView: NSView {
context.fillEllipse(in: rect)
context.restoreGState()
}
}
}
15 changes: 14 additions & 1 deletion Sources/ZoomItMacCore/SelfTest/SelfTestRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public enum SelfTestRunner {
try testSettingsWindowStaysOnTop()
try testZoomAndLiveZoomAreSeparateTabs()
try testBlankScreenUsesControlKeys()
try testTypingPreservesBlankScreen()
try testTypeTabFontSampleUsesSelectedFont()
try testMenuBarIconIsPaddedTemplate()
try testStandardIconIsRoundedSquareWithMargin()
Expand Down Expand Up @@ -702,6 +703,18 @@ public enum SelfTestRunner {
"Expected Ctrl+W/K outside drawing mode to fall back to the pen colour")
}

private static func testTypingPreservesBlankScreen() throws {
try expect(!ZoomCanvasView.clearsBlankScreenWhenLeavingDrawing(for: .typing),
"Expected leaving drawing for typing mode to preserve the sketch-pad background")

let modesThatShouldClear: [AppMode] = [.idle, .staticZoom, .drawOnly, .liveZoom, .captureSelection,
.panoramaCapture, .recording, .breakTimer]
for mode in modesThatShouldClear {
try expect(ZoomCanvasView.clearsBlankScreenWhenLeavingDrawing(for: mode),
"Expected leaving drawing for \(mode) to clear the sketch-pad background")
}
}

/// The Type tab's "Sample" preview must render in the selected typing font
/// (it previously always used the system font, so font changes weren't
/// visible). Also verify the preview size is clamped to a legible range.
Expand Down Expand Up @@ -1729,4 +1742,4 @@ private extension Array {
Array(self[start..<Swift.min(start + size, count)])
}
}
}
}