Skip to content

Commit

Permalink
Fix macOS selection crash and iOS build
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
mchakravarty committed Oct 7, 2024
1 parent 1d7902d commit 3d2f385
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Sources/CodeEditorView/CodeEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ extension CodeEditor: UIViewRepresentable {

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

if language.languageService !== codeView.language.languageService {
(codeView.optCodeStorage?.delegate as? CodeStorageDelegate)?.skipNextChangeNotificationToLanguageService = true
}
codeView.string = text
codeView.text = text
// // FIXME: Stupid hack to force redrawing when the language doesn't change. (A language change already forces
// // FIXME: redrawing.)
// if language == codeView.language {
Expand Down Expand Up @@ -395,7 +395,7 @@ extension CodeEditor: UIViewRepresentable {
}

public func makeCoordinator() -> Coordinator {
return Coordinator(text: $text, position: $position, setAction: setActions)
return Coordinator(text: $text, position: $position, setAction: setActions, setInfo: setInfo)
}

public final class Coordinator: _Coordinator {
Expand Down
8 changes: 7 additions & 1 deletion Sources/CodeEditorView/CodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,13 @@ final class CodeView: NSTextView {
// Updates only if there is an actual selection change.
if oldSelectedRanges != selectedRanges {

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

updateBackgroundFor(oldSelection: combinedRanges(ranges: oldSelectedRanges),
newSelection: combinedRanges(ranges: ranges))
Expand Down

0 comments on commit 3d2f385

Please sign in to comment.