Skip to content

Commit

Permalink
Merge pull request wikimedia#4692 from wikimedia/native-editor-closin…
Browse files Browse the repository at this point in the history
…g-bolditalic-fix

Bug fix - Native Editor last character bold/italic state
  • Loading branch information
mazevedofs authored Jan 5, 2024
2 parents 6915b09 + 6ec4f0c commit a08b4c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ - (BOOL)attributedString:(NSMutableAttributedString *)attributedString isBoldInR

if (attrs[WKSourceEditorCustomKeyFontBoldItalics] != nil || attrs[WKSourceEditorCustomKeyFontBold] != nil) {
isBold = YES;
} else {
// Edge case, check previous character if we are up against a closing bold or italic
if (attrs[WKSourceEditorCustomKeyColorOrange]) {
attrs = [attributedString attributesAtIndex:range.location - 1 effectiveRange:nil];
if (attrs[WKSourceEditorCustomKeyFontBoldItalics] != nil || attrs[WKSourceEditorCustomKeyFontBold] != nil) {
isBold = YES;
}
}
}
}

Expand All @@ -312,6 +320,14 @@ - (BOOL)attributedString:(NSMutableAttributedString *)attributedString isItalics

if (attrs[WKSourceEditorCustomKeyFontBoldItalics] != nil || attrs[WKSourceEditorCustomKeyFontItalics] != nil) {
isItalics = YES;
} else {
// Edge case, check previous character if we are up against a closing bold or italic
if (attrs[WKSourceEditorCustomKeyColorOrange]) {
attrs = [attributedString attributesAtIndex:range.location - 1 effectiveRange:nil];
if (attrs[WKSourceEditorCustomKeyFontBoldItalics] != nil || attrs[WKSourceEditorCustomKeyFontItalics] != nil) {
isItalics = YES;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ final class WKSourceEditorTextFrameworkMediatorTests: XCTestCase {
XCTAssertFalse(selectionStates9.isItalics)
}

func testClosingBoldSelectionStateCursor() throws {
let text = "One '''Two''' Three"
mediator.textView.attributedText = NSAttributedString(string: text)

let selectionStates = mediator.selectionState(selectedDocumentRange: NSRange(location: 10, length: 0))
XCTAssertTrue(selectionStates.isBold)
}

func testClosingItalicsSelectionStateCursor() throws {
let text = "One ''Two'' Three"
mediator.textView.attributedText = NSAttributedString(string: text)

let selectionStates = mediator.selectionState(selectedDocumentRange: NSRange(location: 9, length: 0))
XCTAssertTrue(selectionStates.isItalics)
}

func testHorizontalTemplateButtonSelectionStateCursor() throws {
let text = "Testing simple {{Currentdate}} template example."
mediator.textView.attributedText = NSAttributedString(string: text)
Expand Down

0 comments on commit a08b4c4

Please sign in to comment.