Skip to content

Commit afc302e

Browse files
Small updates
1 parent 9947256 commit afc302e

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/CodeEditSourceEditor/CodeEditSourceEditor/CodeEditSourceEditor.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
4242
/// character's width between characters, etc. Defaults to `1.0`
4343
/// - bracketPairHighlight: The type of highlight to use to highlight bracket pairs.
4444
/// See `BracketPairHighlight` for more information. Defaults to `nil`
45+
/// - useSystemCursor: If true, uses the system cursor on `>=macOS 14`.
4546
/// - undoManager: The undo manager for the text view. Defaults to `nil`, which will create a new CEUndoManager
4647
/// - coordinators: Any text coordinators for the view to use. See ``TextViewCoordinator`` for more information.
4748
public init(
@@ -190,7 +191,6 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
190191

191192
public typealias NSViewControllerType = TextViewController
192193

193-
// TODO: SET COMPLETIONPROVIDER FOR TEXTVIEW
194194
public func makeNSViewController(context: Context) -> TextViewController {
195195
let controller = TextViewController(
196196
string: "",
@@ -235,7 +235,6 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
235235
Coordinator(text: text, cursorPositions: cursorPositions)
236236
}
237237

238-
// TODO: SET COMPLETIONPROVIDER FOR TEXTVIEW
239238
public func updateNSViewController(_ controller: TextViewController, context: Context) {
240239
if !context.coordinator.isUpdateFromTextView {
241240
// Prevent infinite loop of update notifications
@@ -302,6 +301,10 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
302301
controller.letterSpacing = letterSpacing
303302
}
304303

304+
if controller.useSystemCursor != useSystemCursor {
305+
controller.useSystemCursor = useSystemCursor
306+
}
307+
305308
controller.bracketPairHighlight = bracketPairHighlight
306309
}
307310

@@ -322,7 +325,8 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
322325
controller.indentOption == indentOption &&
323326
controller.tabWidth == tabWidth &&
324327
controller.letterSpacing == letterSpacing &&
325-
controller.bracketPairHighlight == bracketPairHighlight
328+
controller.bracketPairHighlight == bracketPairHighlight &&
329+
controller.useSystemCursor == useSystemCursor
326330
}
327331
}
328332

Sources/CodeEditSourceEditor/CodeSuggestion/SuggestionController+Window.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ import AppKit
99

1010
extension SuggestionController {
1111
/// Will constrain the window's frame to be within the visible screen
12-
public func constrainWindowToScreenEdges(cursorRect: NSRect) {
12+
public func constrainWindowToScreenEdges(cursorRect: NSRect, horizontalOffset: CGFloat) {
1313
guard let window = self.window,
1414
let screenFrame = window.screen?.visibleFrame else {
1515
return
1616
}
1717

1818
let windowSize = window.frame.size
1919
let padding: CGFloat = 22
20-
// TODO: PASS IN OFFSET
2120
var newWindowOrigin = NSPoint(
22-
x: cursorRect.origin.x - Self.WINDOW_PADDING - 13 - 16.5,
21+
x: cursorRect.origin.x - Self.WINDOW_PADDING - horizontalOffset,
2322
y: cursorRect.origin.y
2423
)
2524

@@ -237,7 +236,8 @@ extension SuggestionController: NSTableViewDataSource, NSTableViewDelegate {
237236
}
238237

239238
public func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
240-
(items[row] as? any CodeSuggestionEntry)?.view
239+
guard row >= 0, row < items.count else { return nil }
240+
return (items[row] as? any CodeSuggestionEntry)?.view
241241
}
242242

243243
public func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
@@ -254,6 +254,7 @@ extension SuggestionController: NSTableViewDataSource, NSTableViewDelegate {
254254
}
255255
}
256256

257+
/// Used to draw a custom selection highlight for the table row
257258
private class CodeSuggestionRowView: NSTableRowView {
258259
override func drawSelection(in dirtyRect: NSRect) {
259260
guard isSelected else { return }

Sources/CodeEditSourceEditor/CodeSuggestion/SuggestionController.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,3 @@ public final class SuggestionController: NSWindowController {
252252
removeEventMonitors()
253253
}
254254
}
255-
256-
public protocol SuggestionControllerDelegate: AnyObject {
257-
func applyCompletionItem(item: CompletionItem)
258-
func onClose()
259-
func onCompletion()
260-
func onCursorMove()
261-
func onItemSelect(item: CompletionItem)
262-
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// SuggestionControllerDelegate.swift
3+
// CodeEditSourceEditor
4+
//
5+
// Created by Abe Malla on 12/26/24.
6+
//
7+
8+
import LanguageServerProtocol
9+
10+
public protocol SuggestionControllerDelegate: AnyObject {
11+
func applyCompletionItem(item: CompletionItem)
12+
func onClose()
13+
func onCompletion()
14+
func onCursorMove()
15+
func onItemSelect(item: CompletionItem)
16+
}

0 commit comments

Comments
 (0)