From c3bf329fe03b933e3c94decd3885593b0b914c19 Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:54:00 -0500 Subject: [PATCH 1/2] Clip Caret Drawing To Bounds Update the caret drawing function to clip to it's bounds. Fixes a small visual bug where the unfocused box stuck around in the layer because it was never cleared due to it being outside the view's bounds. --- Sources/SwiftTerm/Apple/CaretView.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftTerm/Apple/CaretView.swift b/Sources/SwiftTerm/Apple/CaretView.swift index 9df3a15c..578e66e5 100644 --- a/Sources/SwiftTerm/Apple/CaretView.swift +++ b/Sources/SwiftTerm/Apple/CaretView.swift @@ -16,12 +16,14 @@ extension CaretView { guard let terminal else { return } + context.saveGState() + context.clip(to: [bounds]) context.setFillColor(TTColor.clear.cgColor) context.fill ([bounds]) if !hasFocus { context.setStrokeColor(bgColor) - context.setLineWidth(2) + context.setLineWidth(3) context.stroke(bounds) return } @@ -61,5 +63,6 @@ extension CaretView { } CTFontDrawGlyphs(runFont, runGlyphs, &positions, positions.count, context) } + context.restoreGState() } } From c0b7887fb9a626409919485556cf473e379a17f8 Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:54:52 -0500 Subject: [PATCH 2/2] Update macOS Caret Background Color Updates the macOS Caret background color when the color is set using the public variable. Fixes an issue where the caret color was not being used on macOS if it was changed after initialization. --- Sources/SwiftTerm/Mac/MacCaretView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/SwiftTerm/Mac/MacCaretView.swift b/Sources/SwiftTerm/Mac/MacCaretView.swift index f2442ec9..4d37cce2 100644 --- a/Sources/SwiftTerm/Mac/MacCaretView.swift +++ b/Sources/SwiftTerm/Mac/MacCaretView.swift @@ -85,6 +85,7 @@ class CaretView: NSView, CALayerDelegate { public var caretColor: NSColor = NSColor.selectedControlColor { didSet { + bgColor = caretColor.cgColor updateView() } }