diff --git a/Sources/CodeEditTextView/ItemBox/ItemBoxWindowController+Window.swift b/Sources/CodeEditTextView/ItemBox/ItemBoxWindowController+Window.swift index 65ef35a1..4a93697e 100644 --- a/Sources/CodeEditTextView/ItemBox/ItemBoxWindowController+Window.swift +++ b/Sources/CodeEditTextView/ItemBox/ItemBoxWindowController+Window.swift @@ -123,10 +123,24 @@ extension ItemBoxWindowController { tableView.rowSizeStyle = .custom tableView.rowHeight = 21 tableView.gridStyleMask = [] + tableView.target = self + tableView.action = #selector(tableViewClicked(_:)) let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("ItemsCell")) tableView.addTableColumn(column) } + @objc private func tableViewClicked(_ sender: Any?) { + if NSApp.currentEvent?.clickCount == 2 { + let row = tableView.selectedRow + guard row >= 0, row < items.count else { + return + } + let selectedItem = items[row] + delegate?.applyCompletionItem(selectedItem) + self.close() + } + } + func configureScrollView() { scrollView.documentView = tableView scrollView.hasVerticalScroller = true @@ -173,13 +187,13 @@ extension ItemBoxWindowController { let newFrame = NSRect( x: currentFrame.minX, y: bottomY, - width: currentFrame.width, + width: ItemBoxWindowController.DEFAULT_SIZE.width, height: newHeight ) window.setFrame(newFrame, display: true) } else { // When window is below cursor, maintain the top position - window.setContentSize(NSSize(width: currentFrame.width, height: newHeight)) + window.setContentSize(NSSize(width: ItemBoxWindowController.DEFAULT_SIZE.width, height: newHeight)) } // Dont allow vertical resizing diff --git a/Sources/CodeEditTextView/ItemBox/ItemBoxWindowController.swift b/Sources/CodeEditTextView/ItemBox/ItemBoxWindowController.swift index 81566ab7..90737d17 100644 --- a/Sources/CodeEditTextView/ItemBox/ItemBoxWindowController.swift +++ b/Sources/CodeEditTextView/ItemBox/ItemBoxWindowController.swift @@ -196,13 +196,6 @@ public final class ItemBoxWindowController: NSWindowController { ) } - @objc private func tableViewDoubleClick(_ sender: Any) { - guard tableView.clickedRow >= 0 else { return } - let selectedItem = items[tableView.clickedRow] - delegate?.applyCompletionItem(selectedItem) - self.close() - } - private func resetScrollPosition() { guard let clipView = scrollView.contentView as? NSClipView else { return }