forked from wikimedia/wikipedia-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wikimedia#4700 from wikimedia/native-editor-paragr…
…aph-header-actions Native Editor - Add heading support
- Loading branch information
Showing
18 changed files
with
1,045 additions
and
130 deletions.
There are no files selected for viewing
This file contains 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 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
54 changes: 54 additions & 0 deletions
54
...ors/Source Editor/Formatter Extensions/WKSourceEditorFormatterHeading+ButtonActions.swift
This file contains 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Foundation | ||
import ComponentsObjC | ||
|
||
extension WKSourceEditorFormatterHeading { | ||
func toggleHeadingFormatting(selectedHeading: WKEditorInputView.HeadingButtonType, currentSelectionState: WKSourceEditorSelectionState, textView: UITextView) { | ||
|
||
var currentStateIsParagraph = false | ||
if currentSelectionState.isHeading { | ||
expandSelectedRangeUpToNearestFormattingStrings(startingFormattingString: "==", endingFormattingString: "==", in: textView) | ||
removeSurroundingFormattingStringsFromSelectedRange(startingFormattingString: "==", endingFormattingString: "==", in: textView) | ||
} else if currentSelectionState.isSubheading1 { | ||
expandSelectedRangeUpToNearestFormattingStrings(startingFormattingString: "===", endingFormattingString: "===", in: textView) | ||
removeSurroundingFormattingStringsFromSelectedRange(startingFormattingString: "===", endingFormattingString: "===", in: textView) | ||
} else if currentSelectionState.isSubheading2 { | ||
expandSelectedRangeUpToNearestFormattingStrings(startingFormattingString: "====", endingFormattingString: "====", in: textView) | ||
removeSurroundingFormattingStringsFromSelectedRange(startingFormattingString: "====", endingFormattingString: "====", in: textView) | ||
} else if currentSelectionState.isSubheading3 { | ||
expandSelectedRangeUpToNearestFormattingStrings(startingFormattingString: "=====", endingFormattingString: "=====", in: textView) | ||
removeSurroundingFormattingStringsFromSelectedRange(startingFormattingString: "=====", endingFormattingString: "=====", in: textView) | ||
} else if currentSelectionState.isSubheading4 { | ||
expandSelectedRangeUpToNearestFormattingStrings(startingFormattingString: "======", endingFormattingString: "======", in: textView) | ||
removeSurroundingFormattingStringsFromSelectedRange(startingFormattingString: "======", endingFormattingString: "======", in: textView) | ||
} else { | ||
currentStateIsParagraph = true | ||
} | ||
|
||
let currentlySurroundedByLineBreaks = selectedRangeIsSurroundedByFormattingString(formattingString: "\n", in: textView) || textView.selectedRange.location == 0 && rangeIsFollowedByFormattingString(range: textView.selectedTextRange, formattingString: "\n", in: textView) | ||
|
||
let surroundingLineBreak = currentStateIsParagraph && !currentlySurroundedByLineBreaks ? "\n" : "" | ||
let startingFormattingString: String | ||
let endingFormattingString: String | ||
switch selectedHeading { | ||
case .paragraph: | ||
return | ||
case .heading: | ||
startingFormattingString = surroundingLineBreak + "==" | ||
endingFormattingString = "==" + surroundingLineBreak | ||
case .subheading1: | ||
startingFormattingString = surroundingLineBreak + "===" | ||
endingFormattingString = "===" + surroundingLineBreak | ||
case .subheading2: | ||
startingFormattingString = surroundingLineBreak + "====" | ||
endingFormattingString = "====" + surroundingLineBreak | ||
case .subheading3: | ||
startingFormattingString = surroundingLineBreak + "=====" | ||
endingFormattingString = "=====" + surroundingLineBreak | ||
case .subheading4: | ||
startingFormattingString = surroundingLineBreak + "======" | ||
endingFormattingString = "======" + surroundingLineBreak | ||
} | ||
|
||
addStringFormattingCharacters(startingFormattingString: startingFormattingString, endingFormattingString: endingFormattingString, in: textView) | ||
} | ||
} |
This file contains 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 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.