88import AppKit
99import LanguageServerProtocol
1010
11+ // TODO:
1112// DOCUMENTATION BAR BEHAVIOR:
1213// IF THE DOCUMENTATION BAR APPEARS WHEN SELECTING AN ITEM AND IT EXTENDS BELOW THE SCREEN, IT WILL FLIP THE DIRECTION OF THE ENTIRE WINDOW
1314// IF IT GETS FLIPPED AND THEN THE DOCUMENTATION BAR DISAPPEARS FOR EXAMPLE, IT WONT FLIP BACK EVEN IF THERES SPACE NOW
@@ -61,7 +62,7 @@ public final class ItemBoxWindowController: NSWindowController {
6162 label. textColor = . secondaryLabelColor
6263 label. alignment = . center
6364 label. translatesAutoresizingMaskIntoConstraints = false
64- label. isHidden = true
65+ label. isHidden = false
6566 // TODO: GET FONT SIZE FROM THEME
6667 label. font = . monospacedSystemFont( ofSize: 12 , weight: . regular)
6768 return label
@@ -80,7 +81,6 @@ public final class ItemBoxWindowController: NSWindowController {
8081 configureTableView ( )
8182 configureScrollView ( )
8283 setupNoItemsLabel ( )
83- configurePopover ( )
8484 }
8585
8686 required init ? ( coder: NSCoder ) {
@@ -234,7 +234,6 @@ public final class ItemBoxWindowController: NSWindowController {
234234 tableView. rowSizeStyle = . custom
235235 tableView. rowHeight = 21
236236 tableView. gridStyleMask = [ ]
237-
238237 let column = NSTableColumn ( identifier: NSUserInterfaceItemIdentifier ( " ItemsCell " ) )
239238 tableView. addTableColumn ( column)
240239 }
@@ -262,36 +261,6 @@ public final class ItemBoxWindowController: NSWindowController {
262261 ] )
263262 }
264263
265- private func configurePopover( ) {
266- // popover.behavior = .transient
267- // popover.animates = true
268-
269- // Create and configure the popover content
270- let contentViewController = NSViewController ( )
271- let contentView = NSView ( )
272- contentView. translatesAutoresizingMaskIntoConstraints = false
273-
274- let textField = NSTextField ( labelWithString: " Example Documentation \n This is some example documentation text. " )
275- textField. translatesAutoresizingMaskIntoConstraints = false
276- textField. lineBreakMode = . byWordWrapping
277- textField. preferredMaxLayoutWidth = 300
278- textField. cell? . wraps = true
279- textField. cell? . isScrollable = false
280-
281- contentView. addSubview ( textField)
282-
283- NSLayoutConstraint . activate ( [
284- textField. topAnchor. constraint ( equalTo: contentView. topAnchor) ,
285- textField. leadingAnchor. constraint ( equalTo: contentView. leadingAnchor) ,
286- textField. trailingAnchor. constraint ( equalTo: contentView. trailingAnchor) ,
287- textField. bottomAnchor. constraint ( equalTo: contentView. bottomAnchor) ,
288- contentView. widthAnchor. constraint ( equalToConstant: 300 )
289- ] )
290-
291- contentViewController. view = contentView
292- popover. contentViewController = contentViewController
293- }
294-
295264 private func setupNoItemsLabel( ) {
296265 window? . contentView? . addSubview ( noItemsLabel)
297266
@@ -325,28 +294,22 @@ public final class ItemBoxWindowController: NSWindowController {
325294 return nil
326295 case 125 , 126 : // Down/Up Arrow
327296 self . tableView. keyDown ( with: event)
328- return nil
297+ if self . isVisible {
298+ return nil
299+ }
300+ return event
329301 case 124 : // Right Arrow
330302// handleRightArrow()
303+ self . close ( )
331304 return event
332305 case 123 : // Left Arrow
306+ self . close ( )
333307 return event
334308 case 36 , 48 : // Return/Tab
335- // TODO: TEMPORARY
309+ guard tableView . selectedRow >= 0 else { return event }
336310 let selectedItem = items [ tableView. selectedRow]
337311 self . delegate? . applyCompletionItem ( selectedItem)
338-
339- if items. count > 0 {
340- var nextRow = tableView. selectedRow
341- if nextRow == items. count - 1 && items. count > 1 {
342- nextRow -= 1
343- }
344- items. remove ( at: tableView. selectedRow)
345- if nextRow < items. count {
346- tableView. selectRowIndexes ( IndexSet ( integer: nextRow) , byExtendingSelection: false )
347- tableView. scrollRowToVisible ( nextRow)
348- }
349- }
312+ self . close ( )
350313 return nil
351314 default :
352315 return event
@@ -372,11 +335,8 @@ public final class ItemBoxWindowController: NSWindowController {
372335 !popover. isShown else {
373336 return
374337 }
375-
376- // Get the rect of the selected row in window coordinates
377338 let rowRect = tableView. rect ( ofRow: selectedRow)
378339 let rowRectInWindow = tableView. convert ( rowRect, to: nil )
379- // Calculate the point where the popover should appear
380340 let popoverPoint = NSPoint (
381341 x: window. frame. maxX,
382342 y: window. frame. minY + rowRectInWindow. midY
@@ -425,6 +385,13 @@ public final class ItemBoxWindowController: NSWindowController {
425385 window. minSize = NSSize ( width: Self . DEFAULT_SIZE. width, height: newHeight)
426386 }
427387
388+ @objc private func tableViewDoubleClick( _ sender: Any ) {
389+ guard tableView. clickedRow >= 0 else { return }
390+ let selectedItem = items [ tableView. clickedRow]
391+ delegate? . applyCompletionItem ( selectedItem)
392+ self . close ( )
393+ }
394+
428395 /// Calculate the window height for a given number of rows.
429396 private static func rowsToWindowHeight( for numberOfRows: CGFloat ) -> CGFloat {
430397 let wholeRows = floor ( numberOfRows)
0 commit comments