Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6f539ae
Work in progress.
diegoreymendez Apr 6, 2017
d88d575
Visual-only elements can no longer be introduced by keyboard input.
diegoreymendez Apr 6, 2017
96cc5f8
Committing for pair programming.
diegoreymendez Apr 10, 2017
1c83349
Merges the latest from develop.
diegoreymendez Apr 21, 2017
e70017c
Merges the latest from develop.
diegoreymendez Apr 21, 2017
5aeb11b
Adds some flags to try a hack to fix a really annoying issue.
diegoreymendez Apr 21, 2017
a996292
Adds a few improvements for newline handling.
diegoreymendez Apr 22, 2017
625aea8
WIP: Several improvements for style management.
diegoreymendez Apr 24, 2017
1005dd7
Improves the editing logic.
diegoreymendez Apr 24, 2017
fe607a3
Fixes a problem with some extra newlines being automatically added.
diegoreymendez Apr 24, 2017
b9bfd20
Fixes a previous faulty fix. :)
diegoreymendez Apr 24, 2017
53953d3
Removes a lot of unnecessary code.
diegoreymendez Apr 24, 2017
5d5513c
The unit tests compile again, still fixing them.
diegoreymendez Apr 24, 2017
f16292b
Fixes several tests and improves the logic.
diegoreymendez Apr 24, 2017
92a8f76
Fixes the logic for the removal of single-line attributes.
diegoreymendez Apr 24, 2017
0f54b33
Fixes some issues.
diegoreymendez Apr 24, 2017
34b89fc
Fixes some issues with lists.
diegoreymendez Apr 24, 2017
2b2b689
Fixes some issues with lists.
diegoreymendez Apr 24, 2017
c5c9084
Fixes several unit tests.
diegoreymendez Apr 24, 2017
79de3da
Fixes some issues with the paragraph style.
diegoreymendez Apr 24, 2017
20bf19b
Fixes a unit test.
diegoreymendez Apr 24, 2017
c03d123
Fixes a unit test.
diegoreymendez Apr 24, 2017
a433695
Adds initial support for lists.
diegoreymendez Apr 24, 2017
4b96727
Fixes an issue with selection changes.
diegoreymendez Apr 24, 2017
71c21a0
Fixes a crashing bug.
diegoreymendez Apr 24, 2017
b64f9d3
Fixes a unit test.
diegoreymendez Apr 24, 2017
0e8168b
Fixes 2 unit tests.
diegoreymendez Apr 24, 2017
c44f574
Improves lists handling.
diegoreymendez Apr 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Aztec.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
F19587CF1EA7ECEE0078DD9C /* String+VisualRangeMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = F19587CE1EA7ECEE0078DD9C /* String+VisualRangeMapping.swift */; };
F19587D11EA7EEEE0078DD9C /* StringVisualRangeMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F19587D01EA7EEEE0078DD9C /* StringVisualRangeMappingTests.swift */; };
F1A218151E02D5B3000AF5EB /* UndoManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A218141E02D5B3000AF5EB /* UndoManager.swift */; };
F1ABC1B11EAE279D002E52FE /* HTMLParagraphFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1ABC1B01EAE279D002E52FE /* HTMLParagraphFormatter.swift */; };
F1ABC1B31EAE2816002E52FE /* HTMLParagraph.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1ABC1B21EAE2816002E52FE /* HTMLParagraph.swift */; };
F1C05B991E37F99D007510EA /* Character+Name.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1C05B981E37F99D007510EA /* Character+Name.swift */; };
F1C05B9D1E37FA77007510EA /* String+CharacterName.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1C05B9C1E37FA77007510EA /* String+CharacterName.swift */; };
F1C05B9F1E37FD2F007510EA /* NSAttributedString+CharacterName.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1C05B9E1E37FD2F007510EA /* NSAttributedString+CharacterName.swift */; };
Expand Down Expand Up @@ -238,6 +240,8 @@
F19587CE1EA7ECEE0078DD9C /* String+VisualRangeMapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+VisualRangeMapping.swift"; sourceTree = "<group>"; };
F19587D01EA7EEEE0078DD9C /* StringVisualRangeMappingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringVisualRangeMappingTests.swift; sourceTree = "<group>"; };
F1A218141E02D5B3000AF5EB /* UndoManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UndoManager.swift; sourceTree = "<group>"; };
F1ABC1B01EAE279D002E52FE /* HTMLParagraphFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLParagraphFormatter.swift; sourceTree = "<group>"; };
F1ABC1B21EAE2816002E52FE /* HTMLParagraph.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLParagraph.swift; sourceTree = "<group>"; };
F1C05B981E37F99D007510EA /* Character+Name.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Character+Name.swift"; sourceTree = "<group>"; };
F1C05B9C1E37FA77007510EA /* String+CharacterName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+CharacterName.swift"; sourceTree = "<group>"; };
F1C05B9E1E37FD2F007510EA /* NSAttributedString+CharacterName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+CharacterName.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -490,9 +494,11 @@
599F252E1D8BC9A1002871D6 /* TextKit */ = {
isa = PBXGroup;
children = (
FF7C89A71E3A2B7C000472A8 /* Blockquote.swift */,
B5AF89311E93CFC80051EFDB /* RenderableAttachmentDelegate.swift */,
B572AC271E817CFE008948C2 /* CommentAttachment.swift */,
B57D1C3C1E92C38000EA4B16 /* HTMLAttachment.swift */,
F1ABC1B21EAE2816002E52FE /* HTMLParagraph.swift */,
FF7A1C501E5651EA00C4C7C8 /* LineAttachment.swift */,
599F25301D8BC9A1002871D6 /* MediaAttachment.swift */,
FF4E265F1EA8DF1E005E8E42 /* ImageAttachment.swift */,
Expand All @@ -502,7 +508,6 @@
599F25321D8BC9A1002871D6 /* TextView.swift */,
E109B51B1DC33F2C0099605E /* LayoutManager.swift */,
FFA61E881DF18F3D00B71BF6 /* ParagraphStyle.swift */,
FF7C89A71E3A2B7C000472A8 /* Blockquote.swift */,
);
path = TextKit;
sourceTree = "<group>";
Expand Down Expand Up @@ -583,6 +588,7 @@
FF7C89AB1E3A47F1000472A8 /* StandardAttributeFormatter.swift */,
E1C163A41DB6056B00E66A83 /* BlockquoteFormatter.swift */,
FF13CD4C1E5C8067000FF10E /* HeaderFormatter.swift */,
F1ABC1B01EAE279D002E52FE /* HTMLParagraphFormatter.swift */,
FF8F85831E84162900C12BB4 /* PreFormatter.swift */,
B5B86D3B1DA41A550083DB3F /* TextListFormatter.swift */,
FFD436951E300EF700A0E26F /* FontFormatter.swift */,
Expand Down Expand Up @@ -789,6 +795,7 @@
599F25471D8BC9A1002871D6 /* HTMLConstants.swift in Sources */,
599F25371D8BC9A1002871D6 /* InAttributeConverter.swift in Sources */,
599F25531D8BC9A1002871D6 /* TextStorage.swift in Sources */,
F1ABC1B11EAE279D002E52FE /* HTMLParagraphFormatter.swift in Sources */,
B572AC281E817CFE008948C2 /* CommentAttachment.swift in Sources */,
F1FA0E861E6EF514009D98EE /* Node.swift in Sources */,
599F253C1D8BC9A1002871D6 /* OutHTMLAttributeConverter.swift in Sources */,
Expand Down Expand Up @@ -845,6 +852,7 @@
599F25391D8BC9A1002871D6 /* InHTMLConverter.swift in Sources */,
F10BE6181EA7ADA6002E4625 /* NSMutableAttributedString+ReplaceOcurrences.swift in Sources */,
F1A218151E02D5B3000AF5EB /* UndoManager.swift in Sources */,
F1ABC1B31EAE2816002E52FE /* HTMLParagraph.swift in Sources */,
FFA61EC21DF6C1C900B71BF6 /* NSAttributedString+Archive.swift in Sources */,
599F253E1D8BC9A1002871D6 /* OutHTMLNodeConverter.swift in Sources */,
E109B51C1DC33F2C0099605E /* LayoutManager.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class HMTLNodeToNSAttributedString: SafeConverter {
.h4: HeaderFormatter(headerLevel: .h4),
.h5: HeaderFormatter(headerLevel: .h5),
.h6: HeaderFormatter(headerLevel: .h6),
.p: HTMLParagraphFormatter(),
.pre: PreFormatter(),
.video: VideoFormatter()
]
Expand Down
40 changes: 40 additions & 0 deletions Aztec/Classes/Extensions/String+EndOfLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ extension String {
return isEmptyParagraph(at: index)
}

/// Checks if the receiver has an empty paragraph at the specified offset and if the offset
/// corresponds to EOF (end-of-file).
///
/// - Parameters:
/// - offset: the receiver's offset to check
///
/// - Returns: `true` if the specified offset is in an empty paragraph, `false` otherwise.
///
func isEmptyParagraphAtEndOfFile(at offset: Int) -> Bool {
return offset == characters.count && isEmptyParagraph(at: offset)
}

/// This methods verifies if the receiver string is an end-of-line character.
///
/// - Returns: `true` if the receiver is an end-of-line character.
Expand Down Expand Up @@ -57,6 +69,16 @@ extension String {
return index == endIndex || substring(with: index ..< self.index(after: index)).isEndOfLine()
}

func isEndOfLine(atUTF16Offset utf16Offset: Int) -> Bool {
let utf16Index = utf16.index(utf16.startIndex, offsetBy: utf16Offset)

guard let index = utf16Index.samePosition(in: self) else {
fatalError("This should not be possible, review your logic.")
}

return isEndOfLine(at: index)
}

/// Checks if the location passed is the beggining of a new line.
///
/// - Parameters:
Expand Down Expand Up @@ -86,4 +108,22 @@ extension String {

return isStartOfNewLine(at: index)
}

/// Checks if the location passed is the beggining of a new line.
///
/// - Parameters:
/// - offset: the receiver's offset to check
///
/// - Returns: true if beggining of a new line false otherwise
///
func isStartOfNewLine(atUTF16Offset utf16Offset: Int) -> Bool {

let utf16Index = utf16.index(utf16.startIndex, offsetBy: utf16Offset)

guard let index = utf16Index.samePosition(in: self) else {
fatalError("This should not be possible, review your logic.")
}

return isStartOfNewLine(at: index)
}
}
57 changes: 57 additions & 0 deletions Aztec/Classes/Formatters/HTMLParagraphFormatter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Foundation
import UIKit


// MARK: - Blockquote Formatter
//
class HTMLParagraphFormatter: ParagraphAttributeFormatter {

/// Attributes to be added by default
///
let placeholderAttributes: [String : Any]?


/// Designated Initializer
///
init(placeholderAttributes: [String : Any]? = nil) {
self.placeholderAttributes = placeholderAttributes
}


// MARK: - Overwriten Methods

func apply(to attributes: [String : Any]) -> [String: Any] {
let newParagraphStyle = ParagraphStyle()

if let paragraphStyle = attributes[NSParagraphStyleAttributeName] as? NSParagraphStyle {
newParagraphStyle.setParagraphStyle(paragraphStyle)
}

newParagraphStyle.htmlParagraph = HTMLParagraph()

var resultingAttributes = attributes
resultingAttributes[NSParagraphStyleAttributeName] = newParagraphStyle
return resultingAttributes
}

func remove(from attributes:[String: Any]) -> [String: Any] {
guard let paragraphStyle = attributes[NSParagraphStyleAttributeName] as? ParagraphStyle,
paragraphStyle.blockquote != nil
else {
return attributes
}

let newParagraphStyle = ParagraphStyle()
newParagraphStyle.setParagraphStyle(paragraphStyle)

var resultingAttributes = attributes
resultingAttributes[NSParagraphStyleAttributeName] = newParagraphStyle
return resultingAttributes
}

func present(in attributes: [String : Any]) -> Bool {
let style = attributes[NSParagraphStyleAttributeName] as? ParagraphStyle
return style?.htmlParagraph != nil
}
}

1 change: 1 addition & 0 deletions Aztec/Classes/GUI/FormatBar/FormattingIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public enum FormattingIdentifier: String {
case header5 = "header5"
case header6 = "header6"
case horizontalruler = "horizontalruler"
case p = "p"
}
Loading