Skip to content

Commit ad66b30

Browse files
Fix double click, fix width not reseting
1 parent 2dbf5e0 commit ad66b30

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

Sources/CodeEditTextView/ItemBox/ItemBoxWindowController+Window.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,24 @@ extension ItemBoxWindowController {
123123
tableView.rowSizeStyle = .custom
124124
tableView.rowHeight = 21
125125
tableView.gridStyleMask = []
126+
tableView.target = self
127+
tableView.action = #selector(tableViewClicked(_:))
126128
let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("ItemsCell"))
127129
tableView.addTableColumn(column)
128130
}
129131

132+
@objc private func tableViewClicked(_ sender: Any?) {
133+
if NSApp.currentEvent?.clickCount == 2 {
134+
let row = tableView.selectedRow
135+
guard row >= 0, row < items.count else {
136+
return
137+
}
138+
let selectedItem = items[row]
139+
delegate?.applyCompletionItem(selectedItem)
140+
self.close()
141+
}
142+
}
143+
130144
func configureScrollView() {
131145
scrollView.documentView = tableView
132146
scrollView.hasVerticalScroller = true
@@ -173,13 +187,13 @@ extension ItemBoxWindowController {
173187
let newFrame = NSRect(
174188
x: currentFrame.minX,
175189
y: bottomY,
176-
width: currentFrame.width,
190+
width: ItemBoxWindowController.DEFAULT_SIZE.width,
177191
height: newHeight
178192
)
179193
window.setFrame(newFrame, display: true)
180194
} else {
181195
// When window is below cursor, maintain the top position
182-
window.setContentSize(NSSize(width: currentFrame.width, height: newHeight))
196+
window.setContentSize(NSSize(width: ItemBoxWindowController.DEFAULT_SIZE.width, height: newHeight))
183197
}
184198

185199
// Dont allow vertical resizing

Sources/CodeEditTextView/ItemBox/ItemBoxWindowController.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,6 @@ public final class ItemBoxWindowController: NSWindowController {
196196
)
197197
}
198198

199-
@objc private func tableViewDoubleClick(_ sender: Any) {
200-
guard tableView.clickedRow >= 0 else { return }
201-
let selectedItem = items[tableView.clickedRow]
202-
delegate?.applyCompletionItem(selectedItem)
203-
self.close()
204-
}
205-
206199
private func resetScrollPosition() {
207200
guard let clipView = scrollView.contentView as? NSClipView else { return }
208201

0 commit comments

Comments
 (0)