@@ -10,6 +10,7 @@ import SwiftUI
1010import Combine
1111
1212class SuggestionViewController : NSViewController {
13+ var tintView : NSView !
1314 var tableView : NSTableView !
1415 var scrollView : NSScrollView !
1516 var noItemsLabel : NSTextField !
@@ -29,7 +30,14 @@ class SuggestionViewController: NSViewController {
2930 super. loadView ( )
3031 view. wantsLayer = true
3132 view. layer? . cornerRadius = 8.5
32- view. layer? . backgroundColor = . clear
33+ view. layer? . backgroundColor = NSColor . windowBackgroundColor. cgColor
34+
35+ tintView = NSView ( )
36+ tintView. translatesAutoresizingMaskIntoConstraints = false
37+ tintView. wantsLayer = true
38+ tintView. layer? . cornerRadius = 8.5
39+ tintView. layer? . backgroundColor = . clear
40+ view. addSubview ( tintView)
3341
3442 tableView = NSTableView ( )
3543 configureTableView ( )
@@ -46,6 +54,11 @@ class SuggestionViewController: NSViewController {
4654 view. addSubview ( scrollView)
4755
4856 NSLayoutConstraint . activate ( [
57+ tintView. topAnchor. constraint ( equalTo: view. topAnchor) ,
58+ tintView. bottomAnchor. constraint ( equalTo: view. bottomAnchor) ,
59+ tintView. leadingAnchor. constraint ( equalTo: view. leadingAnchor) ,
60+ tintView. trailingAnchor. constraint ( equalTo: view. trailingAnchor) ,
61+
4962 noItemsLabel. centerXAnchor. constraint ( equalTo: view. centerXAnchor) ,
5063 noItemsLabel. topAnchor. constraint ( equalTo: view. topAnchor, constant: 10 ) ,
5164 noItemsLabel. bottomAnchor. constraint ( equalTo: view. bottomAnchor, constant: - 10 ) ,
@@ -78,22 +91,23 @@ class SuggestionViewController: NSViewController {
7891 blue: color. blueComponent * 0.95 ,
7992 alpha: 1.0
8093 )
81- view . layer? . backgroundColor = newColor. cgColor
94+ tintView . layer? . backgroundColor = newColor. cgColor
8295 } else {
83- view . layer? . backgroundColor = . clear
96+ tintView . layer? . backgroundColor = . clear
8497 }
8598 case . darkAqua:
86- view . layer? . backgroundColor = controller. theme. background. cgColor
99+ tintView . layer? . backgroundColor = controller. theme. background. cgColor
87100 default :
88101 return
89102 }
103+ updateSize ( using: controller)
104+ }
90105
106+ func updateSize( using controller: TextViewController ) {
91107 guard model? . items. isEmpty == false else {
92108 let size = NSSize ( width: 256 , height: noItemsLabel. fittingSize. height + 20 )
93109 preferredContentSize = size
94- view. window? . setContentSize ( size)
95- view. window? . contentMinSize = size
96- view. window? . contentMaxSize = size
110+ ( self . view. window? . windowController as? SuggestionController ) ? . updateWindowSize ( newSize: size)
97111 return
98112 }
99113 guard let rowView = tableView. view ( atColumn: 0 , row: 0 , makeIfNecessary: true ) else {
@@ -104,16 +118,17 @@ class SuggestionViewController: NSViewController {
104118 let numberOfVisibleRows = min ( CGFloat ( model? . items. count ?? 0 ) , SuggestionController . MAX_VISIBLE_ROWS)
105119 let newHeight = rowHeight * numberOfVisibleRows + SuggestionController. WINDOW_PADDING * 2
106120
107- let maxLength = min ( ( model? . items. max ( by: { $0. label. count < $1. label. count } ) ? . label. count ?? 16 ) + 4 , 48 )
108- let newWidth = max ( 256 , CGFloat ( maxLength) * controller. font. charWidth)
121+ let maxLength = min (
122+ ( model? . items. reduce ( 0 , { max ( $0, $1. label. count + ( $1. detail? . count ?? 0 ) ) } ) ?? 16 ) + 4 ,
123+ 64
124+ )
125+ let newWidth = CGFloat ( maxLength) * controller. font. charWidth
109126
110127 view. constraints. filter ( { $0. firstAnchor == view. heightAnchor } ) . forEach { $0. isActive = false }
111128 view. heightAnchor. constraint ( equalToConstant: newHeight) . isActive = true
112129
113- preferredContentSize = NSSize ( width: newWidth, height: newHeight)
114- view. window? . setContentSize ( NSSize ( width: newWidth, height: newHeight) )
115- view. window? . contentMinSize = NSSize ( width: newWidth, height: newHeight)
116- view. window? . contentMaxSize = NSSize ( width: . infinity, height: newHeight)
130+ let newSize = NSSize ( width: newWidth, height: newHeight)
131+ ( self . view. window? . windowController as? SuggestionController ) ? . updateWindowSize ( newSize: newSize)
117132 }
118133
119134 func configureTableView( ) {
@@ -158,6 +173,9 @@ class SuggestionViewController: NSViewController {
158173 scrollView. isHidden = model. items. isEmpty
159174 }
160175 tableView. reloadData ( )
176+ if let activeTextView = model? . activeTextView {
177+ updateSize ( using: activeTextView)
178+ }
161179 }
162180
163181 @objc private func tableViewClicked( _ sender: Any ? ) {
@@ -204,7 +222,7 @@ extension SuggestionViewController: NSTableViewDataSource, NSTableViewDelegate {
204222 rootView: CodeSuggestionLabelView (
205223 suggestion: model. items [ row] ,
206224 labelColor: textView. theme. text. color,
207- secondaryLabelColor: textView. theme. comments . color,
225+ secondaryLabelColor: textView. theme. text . color. withAlphaComponent ( 0.5 ) ,
208226 font: textView. font
209227 )
210228 )
0 commit comments