Skip to content

Commit 61c04b7

Browse files
author
Gerardo
committed
Merge branch 'develop' into feature/mark-formatting-improvements
2 parents af4c463 + 006acea commit 61c04b7

14 files changed

Lines changed: 197 additions & 149 deletions

.buildkite/pipeline.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Nodes with values to reuse in the pipeline.
22
common_params:
33
plugins: &common_plugins
4-
- &bash_cache automattic/bash-cache#2.0.0: ~
4+
- automattic/a8c-ci-toolkit#2.13.0
55
# Common environment values to use with the `env` key.
66
env: &common_env
77
IMAGE_ID: xcode-13
@@ -14,9 +14,6 @@ steps:
1414
- label: "🧪 Build and Test"
1515
key: "test"
1616
command: |
17-
# See https://github.com/Automattic/bash-cache-buildkite-plugin/issues/16
18-
gem install bundler:2.3.4
19-
2017
build_and_test_pod
2118
env: *common_env
2219
plugins: *common_plugins
@@ -27,9 +24,6 @@ steps:
2724
- label: "🔬 Validate Podspecs"
2825
key: "validate"
2926
command: |
30-
# See https://github.com/Automattic/bash-cache-buildkite-plugin/issues/16
31-
gem install bundler:2.3.4
32-
3327
validate_podspec
3428
env: *common_env
3529
plugins: *common_plugins
@@ -40,9 +34,6 @@ steps:
4034
- label: "🧹 Lint"
4135
key: "lint"
4236
command: |
43-
# See https://github.com/Automattic/bash-cache-buildkite-plugin/issues/16
44-
gem install bundler:2.3.4
45-
4637
lint_pod
4738
env: *common_env
4839
plugins: *common_plugins

.buildkite/publish-aztec-pod.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ SPECS_REPO="git@github.com:wordpress-mobile/cocoapods-specs.git"
55
SLACK_WEBHOOK=$PODS_SLACK_WEBHOOK
66

77
echo "--- :rubygems: Setting up Gems"
8-
# See https://github.com/Automattic/bash-cache-buildkite-plugin/issues/16
9-
gem install bundler:2.3.4
10-
118
install_gems
129

1310
echo "--- :cocoapods: Publishing Pod to CocoaPods CDN"

.buildkite/publish-editor.pod.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ SPECS_REPO="git@github.com:wordpress-mobile/cocoapods-specs.git"
55
SLACK_WEBHOOK=$PODS_SLACK_WEBHOOK
66

77
echo "--- :rubygems: Setting up Gems"
8-
# See https://github.com/Automattic/bash-cache-buildkite-plugin/issues/16
9-
gem install bundler:2.3.4
10-
118
install_gems
129

1310
echo "--- :cocoapods: Publishing Pod to CocoaPods CDN"

.circleci/config.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ Fixes #
22

33
To test:
44

5+
---
6+
7+
- [ ] I have considered if this change warrants release notes and have added them to the appropriate section in the `CHANGELOG.md` if necessary.

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.6.4
1+
2.7.4

