-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb1d382
commit 12be418
Showing
14 changed files
with
155 additions
and
78 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Sources/CodeEditTextView/Extensions/NSRange+/NSRange+init.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// NSRange.swift | ||
// CodeEditTextView | ||
// | ||
// Created by Khan Winter on 8/20/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NSRange { | ||
@inline(__always) | ||
init(start: Int, end: Int) { | ||
self.init(location: start, length: end - start) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Sources/CodeEditTextView/TextSelectionManager/Destination.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// Destination.swift | ||
// CodeEditTextView | ||
// | ||
// Created by Khan Winter on 8/20/24. | ||
// | ||
|
||
public extension TextSelectionManager { | ||
public enum Destination { | ||
case character | ||
case word | ||
case line | ||
case visualLine | ||
case page | ||
case document | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Sources/CodeEditTextView/TextSelectionManager/Direction.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Direction.swift | ||
// CodeEditTextView | ||
// | ||
// Created by Khan Winter on 8/20/24. | ||
// | ||
|
||
public extension TextSelectionManager { | ||
public enum Direction { | ||
case up | ||
case down | ||
case forward | ||
case backward | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Sources/CodeEditTextView/TextSelectionManager/TextSelection.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// TextSelection.swift | ||
// CodeEditTextView | ||
// | ||
// Created by Khan Winter on 8/20/24. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
|
||
public extension TextSelectionManager { | ||
public class TextSelection: Hashable, Equatable { | ||
public var range: NSRange | ||
weak var view: NSView? | ||
var boundingRect: CGRect = .zero | ||
var suggestedXPos: CGFloat? | ||
/// The position this selection should 'rotate' around when modifying selections. | ||
var pivot: Int? | ||
|
||
init(range: NSRange, view: CursorView? = nil) { | ||
self.range = range | ||
self.view = view | ||
} | ||
|
||
var isCursor: Bool { | ||
range.length == 0 | ||
} | ||
|
||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(range) | ||
} | ||
|
||
public static func == (lhs: TextSelection, rhs: TextSelection) -> Bool { | ||
lhs.range == rhs.range | ||
} | ||
} | ||
} | ||
|
||
private extension TextSelectionManager.TextSelection { | ||
func didInsertText(length: Int, retainLength: Bool = false) { | ||
if !retainLength { | ||
range.length = 0 | ||
} | ||
range.location += length | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters