-
Notifications
You must be signed in to change notification settings - Fork 149
Lists: Nuking Zero Width Spaces #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jleandroperez
merged 23 commits into
develop
from
issue/414-nuking-zero-width-spaces-from-text-lists
Apr 18, 2017
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
1e04997
LayoutManager: Minor cleanup
jleandroperez c2cb0d3
TextListFormatter: Adds comments
jleandroperez a7a620a
TextListFormatter: Disabling empty line placeholders
jleandroperez 9a99ac0
LayoutManager: Removes extraLineFragment Workaround for lists
jleandroperez a47ebb3
TextView: Hack hack
jleandroperez 63eee3e
AttributeFormatter: Style Updates
jleandroperez 2b6fae0
TextView: Re-Enables Redraw Workaround
jleandroperez 6e01e48
TextView: Overwritting Typing Attributes
jleandroperez a5d544c
TextView: Cleanup
jleandroperez 03066ff
TextListFormatter: Revers faulty update
jleandroperez 463dc88
TextView: Updates refreshStylesAfterDeletion
jleandroperez 57f1aec
TextStorage: Updates Style
jleandroperez 39176ef
TextView: New Unit Tests
jleandroperez 08b9951
TextView: Fixing newline behavior
jleandroperez af9a78f
TextView: Updates ensureRemovalOfListAttribute Logic
jleandroperez f33abea
TextView: Updates Newline Insertion Logic
jleandroperez 5b148d4
TextView: Wiring List Formatter Check
jleandroperez 9ba0490
TextViewTests: New Unit Tests
jleandroperez f2e0f47
Implements new NSAttributedString Helper
jleandroperez 6e51226
TextView: New Unit Test
jleandroperez d4755a9
TextView: Fixing unit test
jleandroperez c98217d
TextView: New Unit Test
jleandroperez ec35ce0
TextView: Addressing Unit Tests Comments
jleandroperez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,53 +1,83 @@ | ||
| import Foundation | ||
| import UIKit | ||
|
|
||
|
|
||
| // MARK: - Lists Formatter | ||
| // | ||
| class TextListFormatter: ParagraphAttributeFormatter { | ||
|
|
||
|
|
||
| /// Style of the list | ||
| /// | ||
| let listStyle: TextList.Style | ||
|
|
||
| /// Attributes to be added by default | ||
| /// | ||
| let placeholderAttributes: [String : Any]? | ||
|
|
||
|
|
||
| /// Designated Initializer | ||
| /// | ||
| init(style: TextList.Style, placeholderAttributes: [String : Any]? = nil) { | ||
| self.listStyle = style | ||
| self.placeholderAttributes = placeholderAttributes | ||
| } | ||
|
|
||
|
|
||
| // MARK: - Overwriten Methods | ||
|
|
||
| func apply(to attributes: [String : Any]) -> [String: Any] { | ||
| var resultingAttributes = attributes | ||
| let newParagraphStyle = ParagraphStyle() | ||
| if let paragraphStyle = attributes[NSParagraphStyleAttributeName] as? NSParagraphStyle { | ||
| newParagraphStyle.setParagraphStyle(paragraphStyle) | ||
| } | ||
|
|
||
| if newParagraphStyle.textList == nil { | ||
| newParagraphStyle.headIndent += Metrics.listTextIndentation | ||
| newParagraphStyle.firstLineHeadIndent += Metrics.listTextIndentation | ||
| } | ||
|
|
||
| newParagraphStyle.textList = TextList(style: self.listStyle) | ||
|
|
||
| var resultingAttributes = attributes | ||
| resultingAttributes[NSParagraphStyleAttributeName] = newParagraphStyle | ||
|
|
||
| return resultingAttributes | ||
| } | ||
|
|
||
| func remove(from attributes:[String: Any]) -> [String: Any] { | ||
| var resultingAttributes = attributes | ||
| let newParagraphStyle = ParagraphStyle() | ||
| func remove(from attributes: [String: Any]) -> [String: Any] { | ||
| guard let paragraphStyle = attributes[NSParagraphStyleAttributeName] as? ParagraphStyle, | ||
| paragraphStyle.textList?.style == self.listStyle | ||
| else { | ||
| return resultingAttributes | ||
| return attributes | ||
| } | ||
|
|
||
| let newParagraphStyle = ParagraphStyle() | ||
| newParagraphStyle.setParagraphStyle(paragraphStyle) | ||
| newParagraphStyle.headIndent -= Metrics.listTextIndentation | ||
| newParagraphStyle.firstLineHeadIndent -= Metrics.listTextIndentation | ||
| newParagraphStyle.textList = nil | ||
|
|
||
| var resultingAttributes = attributes | ||
| resultingAttributes[NSParagraphStyleAttributeName] = newParagraphStyle | ||
|
|
||
| return resultingAttributes | ||
| } | ||
|
|
||
| func present(in attributes: [String : Any]) -> Bool { | ||
| guard let paragraphStyle = attributes[NSParagraphStyleAttributeName] as? ParagraphStyle, | ||
| let textList = paragraphStyle.textList else { | ||
| guard let style = attributes[NSParagraphStyleAttributeName] as? ParagraphStyle, let list = style.textList else { | ||
| return false | ||
| } | ||
| return textList.style == listStyle | ||
|
|
||
| return list.style == listStyle | ||
| } | ||
|
|
||
| func needsEmptyLinePlaceholder() -> Bool { | ||
| return false | ||
| } | ||
|
|
||
| static func listsOfAnyKindPresent(in attributes: [String: Any]) -> Bool { | ||
| let style = attributes[NSParagraphStyleAttributeName] as? ParagraphStyle | ||
| return style?.textList != nil | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider adding extra documentation to explain why this is necessary. Specifically something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, thank you!