Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
14b5e11a
Unverified
Commit
14b5e11a
authored
Nov 05, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
editor: tweaks to Editor for performance testing
parent
918b3f00
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
26 deletions
+31
-26
Sources/iOS/CharacterAttribute.swift
+0
-20
Sources/iOS/TextStorage.swift
+31
-6
No files found.
Sources/iOS/CharacterAttribute.swift
View file @
14b5e11a
...
...
@@ -101,26 +101,6 @@ public func CharacterAttributeToValue(attribute: CharacterAttribute) -> String {
}
}
extension
NSAttributedString
{
/**
Retrieves the character attributes that are currently applied.
- Parameter at location: An Int.
- Parameter effectiveRange: An optional NSRangePointer.
- Returns: A Dictionary of CharacterAttribute type keys and Any type values.
*/
open
func
characterAttributes
(
at
location
:
Int
,
effectiveRange
:
NSRangePointer
?)
->
[
CharacterAttribute
:
Any
]
{
var
ca
=
[
CharacterAttribute
:
Any
]()
attributes
(
at
:
location
,
effectiveRange
:
effectiveRange
)
.
forEach
{
(
key
,
value
)
in
guard
let
attribute
=
CharacterAttribute
.
init
(
rawValue
:
key
)
else
{
return
}
ca
[
attribute
]
=
value
}
return
ca
}
}
extension
NSMutableAttributedString
{
/**
Adds a character attribute to a given range.
...
...
Sources/iOS/TextStorage.swift
View file @
14b5e11a
...
...
@@ -56,10 +56,10 @@ public protocol TextStorageDelegate: NSTextStorageDelegate {
}
open
class
TextStorage
:
NSTextStorage
{
/// A storage facility for attributed text.
/// A storage facility for attributed text.
open
fileprivate
(
set
)
var
storage
:
NSMutableAttributedString
!
/// The regular expression to match text fragments against.
/// The regular expression to match text fragments against.
open
var
expression
:
NSRegularExpression
?
/// Initializer.
...
...
@@ -70,13 +70,13 @@ open class TextStorage: NSTextStorage {
/// Initializer.
public
override
init
()
{
super
.
init
()
prepareStore
()
prepareStor
ag
e
()
}
}
extension
TextStorage
{
/// Prepare the store.
fileprivate
func
prepareStore
()
{
/// Prepare the stor
ag
e.
fileprivate
func
prepareStor
ag
e
()
{
storage
=
NSMutableAttributedString
()
}
}
...
...
@@ -97,6 +97,8 @@ extension TextStorage {
(
self
.
delegate
as?
TextStorageDelegate
)?
.
textStorage
?(
textStorage
:
self
,
didProcessEditing
:
self
.
string
,
result
:
result
,
flags
:
flags
,
stop
:
stop
)
}
storage
.
fixAttributes
(
in
:
range
)
super
.
processEditing
()
}
...
...
@@ -136,4 +138,27 @@ extension TextStorage {
storage
.
setAttributes
(
attrs
,
range
:
range
)
edited
(
.
editedAttributes
,
range
:
range
,
changeInLength
:
0
)
}
/**
Adds an individual attribute.
- Parameter _ name: Attribute name.
- Parameter value: An Any type.
- Parameter range: A range of characters that will have their
attributes added.
*/
open
override
func
addAttribute
(
_
name
:
String
,
value
:
Any
,
range
:
NSRange
)
{
storage
.
addAttribute
(
name
,
value
:
value
,
range
:
range
)
edited
(
.
editedAttributes
,
range
:
range
,
changeInLength
:
0
)
}
/**
Removes an individual attribute.
- Parameter _ name: Attribute name.
- Parameter range: A range of characters that will have their
attributes removed.
*/
open
override
func
removeAttribute
(
_
name
:
String
,
range
:
NSRange
)
{
storage
.
removeAttribute
(
name
,
range
:
range
)
edited
(
.
editedAttributes
,
range
:
range
,
changeInLength
:
0
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment