Skip to content

Commit 2dbf5e0

Browse files
Lint
1 parent 09e7484 commit 2dbf5e0

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

Sources/CodeEditTextView/ItemBox/ItemBoxWindowController+Window.swift

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Abe Malla on 12/22/24.
66
//
77

8+
import AppKit
9+
810
extension ItemBoxWindowController {
911
/// Will constrain the window's frame to be within the visible screen
1012
public func constrainWindowToScreenEdges(cursorRect: NSRect) {
@@ -59,7 +61,7 @@ extension ItemBoxWindowController {
5961

6062
// MARK: - Private Methods
6163

62-
private static func makeWindow() -> NSWindow {
64+
static func makeWindow() -> NSWindow {
6365
let window = NSWindow(
6466
contentRect: NSRect(origin: .zero, size: self.DEFAULT_SIZE),
6567
styleMask: [.resizable, .fullSizeContentView, .nonactivatingPanel],
@@ -72,7 +74,7 @@ extension ItemBoxWindowController {
7274
return window
7375
}
7476

75-
private static func configureWindow(_ window: NSWindow) {
77+
static func configureWindow(_ window: NSWindow) {
7678
window.titleVisibility = .hidden
7779
window.titlebarAppearsTransparent = true
7880
window.isExcludedFromWindowsMenu = true
@@ -86,7 +88,7 @@ extension ItemBoxWindowController {
8688
window.minSize = Self.DEFAULT_SIZE
8789
}
8890

89-
private static func configureWindowContent(_ window: NSWindow) {
91+
static func configureWindowContent(_ window: NSWindow) {
9092
guard let contentView = window.contentView else { return }
9193

9294
contentView.wantsLayer = true
@@ -108,7 +110,7 @@ extension ItemBoxWindowController {
108110
contentView.shadow = innerShadow
109111
}
110112

111-
private func configureTableView() {
113+
func configureTableView() {
112114
tableView.delegate = self
113115
tableView.dataSource = self
114116
tableView.headerView = nil
@@ -125,7 +127,7 @@ extension ItemBoxWindowController {
125127
tableView.addTableColumn(column)
126128
}
127129

128-
private func configureScrollView() {
130+
func configureScrollView() {
129131
scrollView.documentView = tableView
130132
scrollView.hasVerticalScroller = true
131133
scrollView.verticalScroller = NoSlotScroller()
@@ -150,7 +152,7 @@ extension ItemBoxWindowController {
150152

151153
/// Updates the item box window's height based on the number of items.
152154
/// If there are no items, the default label will be displayed instead.
153-
private func updateItemBoxWindowAndContents() {
155+
func updateItemBoxWindowAndContents() {
154156
guard let window = self.window else {
155157
return
156158
}
@@ -185,7 +187,7 @@ extension ItemBoxWindowController {
185187
window.minSize = NSSize(width: Self.DEFAULT_SIZE.width, height: newHeight)
186188
}
187189

188-
private func configureNoItemsLabel() {
190+
func configureNoItemsLabel() {
189191
window?.contentView?.addSubview(noItemsLabel)
190192

191193
NSLayoutConstraint.activate([
@@ -195,7 +197,7 @@ extension ItemBoxWindowController {
195197
}
196198

197199
/// Calculate the window height for a given number of rows.
198-
private static func rowsToWindowHeight(for numberOfRows: CGFloat) -> CGFloat {
200+
static func rowsToWindowHeight(for numberOfRows: CGFloat) -> CGFloat {
199201
let wholeRows = floor(numberOfRows)
200202
let partialRow = numberOfRows - wholeRows
201203

@@ -231,3 +233,32 @@ extension ItemBoxWindowController: NSTableViewDataSource, NSTableViewDelegate {
231233
return true
232234
}
233235
}
236+
237+
private class ItemBoxRowView: NSTableRowView {
238+
override func drawSelection(in dirtyRect: NSRect) {
239+
guard isSelected else { return }
240+
guard let context = NSGraphicsContext.current?.cgContext else { return }
241+
242+
context.saveGState()
243+
defer { context.restoreGState() }
244+
245+
// Create a rect that's inset from the edges and has proper padding
246+
// TODO: We create a new selectionRect instead of using dirtyRect
247+
// because there is a visual bug when holding down the arrow keys
248+
// to select the first or last item, which draws a clipped
249+
// rectangular highlight shape instead of the whole rectangle.
250+
// Replace this when it gets fixed.
251+
let selectionRect = NSRect(
252+
x: WINDOW_PADDING,
253+
y: 0,
254+
width: bounds.width - (WINDOW_PADDING * 2),
255+
height: bounds.height
256+
)
257+
let cornerRadius: CGFloat = 5
258+
let path = NSBezierPath(roundedRect: selectionRect, xRadius: cornerRadius, yRadius: cornerRadius)
259+
let selectionColor = NSColor.gray.withAlphaComponent(0.19)
260+
261+
context.setFillColor(selectionColor.cgColor)
262+
path.fill()
263+
}
264+
}

Sources/CodeEditTextView/ItemBox/ItemBoxWindowController.swift

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public protocol ItemBoxEntry {
1414
}
1515

1616
/// Padding at top and bottom of the window
17-
private let WINDOW_PADDING: CGFloat = 5
17+
let WINDOW_PADDING: CGFloat = 5
1818

1919
public final class ItemBoxWindowController: NSWindowController {
2020

@@ -42,17 +42,17 @@ public final class ItemBoxWindowController: NSWindowController {
4242
// MARK: - Private Properties
4343

4444
/// Height of a single row
45-
private static let ROW_HEIGHT: CGFloat = 21
45+
static let ROW_HEIGHT: CGFloat = 21
4646
/// Maximum number of visible rows (8.5)
47-
private static let MAX_VISIBLE_ROWS: CGFloat = 8.5
47+
static let MAX_VISIBLE_ROWS: CGFloat = 8.5
4848

49-
private let tableView = NSTableView()
50-
private let scrollView = NSScrollView()
51-
private let popover = NSPopover()
49+
let tableView = NSTableView()
50+
let scrollView = NSScrollView()
51+
let popover = NSPopover()
5252
/// Tracks when the window is placed above the cursor
53-
private var isWindowAboveCursor = false
53+
var isWindowAboveCursor = false
5454

55-
private let noItemsLabel: NSTextField = {
55+
let noItemsLabel: NSTextField = {
5656
let label = NSTextField(labelWithString: "No Completions")
5757
label.textColor = .secondaryLabelColor
5858
label.alignment = .center
@@ -83,7 +83,7 @@ public final class ItemBoxWindowController: NSWindowController {
8383
}
8484

8585
/// Opens the window of items
86-
private func show() {
86+
func show() {
8787
setupEventMonitor()
8888
resetScrollPosition()
8989
super.showWindow(nil)
@@ -227,43 +227,14 @@ public final class ItemBoxWindowController: NSWindowController {
227227
}
228228
}
229229

230-
private class NoSlotScroller: NSScroller {
230+
class NoSlotScroller: NSScroller {
231231
override class var isCompatibleWithOverlayScrollers: Bool { true }
232232

233233
override func drawKnobSlot(in slotRect: NSRect, highlight flag: Bool) {
234234
// Don't draw the knob slot (the background track behind the knob)
235235
}
236236
}
237237

238-
private class ItemBoxRowView: NSTableRowView {
239-
override func drawSelection(in dirtyRect: NSRect) {
240-
guard isSelected else { return }
241-
guard let context = NSGraphicsContext.current?.cgContext else { return }
242-
243-
context.saveGState()
244-
defer { context.restoreGState() }
245-
246-
// Create a rect that's inset from the edges and has proper padding
247-
// TODO: We create a new selectionRect instead of using dirtyRect
248-
// because there is a visual bug when holding down the arrow keys
249-
// to select the first or last item, which draws a clipped
250-
// rectangular highlight shape instead of the whole rectangle.
251-
// Replace this when it gets fixed.
252-
let selectionRect = NSRect(
253-
x: WINDOW_PADDING,
254-
y: 0,
255-
width: bounds.width - (WINDOW_PADDING * 2),
256-
height: bounds.height
257-
)
258-
let cornerRadius: CGFloat = 5
259-
let path = NSBezierPath(roundedRect: selectionRect, xRadius: cornerRadius, yRadius: cornerRadius)
260-
let selectionColor = NSColor.gray.withAlphaComponent(0.19)
261-
262-
context.setFillColor(selectionColor.cgColor)
263-
path.fill()
264-
}
265-
}
266-
267238
public protocol ItemBoxDelegate: AnyObject {
268239
func applyCompletionItem(_ item: CompletionItem)
269240
}

0 commit comments

Comments
 (0)