Эх сурвалжийг харах

Mac: track the cursor changes

Miguel de Icaza 3 жил өмнө
parent
commit
1ea7d6220a

+ 11 - 11
Sources/SwiftTerm/Mac/MacCaretView.swift

@@ -22,8 +22,9 @@ class CaretView: NSView {
         sub = CALayer ()
         sub = CALayer ()
         super.init(frame: frame)
         super.init(frame: frame)
         wantsLayer = true
         wantsLayer = true
-        setupView()
-        updateCursorStyle(style: style)
+        layer?.addSublayer(sub)
+        
+        updateView()
     }
     }
     
     
     required init?(coder: NSCoder) {
     required init?(coder: NSCoder) {
@@ -32,11 +33,11 @@ class CaretView: NSView {
     
     
     var style: CursorStyle {
     var style: CursorStyle {
         didSet {
         didSet {
-            updateCursorStyle (style: style)
+            updateCursorStyle ()
         }
         }
     }
     }
     
     
-    func updateCursorStyle (style: CursorStyle) {
+    func updateCursorStyle () {
         switch style {
         switch style {
         case .blinkUnderline, .blinkBlock, .blinkBar:
         case .blinkUnderline, .blinkBlock, .blinkBar:
             let anim = CABasicAnimation.init(keyPath: #keyPath (CALayer.opacity))
             let anim = CABasicAnimation.init(keyPath: #keyPath (CALayer.opacity))
@@ -70,24 +71,23 @@ class CaretView: NSView {
     
     
     public var caretColor: NSColor = NSColor.selectedControlColor {
     public var caretColor: NSColor = NSColor.selectedControlColor {
         didSet {
         didSet {
-            setupView()
+            updateView()
         }
         }
     }
     }
     
     
     public var focused: Bool = false {
     public var focused: Bool = false {
         didSet {
         didSet {
-            setupView()
+            updateView()
         }
         }
     }
     }
 
 
-    func setupView() {
+    func updateView() {
+        let isFirst = focused
         guard let layer = layer else { return }
         guard let layer = layer else { return }
         sub.frame = CGRect (origin: CGPoint.zero, size: layer.frame.size)
         sub.frame = CGRect (origin: CGPoint.zero, size: layer.frame.size)
-        layer.addSublayer(sub)
-        sub.borderWidth = focused ? 0 : 2
+        sub.borderWidth = isFirst ? 0 : 2
         sub.borderColor = caretColor.cgColor
         sub.borderColor = caretColor.cgColor
-        sub.backgroundColor = focused ? caretColor.cgColor : NSColor.clear.cgColor
-        //layer.opacity = 0.7
+        sub.backgroundColor = isFirst ? caretColor.cgColor : NSColor.clear.cgColor
     }
     }
     
     
     override func hitTest(_ point: NSPoint) -> NSView? {
     override func hitTest(_ point: NSPoint) -> NSView? {