-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
a9cb52f
commit 99d8794
Showing
4 changed files
with
53 additions
and
31 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Foundation | ||
|
||
public protocol TextSystemInterface { | ||
func clearStyle(in range: NSRange) | ||
func applyStyle(to token: Token) | ||
|
||
var length: Int { get } | ||
var visibleRange: NSRange { get } | ||
} | ||
|
||
public extension TextSystemInterface { | ||
func clearStyles(in set: IndexSet) { | ||
for range in set.nsRangeView { | ||
clearStyle(in: range) | ||
} | ||
} | ||
|
||
func applyStyles(to tokens: [Token]) { | ||
for token in tokens { | ||
applyStyle(to: token) | ||
} | ||
} | ||
|
||
func apply(_ tokenApplication: TokenApplication, to set: IndexSet) { | ||
if tokenApplication.action == .replace { | ||
clearStyles(in: set) | ||
} | ||
|
||
applyStyles(to: tokenApplication.tokens) | ||
} | ||
} |
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