From 4561534101df45f34df38b19914201cc2b99ab71 Mon Sep 17 00:00:00 2001 From: "C. Bess" Date: Sat, 26 Mar 2022 12:01:30 -0500 Subject: [PATCH 1/3] expose indentation operations - make increase/decrease indentation actions visible - cleanup code --- Aztec/Classes/TextKit/TextView.swift | 40 +++++++++++++--------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index 2d83526bb..b742ba9c9 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -555,43 +555,44 @@ open class TextView: UITextView { } @objc func handleShiftTab(command: UIKeyCommand) { - - let lists = TextListFormatter.lists(in: typingAttributes) - let quotes = BlockquoteFormatter.blockquotes(in: typingAttributes) - - if let list = lists.last { - indent(list: list, increase: false) - - } else if let quote = quotes.last { - indent(blockquote: quote, increase: false) - - } else { - return - } + decreaseIndent() } @objc func handleTab(command: UIKeyCommand) { - + increaseIndent() + } + + // MARK: - General Indentation + + /// Increases the indentation of the selected range + open func increaseIndent() { let lists = TextListFormatter.lists(in: typingAttributes) let quotes = BlockquoteFormatter.blockquotes(in: typingAttributes) if let list = lists.last, lists.count < maximumListIndentationLevels { indent(list: list) - } else if let quote = quotes.last, quotes.count < maximumBlockquoteIndentationLevels { indent(blockquote: quote) - } else { insertText(String(.tab)) } - } + /// Decreases the indentation of the selected range + open func decreaseIndent() { + let lists = TextListFormatter.lists(in: typingAttributes) + let quotes = BlockquoteFormatter.blockquotes(in: typingAttributes) + + if let list = lists.last { + indent(list: list, increase: false) + } else if let quote = quotes.last { + indent(blockquote: quote, increase: false) + } + } // MARK: - Text List indent methods private func indent(list: TextList, increase: Bool = true) { - let formatter = TextListFormatter(style: list.style, placeholderAttributes: nil, increaseDepth: true) let li = LiFormatter(placeholderAttributes: nil) @@ -629,9 +630,6 @@ open class TextView: UITextView { // MARK: - Blockquote indent methods private func indent(blockquote: Blockquote, increase: Bool = true) { - - - let formatter = BlockquoteFormatter(placeholderAttributes: typingAttributes, increaseDepth: true) let targetRange = formatter.applicationRange(for: selectedRange, in: storage) From ed55d4a1107355eafc338c8d96bd580d6128b8fd Mon Sep 17 00:00:00 2001 From: "C. Bess" Date: Sat, 26 Mar 2022 12:31:03 -0500 Subject: [PATCH 2/3] cleanup whitespace --- Aztec/Classes/TextKit/TextView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index b742ba9c9..85a53e4c2 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -563,7 +563,7 @@ open class TextView: UITextView { } // MARK: - General Indentation - + /// Increases the indentation of the selected range open func increaseIndent() { let lists = TextListFormatter.lists(in: typingAttributes) @@ -582,14 +582,14 @@ open class TextView: UITextView { open func decreaseIndent() { let lists = TextListFormatter.lists(in: typingAttributes) let quotes = BlockquoteFormatter.blockquotes(in: typingAttributes) - + if let list = lists.last { indent(list: list, increase: false) } else if let quote = quotes.last { indent(blockquote: quote, increase: false) } } - + // MARK: - Text List indent methods private func indent(list: TextList, increase: Bool = true) { From 1ce621c2cd93c5f883244be06704fffe7225e397 Mon Sep 17 00:00:00 2001 From: "C. Bess" Date: Sat, 26 Mar 2022 12:31:51 -0500 Subject: [PATCH 3/3] cleanup whitespace --- Aztec/Classes/TextKit/TextView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index 85a53e4c2..e4e0404bf 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -561,7 +561,7 @@ open class TextView: UITextView { @objc func handleTab(command: UIKeyCommand) { increaseIndent() } - + // MARK: - General Indentation /// Increases the indentation of the selected range