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
a9eafa58
Unverified
Commit
a9eafa58
authored
Nov 04, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
editor: fixed issue where regular expression was not set upon initialization
parent
c693872f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
45 deletions
+32
-45
Sources/iOS/Editor.swift
+20
-25
Sources/iOS/TextStorage.swift
+12
-20
No files found.
Sources/iOS/Editor.swift
View file @
a9eafa58
...
...
@@ -33,36 +33,26 @@ import UIKit
@objc(EditorDelegate)
public
protocol
EditorDelegate
{
/**
An optional delegation method that is executed when
text will be processed during editing.
- Parameter text: The Text instance assodicated with the
delegation object.
- Parameter textStorage: The TextStorage instance
associated with the delegation object.
- Parameter string: The string value that is currently
being edited.
- Parameter range: The range of characters that are being
edited.
A delegation method that is executed when text will be
processed during editing.
- Parameter editor: An Editor.
- Parameter willProcessEditing textStorage: A TextStorage.
- Parameter text: A String.
- Parameter range: A NSRange.
*/
@objc
optional
func
editor
(
editor
:
Editor
,
willProcess
textStorage
:
TextStorage
,
string
:
String
,
range
:
NSRange
)
optional
func
editor
(
editor
:
Editor
,
willProcess
Editing
textStorage
:
TextStorage
,
text
:
String
,
range
:
NSRange
)
/**
An optional delegation method that is executed after
the edit processing has completed.
- Parameter text: The Text instance assodicated with the
delegation object.
- Parameter textStorage: The TextStorage instance
associated with the delegation object.
- Parameter string: The string value that was edited.
- Parameter result: A NSTextCheckingResult associated
with the processing result.
- Parameter flags: Matching flags.
- Parameter stop: Halts a service which is either
publishing or resolving.
A delegation method that is executed when text has been
processed after editing.
- Parameter editor: An Editor.
- Parameter didProcessEditing textStorage: A TextStorage.
- Parameter text: A String.
- Parameter range: A NSRange.
*/
@objc
optional
func
editor
(
editor
:
Editor
,
didProcess
textStorage
:
TextStorage
,
string
:
String
,
result
:
NSTextCheckingResult
?,
flags
:
NSRegularExpression
.
MatchingFlags
,
stop
:
UnsafeMutablePointer
<
ObjCBool
>
)
optional
func
editor
(
editor
:
Editor
,
didProcess
Editing
textStorage
:
TextStorage
,
text
:
String
,
range
:
NSRange
)
}
open
class
Editor
:
View
{
...
...
@@ -124,6 +114,7 @@ open class Editor: View {
prepareTextContainer
()
prepareLayoutManager
()
prepareTextStorage
()
prepareRegularExpression
()
prepareTextView
()
}
}
...
...
@@ -161,10 +152,14 @@ extension Editor {
extension
Editor
:
TextStorageDelegate
{
open
func
textStorage
(
textStorage
:
TextStorage
,
willProcessEditing
text
:
String
,
range
:
NSRange
)
{
delegate
?
.
editor
?(
editor
:
self
,
willProcessEditing
:
textStorage
,
text
:
string
,
range
:
range
)
}
open
func
textStorage
(
textStorage
:
TextStorage
,
didProcessEditing
text
:
String
,
result
:
NSTextCheckingResult
?,
flags
:
NSRegularExpression
.
MatchingFlags
,
stop
:
UnsafeMutablePointer
<
ObjCBool
>
)
{
guard
let
range
=
result
?
.
range
else
{
return
}
delegate
?
.
editor
?(
editor
:
self
,
didProcessEditing
:
textStorage
,
text
:
string
,
range
:
range
)
}
}
Sources/iOS/TextStorage.swift
View file @
a9eafa58
...
...
@@ -57,7 +57,7 @@ public protocol TextStorageDelegate: NSTextStorageDelegate {
open
class
TextStorage
:
NSTextStorage
{
/// A storage facility for attributed text.
open
fileprivate
(
set
)
var
store
:
NSMutableAttributedString
!
open
fileprivate
(
set
)
var
stor
ag
e
:
NSMutableAttributedString
!
/// The regular expression to match text fragments against.
open
var
expression
:
NSRegularExpression
?
...
...
@@ -72,34 +72,29 @@ open class TextStorage: NSTextStorage {
super
.
init
()
prepareStore
()
}
}
extension
TextStorage
{
/// Prepare the store.
fileprivate
func
prepareStore
()
{
store
=
NSMutableAttributedString
()
stor
ag
e
=
NSMutableAttributedString
()
}
}
extension
TextStorage
{
/// A String value of the attirbutedString property.
open
override
var
string
:
String
{
return
store
.
string
return
stor
ag
e
.
string
}
/// Processes the text when editing.
open
override
func
processEditing
()
{
let
range
:
NSRange
=
(
string
as
NSString
)
.
paragraphRange
(
for
:
editedRange
)
let
range
=
(
string
as
NSString
)
.
paragraphRange
(
for
:
editedRange
)
(
delegate
as?
TextStorageDelegate
)?
.
textStorage
?(
textStorage
:
self
,
willProcessEditing
:
string
,
range
:
range
)
expression
!.
enumerateMatches
(
in
:
string
,
options
:
[],
range
:
range
)
{
[
weak
self
]
(
result
:
NSTextCheckingResult
?,
flags
:
NSRegularExpression
.
MatchingFlags
,
stop
:
UnsafeMutablePointer
<
ObjCBool
>
)
->
Void
in
guard
let
s
=
self
else
{
return
}
(
s
.
delegate
as?
TextStorageDelegate
)?
.
textStorage
!
(
textStorage
:
s
,
didProcessEditing
:
s
.
string
,
result
:
result
,
flags
:
flags
,
stop
:
stop
)
expression
?
.
enumerateMatches
(
in
:
string
,
options
:
[],
range
:
range
)
{
[
unowned
self
]
(
result
:
NSTextCheckingResult
?,
flags
:
NSRegularExpression
.
MatchingFlags
,
stop
:
UnsafeMutablePointer
<
ObjCBool
>
)
->
Void
in
(
self
.
delegate
as?
TextStorageDelegate
)?
.
textStorage
?(
textStorage
:
self
,
didProcessEditing
:
self
.
string
,
result
:
result
,
flags
:
flags
,
stop
:
stop
)
}
super
.
processEditing
()
...
...
@@ -107,9 +102,8 @@ extension TextStorage {
/**
Returns the attributes for the character at a given index.
- Parameter location: The index for which to return attributes.
This value must lie within the bounds of the receiver.
- Parameter range: Upon return, the range over which the
- Parameter location: An Int
- Parameter effectiveRange range: Upon return, the range over which the
attributes and values are the same as those at index. This range
isn’t necessarily the maximum range covered, and its extent is
implementation-dependent. If you need the maximum range, use
...
...
@@ -117,8 +111,8 @@ extension TextStorage {
If you don't need this value, pass NULL.
- Returns: The attributes for the character at index.
*/
open
override
func
attributes
(
at
location
:
Int
,
effectiveRange
range
:
NSRangePointer
?)
->
[
String
:
Any
]
{
return
store
.
attributes
(
at
:
location
,
effectiveRange
:
range
)
open
override
func
attributes
(
at
location
:
Int
,
effectiveRange
range
:
NSRangePointer
?)
->
[
String
:
Any
]
{
return
stor
ag
e
.
attributes
(
at
:
location
,
effectiveRange
:
range
)
}
/**
...
...
@@ -128,8 +122,7 @@ extension TextStorage {
will be replaced with.
*/
open
override
func
replaceCharacters
(
in
range
:
NSRange
,
with
str
:
String
)
{
store
.
replaceCharacters
(
in
:
range
,
with
:
str
)
storage
.
replaceCharacters
(
in
:
range
,
with
:
str
)
edited
(
.
editedCharacters
,
range
:
range
,
changeInLength
:
str
.
utf16
.
count
-
range
.
length
)
}
...
...
@@ -140,8 +133,7 @@ extension TextStorage {
attributes updated.
*/
open
override
func
setAttributes
(
_
attrs
:
[
String
:
Any
]?,
range
:
NSRange
)
{
store
.
setAttributes
(
attrs
,
range
:
range
)
storage
.
setAttributes
(
attrs
,
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