Aztec/Classes/Extensions/NSAttributedString+ParagraphRange.swift

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ extension NSAttributedString {
2222
///
2323
func paragraphRanges(intersecting range: NSRange, includeParagraphSeparator: Bool = true) -> [NSRange] {
2424
var paragraphRanges = [NSRange]()
25-
let swiftRange = string.range(fromUTF16NSRange: range)
26-
let paragraphsRange = string.paragraphRange(for: swiftRange)
27-
28-
string.enumerateSubstrings(in: paragraphsRange, options: .byParagraphs) { [unowned self] (substring, substringRange, enclosingRange, stop) in
25+
let paragraphsRange = foundationString.paragraphRange(for: range)
26+
27+
foundationString.enumerateSubstrings(in: paragraphsRange, options: .byParagraphs) { (substring, substringRange, enclosingRange, stop) in
2928
let paragraphRange = includeParagraphSeparator ? enclosingRange : substringRange
30-
paragraphRanges.append(self.string.utf16NSRange(from: paragraphRange))
29+
paragraphRanges.append(paragraphRange)
3130
}
32-
31+
3332
return paragraphRanges
3433
}
3534

@@ -44,16 +43,12 @@ extension NSAttributedString {
4443
///
4544
func paragraphRanges(intersecting range: NSRange) -> ([ParagraphRange]) {
4645
var paragraphRanges = [ParagraphRange]()
47-
let swiftRange = string.range(fromUTF16NSRange: range)
48-
let paragraphsRange = string.paragraphRange(for: swiftRange)
49-
50-
string.enumerateSubstrings(in: paragraphsRange, options: .byParagraphs) { [unowned self] (substring, substringRange, enclosingRange, stop) in
51-
let substringNSRange = self.string.utf16NSRange(from: substringRange)
52-
let enclosingNSRange = self.string.utf16NSRange(from: enclosingRange)
53-
54-
paragraphRanges.append((substringNSRange, enclosingNSRange))
46+
let paragraphsRange = foundationString.paragraphRange(for: range)
47+
48+
foundationString.enumerateSubstrings(in: paragraphsRange, options: .byParagraphs) { (substring, substringRange, enclosingRange, stop) in
49+
paragraphRanges.append((substringRange, enclosingRange))
5550
}
56-
51+
5752
return paragraphRanges
5853
}
5954

@@ -62,10 +57,7 @@ extension NSAttributedString {
6257
/// This is an attributed string wrapper for `NSString.paragraphRangeForRange()`
6358
///
6459
func paragraphRange(for range: NSRange) -> NSRange {
65-
let swiftRange = string.range(fromUTF16NSRange: range)
66-
let outRange = string.paragraphRange(for: swiftRange)
67-
68-
return string.utf16NSRange(from: outRange)
60+
return foundationString.paragraphRange(for: range)
6961
}
7062

7163
func paragraphRange(for attachment: NSTextAttachment) -> NSRange {

Aztec/Classes/TextKit/TextView.swift

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -555,43 +555,44 @@ open class TextView: UITextView {
555555
}
556556

557557
@objc func handleShiftTab(command: UIKeyCommand) {
558-
559-
let lists = TextListFormatter.lists(in: typingAttributes)
560-
let quotes = BlockquoteFormatter.blockquotes(in: typingAttributes)
561-
562-
if let list = lists.last {
563-
indent(list: list, increase: false)
564-
565-
} else if let quote = quotes.last {
566-
indent(blockquote: quote, increase: false)
567-
568-
} else {
569-
return
570-
}
558+
decreaseIndent()
571559
}
572560

573561
@objc func handleTab(command: UIKeyCommand) {
574-
562+
increaseIndent()
563+
}
564+
565+
// MARK: - General Indentation
566+
567+
/// Increases the indentation of the selected range
568+
open func increaseIndent() {
575569
let lists = TextListFormatter.lists(in: typingAttributes)
576570
let quotes = BlockquoteFormatter.blockquotes(in: typingAttributes)
577571

578572
if let list = lists.last, lists.count < maximumListIndentationLevels {
579573
indent(list: list)
580-
581574
} else if let quote = quotes.last, quotes.count < maximumBlockquoteIndentationLevels {
582575
indent(blockquote: quote)
583-
584576
} else {
585577
insertText(String(.tab))
586578
}
587-
588579
}
589580

590-
581+
/// Decreases the indentation of the selected range
582+
open func decreaseIndent() {
583+
let lists = TextListFormatter.lists(in: typingAttributes)
584+
let quotes = BlockquoteFormatter.blockquotes(in: typingAttributes)
585+
586+
if let list = lists.last {
587+
indent(list: list, increase: false)
588+
} else if let quote = quotes.last {
589+
indent(blockquote: quote, increase: false)
590+
}
591+
}
592+
591593
// MARK: - Text List indent methods
592594

593595
private func indent(list: TextList, increase: Bool = true) {
594-
595596
let formatter = TextListFormatter(style: list.style, placeholderAttributes: nil, increaseDepth: true)
596597
let li = LiFormatter(placeholderAttributes: nil)
597598

@@ -629,9 +630,6 @@ open class TextView: UITextView {
629630
// MARK: - Blockquote indent methods
630631

631632
private func indent(blockquote: Blockquote, increase: Bool = true) {
632-
633-
634-
635633
let formatter = BlockquoteFormatter(placeholderAttributes: typingAttributes, increaseDepth: true)
636634
let targetRange = formatter.applicationRange(for: selectedRange, in: storage)
637635

AztecTests/Extensions/NSAttributedStringParagraphRangeTests.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,54 @@ class NSAttributedStringParagraphRangeTests: XCTestCase {
4646
XCTAssertEqual(ranges.first?.rangeExcludingParagraphSeparator, expectedRangeWithoutSeparator)
4747
XCTAssertEqual(ranges.first?.rangeIncludingParagraphSeparator, expectedRangeWithSeparator)
4848
}
49+
50+
/// Tests that `paragraphRange(for:)` with a paragraph separator character
51+
/// returns the correct `NSRange`.
52+
///
53+
/// This test was added due to an iOS 17 crash when calling String.paragraphRange(for: range)
54+
/// on a single paragraph separator character.
55+
///
56+
func testParagraphRangeWorkWithParagraphSeparator() {
57+
let attributedString = NSAttributedString(string: "\u{2029}")
58+
let range = NSRange(location: 0, length: 1)
59+
let expectedRange = NSRange(location: 0, length: 1)
60+
61+
let paragraphRange = attributedString.paragraphRange(for: range)
62+
63+
XCTAssertEqual(paragraphRange, expectedRange)
64+
}
65+
66+
/// Tests that `paragraphRanges(intersecting:)` with a paragraph separator character
67+
/// returns the correct `[NSRange]`.
68+
///
69+
/// This test was added due to an iOS 17 crash when calling String.paragraphRange(for: range)
70+
/// on a single paragraph separator character.
71+
///
72+
func testParagraphRangesWorkWithParagraphSeparator() {
73+
let attributedString = NSAttributedString(string: "\u{2029}")
74+
let range = NSRange(location: 0, length: 1)
75+
let expectedRange = NSRange(location: 0, length: 1)
76+
77+
let ranges = attributedString.paragraphRanges(intersecting: range, includeParagraphSeparator: true)
78+
79+
XCTAssertEqual(ranges.first!, expectedRange)
80+
}
81+
82+
/// Tests that `paragraphRanges(intersecting:)` with a paragraph separator character
83+
/// returns the correct `ParagraphRange`.
84+
///
85+
/// This test was added due to an iOS 17 crash when calling String.paragraphRange(for: range)
86+
/// on a single paragraph separator character.
87+
///
88+
func testParagraphRangesWorkWithAndWithoutParagraphSeparator() {
89+
let attributedString = NSAttributedString(string: "\u{2029}")
90+
let range = NSRange(location: 0, length: 1)
91+
let expectedRangeWithoutSeparator = NSRange(location: 0, length: 0)
92+
let expectedRangeWithSeparator = NSRange(location: 0, length: 1)
93+
94+
let ranges = attributedString.paragraphRanges(intersecting: range)
95+
96+
XCTAssertEqual(ranges.first!.rangeIncludingParagraphSeparator, expectedRangeWithSeparator)
97+
XCTAssertEqual(ranges.first!.rangeExcludingParagraphSeparator, expectedRangeWithoutSeparator)
98+
}
4999
}

CHANGELOG.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,77 @@
1+
# Changelog
2+
3+
The format of this document is inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and the project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4+
5+
<!-- This is a comment, you won't see it when GitHub renders the Markdown file.
6+
7+
When releasing a new version:
8+
9+
1. Remove any empty section (those with `_None._`)
10+
2. Update the `## Unreleased` header to `## [<version_number>](https://github.com/wordpress-mobile/AztecEditor-iOS/releases/tag/<version_number>)`
11+
3. Add a new "Unreleased" section for the next iteration, by copy/pasting the following template:
12+
13+
## Unreleased
14+
15+
### Breaking Changes
16+
17+
_None._
18+
19+
### New Features
20+
21+
_None._
22+
23+
### Bug Fixes
24+
25+
_None._
26+
27+
### Internal Changes
28+
29+
_None._
30+
31+
-->
32+
33+
## Unreleased
34+
35+
### Breaking Changes
36+
37+
_None._
38+
39+
### New Features
40+
41+
_None._
42+
43+
### Bug Fixes
44+
45+
_None._
46+
47+
### Internal Changes
48+
49+
_None._
50+
51+
52+
## [1.19.9](https://github.com/wordpress-mobile/AztecEditor-iOS/releases/tag/1.19.9)
53+
54+
### Breaking Changes
55+
56+
_None._
57+
58+
### New Features
59+
60+
_None._
61+
62+
### Bug Fixes
63+
64+
* Worked around a crash that could occur when calling String.paragraphRange(for:) on iOS 17. [#1373]
65+
66+
### Internal Changes
67+
68+
- Add this changelog file. [#1365]
69+
70+
---
71+
72+
_Versions below this precede the Keep a Changelog-inspired formatting._
73+
74+
175
1.19.8
276
-------
377
* Fix Li tag when switching the list style.

0 commit comments

Comments
 (0)