Skip to content

Commit

Permalink
Introduce the SelectionSet type
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Dec 28, 2024
1 parent 66e5fa5 commit 53e0ea9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ extension KeyModifierFlags {
}

open class MultiCursorTextView: NSTextView {
// this is a retain cycle, but it's convenient
private lazy var coordinator = TextSystemCursorCoordinator(
textView: self,
system: IBeamTextViewSystem(textView: self)
Expand Down
5 changes: 5 additions & 0 deletions Sources/IBeam/MultiCursorState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public final class MultiCursorState<System: TextSystem> {
public var textSystem: System {
processor.textSystem
}

public var cursorSet: CursorSet<TextRange> {
// this is very inefficient
CursorSet(ranges: cursors.map({ $0.textRange }))
}
}

extension MultiCursorState {
Expand Down
11 changes: 11 additions & 0 deletions Sources/IBeam/SelectionSet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public struct CursorSet<TextRange> {
public let ranges: [TextRange]

public init(ranges: [TextRange] = []) {
self.ranges = ranges
}
}

extension CursorSet: Equatable where TextRange: Equatable {}
extension CursorSet: Hashable where TextRange: Hashable {}
extension CursorSet: Sendable where TextRange: Sendable {}

0 comments on commit 53e0ea9

Please sign in to comment.