Skip to content

Commit 3d2f385

Browse files
committed
Fix macOS selection crash and iOS build
* Multi-line selection crashes on macOS if applied to the minimap view. So, we only propagate the insertion point for now. * iOS flavour catching up on some changes in the macOS flavour.
1 parent 1d7902d commit 3d2f385

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

Sources/CodeEditorView/CodeEditor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,12 @@ extension CodeEditor: UIViewRepresentable {
359359

360360
context.coordinator.updateBindings(text: $text, position: $position, setAction: setActions, setInfo: setInfo)
361361
if codeView.lastMessages != messages { codeView.update(messages: messages) }
362-
if text != codeView.string { // Hoping for the string comparison fast path...
362+
if text != codeView.text { // Hoping for the string comparison fast path...
363363

364364
if language.languageService !== codeView.language.languageService {
365365
(codeView.optCodeStorage?.delegate as? CodeStorageDelegate)?.skipNextChangeNotificationToLanguageService = true
366366
}
367-
codeView.string = text
367+
codeView.text = text
368368
// // FIXME: Stupid hack to force redrawing when the language doesn't change. (A language change already forces
369369
// // FIXME: redrawing.)
370370
// if language == codeView.language {
@@ -395,7 +395,7 @@ extension CodeEditor: UIViewRepresentable {
395395
}
396396

397397
public func makeCoordinator() -> Coordinator {
398-
return Coordinator(text: $text, position: $position, setAction: setActions)
398+
return Coordinator(text: $text, position: $position, setAction: setActions, setInfo: setInfo)
399399
}
400400

401401
public final class Coordinator: _Coordinator {

Sources/CodeEditorView/CodeView.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,13 @@ final class CodeView: NSTextView {
733733
// Updates only if there is an actual selection change.
734734
if oldSelectedRanges != selectedRanges {
735735

736-
minimapView?.selectedRanges = selectedRanges // minimap mirrors the selection of the main code view
736+
// FIXME: The following does not succeed for anything, but setting an insertion point. From macOS 15, selecting
737+
// FIXME: across more than one line, leads to a crash.
738+
// minimapView?.setSelectedRanges(ranges, affinity: affinity, stillSelecting: stillSelectingFlag)
739+
// FIXME: Hence, we only set insertion points for now. (They lead to a line highlight.)
740+
if let insertionPoint {
741+
minimapView?.setSelectedRange(NSRange(location: insertionPoint, length: 0))
742+
}
737743

738744
updateBackgroundFor(oldSelection: combinedRanges(ranges: oldSelectedRanges),
739745
newSelection: combinedRanges(ranges: ranges))

0 commit comments

Comments
 (0)