diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd421902..e405184eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [v1.3.20](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.3.20) +### Changed +- Support for `` for italic and using it as default via the formatting toolbar #777 + ## [v1.3.19](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.3.19) ### Fixed - Option to avoid autofocus when getting visible #783 diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/FormattingHistoryTests.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/FormattingHistoryTests.kt index abbdb744c..ea13de73e 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/FormattingHistoryTests.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/FormattingHistoryTests.kt @@ -187,7 +187,7 @@ class FormattingHistoryTests : BaseHistoryTest() { @Test fun testAddItalicAndUnderlineUndoRedo() { val text = "There's no crying in baseball!" - val htmlRegex = Regex("$text|$text") + val htmlRegex = Regex("$text|$text") val editorPage = EditorPage() // Insert text snippet diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt index e67a60095..a277e8fd9 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt @@ -22,7 +22,7 @@ class MixedTextFormattingTests : BaseTest() { val text1 = "so" val text2 = "me " val text3 = "text " - val regex = Regex("$text1$text2<(strong|i)><(strong|i)>$text3") + val regex = Regex("$text1$text2<(strong|em)><(strong|em)>$text3") EditorPage() .toggleBold() diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/SimpleTextFormattingTests.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/SimpleTextFormattingTests.kt index e7fd61ddb..170b35f49 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/SimpleTextFormattingTests.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/SimpleTextFormattingTests.kt @@ -32,7 +32,7 @@ class SimpleTextFormattingTests : BaseTest() { fun testSimpleItalicFormatting() { val text1 = "some" val text2 = "text" - val html = "$text1$text2" + val html = "$text1$text2" EditorPage() .insertText(text1) @@ -335,7 +335,7 @@ class SimpleTextFormattingTests : BaseTest() { @Test fun testInlineStyleAndDelete() { val text1 = "some" - val html = "som" + val html = "som" EditorPage() .toggleItalics() diff --git a/aztec/src/main/java/org/wordpress/aztec/Html.java b/aztec/src/main/java/org/wordpress/aztec/Html.java index a4f3aaa8b..434ad16cf 100644 --- a/aztec/src/main/java/org/wordpress/aztec/Html.java +++ b/aztec/src/main/java/org/wordpress/aztec/Html.java @@ -46,6 +46,7 @@ import org.wordpress.aztec.spans.AztecStyleBoldSpan; import org.wordpress.aztec.spans.AztecStyleCiteSpan; import org.wordpress.aztec.spans.AztecStyleItalicSpan; +import org.wordpress.aztec.spans.AztecStyleEmphasisSpan; import org.wordpress.aztec.spans.AztecStyleStrongSpan; import org.wordpress.aztec.spans.AztecSubscriptSpan; import org.wordpress.aztec.spans.AztecSuperscriptSpan; @@ -318,7 +319,7 @@ private void handleStartTag(String tag, Attributes attributes, int nestingLevel) } else if (tag.equalsIgnoreCase("b")) { start(spannableStringBuilder, AztecTextFormat.FORMAT_BOLD, attributes); } else if (tag.equalsIgnoreCase("em")) { - start(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC, attributes); + start(spannableStringBuilder, AztecTextFormat.FORMAT_EMPHASIS, attributes); } else if (tag.equalsIgnoreCase("cite")) { start(spannableStringBuilder, AztecTextFormat.FORMAT_CITE, attributes); } else if (tag.equalsIgnoreCase("dfn")) { @@ -411,7 +412,7 @@ private void handleEndTag(String tag, int nestingLevel) { } else if (tag.equalsIgnoreCase("b")) { end(spannableStringBuilder, AztecTextFormat.FORMAT_BOLD); } else if (tag.equalsIgnoreCase("em")) { - end(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC); + end(spannableStringBuilder, AztecTextFormat.FORMAT_EMPHASIS); } else if (tag.equalsIgnoreCase("cite")) { end(spannableStringBuilder, AztecTextFormat.FORMAT_CITE); } else if (tag.equalsIgnoreCase("dfn")) { @@ -498,6 +499,9 @@ private static void start(SpannableStringBuilder text, AztecTextFormat textForma case FORMAT_ITALIC: newSpan = new AztecStyleItalicSpan(attributes); break; + case FORMAT_EMPHASIS: + newSpan = new AztecStyleEmphasisSpan(attributes); + break; case FORMAT_CITE: newSpan = new AztecStyleCiteSpan(attributes); break; @@ -550,6 +554,9 @@ private static void end(SpannableStringBuilder text, AztecTextFormat textFormat) case FORMAT_ITALIC: span = (AztecStyleItalicSpan) getLast(text, AztecStyleItalicSpan.class); break; + case FORMAT_EMPHASIS: + span = (AztecStyleEmphasisSpan) getLast(text, AztecStyleEmphasisSpan.class); + break; case FORMAT_CITE: span = (AztecStyleCiteSpan) getLast(text, AztecStyleCiteSpan.class); break; diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index c5f3a208b..6bcb26ba0 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -925,6 +925,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown AztecTextFormat.FORMAT_HEADING_6, AztecTextFormat.FORMAT_PREFORMAT -> blockFormatter.toggleHeading(textFormat) AztecTextFormat.FORMAT_ITALIC, + AztecTextFormat.FORMAT_EMPHASIS, AztecTextFormat.FORMAT_CITE, AztecTextFormat.FORMAT_UNDERLINE, AztecTextFormat.FORMAT_STRIKETHROUGH, @@ -957,6 +958,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown AztecTextFormat.FORMAT_BOLD, AztecTextFormat.FORMAT_STRONG, AztecTextFormat.FORMAT_ITALIC, + AztecTextFormat.FORMAT_EMPHASIS, AztecTextFormat.FORMAT_CITE, AztecTextFormat.FORMAT_UNDERLINE, AztecTextFormat.FORMAT_STRIKETHROUGH, @@ -1361,6 +1363,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_BOLD, start, end) inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_STRONG, start, end) inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_ITALIC, start, end) + inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_EMPHASIS, start, end) inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_CITE, start, end) inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_STRIKETHROUGH, start, end) inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_UNDERLINE, start, end) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecTextFormat.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecTextFormat.kt index ce58a2aa1..2f0bb4bae 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecTextFormat.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecTextFormat.kt @@ -16,6 +16,7 @@ enum class AztecTextFormat : ITextFormat { FORMAT_BOLD, FORMAT_STRONG, FORMAT_ITALIC, + FORMAT_EMPHASIS, FORMAT_CITE, FORMAT_UNDERLINE, FORMAT_STRIKETHROUGH, diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt index 77c706db1..0f4f86f4c 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt @@ -16,6 +16,7 @@ import org.wordpress.aztec.spans.AztecStrikethroughSpan import org.wordpress.aztec.spans.AztecStyleBoldSpan import org.wordpress.aztec.spans.AztecStyleCiteSpan import org.wordpress.aztec.spans.AztecStyleItalicSpan +import org.wordpress.aztec.spans.AztecStyleEmphasisSpan import org.wordpress.aztec.spans.AztecStyleStrongSpan import org.wordpress.aztec.spans.AztecStyleSpan import org.wordpress.aztec.spans.AztecUnderlineSpan @@ -65,6 +66,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat AztecTextFormat.FORMAT_BOLD, AztecTextFormat.FORMAT_STRONG, AztecTextFormat.FORMAT_ITALIC, + AztecTextFormat.FORMAT_EMPHASIS, AztecTextFormat.FORMAT_CITE, AztecTextFormat.FORMAT_STRIKETHROUGH, AztecTextFormat.FORMAT_UNDERLINE, @@ -198,6 +200,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat AztecStyleBoldSpan::class.java -> return AztecTextFormat.FORMAT_BOLD AztecStyleStrongSpan::class.java -> return AztecTextFormat.FORMAT_STRONG AztecStyleItalicSpan::class.java -> return AztecTextFormat.FORMAT_ITALIC + AztecStyleEmphasisSpan::class.java -> return AztecTextFormat.FORMAT_EMPHASIS AztecStyleCiteSpan::class.java -> return AztecTextFormat.FORMAT_CITE AztecStrikethroughSpan::class.java -> return AztecTextFormat.FORMAT_STRIKETHROUGH AztecUnderlineSpan::class.java -> return AztecTextFormat.FORMAT_UNDERLINE @@ -341,6 +344,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat AztecTextFormat.FORMAT_BOLD -> return AztecStyleBoldSpan() AztecTextFormat.FORMAT_STRONG -> return AztecStyleStrongSpan() AztecTextFormat.FORMAT_ITALIC -> return AztecStyleItalicSpan() + AztecTextFormat.FORMAT_EMPHASIS -> return AztecStyleEmphasisSpan() AztecTextFormat.FORMAT_CITE -> return AztecStyleCiteSpan() AztecTextFormat.FORMAT_STRIKETHROUGH -> return AztecStrikethroughSpan() AztecTextFormat.FORMAT_UNDERLINE -> return AztecUnderlineSpan() diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecStyleEmphasisSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecStyleEmphasisSpan.kt new file mode 100644 index 000000000..ac210a8d0 --- /dev/null +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecStyleEmphasisSpan.kt @@ -0,0 +1,18 @@ +package org.wordpress.aztec.spans + +import android.graphics.Typeface +import org.wordpress.aztec.AztecAttributes + +class AztecStyleEmphasisSpan(attributes: AztecAttributes = AztecAttributes()) + : AztecStyleSpan(Typeface.ITALIC, attributes) { + + override val TAG by lazy { + when (style) { + Typeface.ITALIC -> { + return@lazy "em" + } + } + throw IllegalArgumentException() + } +} + diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt b/aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt index 0aaf93aad..d9014c309 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt @@ -182,7 +182,7 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener { } KeyEvent.KEYCODE_I -> { if (event.isCtrlPressed) { // Italic = Ctrl + I - aztecToolbarListener?.onToolbarFormatButtonClicked(AztecTextFormat.FORMAT_ITALIC, true) + aztecToolbarListener?.onToolbarFormatButtonClicked(AztecTextFormat.FORMAT_EMPHASIS, true) findViewById(ToolbarAction.ITALIC.buttonId).performClick() return true } diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/toolbar/ToolbarAction.kt b/aztec/src/main/kotlin/org/wordpress/aztec/toolbar/ToolbarAction.kt index efaf18a29..db77d457a 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/toolbar/ToolbarAction.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/toolbar/ToolbarAction.kt @@ -34,7 +34,7 @@ enum class ToolbarAction constructor(override val buttonId: Int, override val ac ITALIC( R.id.format_bar_button_italic, ToolbarActionType.INLINE_STYLE, - setOf(AztecTextFormat.FORMAT_ITALIC)), + setOf(AztecTextFormat.FORMAT_EMPHASIS, AztecTextFormat.FORMAT_ITALIC)), STRIKETHROUGH( R.id.format_bar_button_strikethrough, ToolbarActionType.INLINE_STYLE, diff --git a/aztec/src/test/kotlin/org/wordpress/aztec/AztecToolbarTest.kt b/aztec/src/test/kotlin/org/wordpress/aztec/AztecToolbarTest.kt index 0d0a3f8bd..3a7859413 100644 --- a/aztec/src/test/kotlin/org/wordpress/aztec/AztecToolbarTest.kt +++ b/aztec/src/test/kotlin/org/wordpress/aztec/AztecToolbarTest.kt @@ -136,7 +136,7 @@ class AztecToolbarTest { Assert.assertTrue(italicButton.isChecked) editText.append("italic") - Assert.assertEquals("italic", editText.toHtml()) + Assert.assertEquals("italic", editText.toHtml()) italicButton.performClick() Assert.assertFalse(italicButton.isChecked) } @@ -155,7 +155,7 @@ class AztecToolbarTest { editText.setSelection(0, editText.length()) italicButton.performClick() Assert.assertTrue(italicButton.isChecked) - Assert.assertEquals("italic", editText.toHtml()) + Assert.assertEquals("italic", editText.toHtml()) italicButton.performClick() Assert.assertFalse(italicButton.isChecked) @@ -268,21 +268,21 @@ class AztecToolbarTest { editText.append("Ita") italicButton.performClick() editText.append("lic") - Assert.assertEquals("BoldItalic", editText.toHtml()) + Assert.assertEquals("BoldItalic", editText.toHtml()) // Strike strikeThroughButton.performClick() editText.append("Str") strikeThroughButton.performClick() editText.append("ike") - Assert.assertEquals("BoldItalicStrike", editText.toHtml()) + Assert.assertEquals("BoldItalicStrike", editText.toHtml()) // Underline underlineButton.performClick() editText.append("Under") underlineButton.performClick() editText.append("line") - Assert.assertEquals("BoldItalicStrikeUnderline", editText.toHtml()) + Assert.assertEquals("BoldItalicStrikeUnderline", editText.toHtml()) // Clear text editText.setText("") @@ -299,21 +299,21 @@ class AztecToolbarTest { italicButton.performClick() editText.append("lic") italicButton.performClick() - Assert.assertEquals("BoldItalic", editText.toHtml()) + Assert.assertEquals("BoldItalic", editText.toHtml()) // Strike editText.append("Str") strikeThroughButton.performClick() editText.append("ike") strikeThroughButton.performClick() - Assert.assertEquals("BoldItalicStrike", editText.toHtml()) + Assert.assertEquals("BoldItalicStrike", editText.toHtml()) // Underline editText.append("Under") underlineButton.performClick() editText.append("line") underlineButton.performClick() - Assert.assertEquals("BoldItalicStrikeUnderline", editText.toHtml()) + Assert.assertEquals("BoldItalicStrikeUnderline", editText.toHtml()) } /** @@ -342,7 +342,7 @@ class AztecToolbarTest { editText.append("Ita") italicButton.performClick() editText.append("lic") - Assert.assertEquals(" Bold Italic", editText.toHtml()) + Assert.assertEquals(" Bold Italic", editText.toHtml()) // Space editText.append(" ") @@ -352,7 +352,7 @@ class AztecToolbarTest { editText.append("Str") strikeThroughButton.performClick() editText.append("ike") - Assert.assertEquals(" Bold Italic Strike", editText.toHtml()) + Assert.assertEquals(" Bold Italic Strike", editText.toHtml()) // Space editText.append(" ") @@ -362,7 +362,7 @@ class AztecToolbarTest { editText.append("Under") underlineButton.performClick() editText.append("line") - Assert.assertEquals(" Bold Italic Strike Underline", editText.toHtml()) + Assert.assertEquals(" Bold Italic Strike Underline", editText.toHtml()) } /** @@ -392,7 +392,7 @@ class AztecToolbarTest { italicButton.performClick() Assert.assertTrue(italicButton.isChecked) - Assert.assertEquals("bold bolditalic italic strike underline normal", editText.toHtml()) + Assert.assertEquals("bold bolditalic italic strike underline normal", editText.toHtml()) editText.setSelection(16, 22) @@ -407,14 +407,14 @@ class AztecToolbarTest { strikeThroughButton.performClick() Assert.assertTrue(strikeThroughButton.isChecked) - Assert.assertEquals("bold bolditalic italic strike underline normal", editText.toHtml()) + Assert.assertEquals("bold bolditalic italic strike underline normal", editText.toHtml()) editText.setSelection(30, 39) underlineButton.performClick() Assert.assertTrue(underlineButton.isChecked) - Assert.assertEquals("bold bolditalic italic strike underline normal", editText.toHtml()) + Assert.assertEquals("bold bolditalic italic strike underline normal", editText.toHtml()) } /** @@ -435,31 +435,31 @@ class AztecToolbarTest { italicButton.performClick() Assert.assertTrue(boldButton.isChecked) editText.append("bolditalic") - Assert.assertEquals("boldbolditalic", editText.toHtml()) + Assert.assertEquals("boldbolditalic", editText.toHtml()) boldButton.performClick() Assert.assertFalse(boldButton.isChecked) editText.append("italic") - Assert.assertEquals("boldbolditalicitalic", editText.toHtml()) + Assert.assertEquals("boldbolditalicitalic", editText.toHtml()) italicButton.performClick() Assert.assertFalse(italicButton.isChecked) strikeThroughButton.performClick() Assert.assertTrue(strikeThroughButton.isChecked) editText.append("strike") - Assert.assertEquals("boldbolditalicitalicstrike", editText.toHtml()) + Assert.assertEquals("boldbolditalicitalicstrike", editText.toHtml()) strikeThroughButton.performClick() Assert.assertFalse(strikeThroughButton.isChecked) underlineButton.performClick() Assert.assertTrue(underlineButton.isChecked) editText.append("underline") - Assert.assertEquals("boldbolditalicitalicstrikeunderline", editText.toHtml()) + Assert.assertEquals("boldbolditalicitalicstrikeunderline", editText.toHtml()) underlineButton.performClick() Assert.assertFalse(underlineButton.isChecked) editText.append("normal") - Assert.assertEquals("boldbolditalicitalicstrikeunderlinenormal", editText.toHtml()) + Assert.assertEquals("boldbolditalicitalicstrikeunderlinenormal", editText.toHtml()) } /** @@ -606,12 +606,12 @@ class AztecToolbarTest { @Test @Throws(Exception::class) fun extendStyleFromWholeSelection() { - editText.fromHtml("bolditalic") + editText.fromHtml("bolditalic") editText.setSelection(0, editText.length()) italicButton.performClick() - Assert.assertEquals("bolditalic", editText.toHtml()) + Assert.assertEquals("bolditalic", editText.toHtml()) } /** @@ -630,7 +630,7 @@ class AztecToolbarTest { Assert.assertEquals("bolditalic", editText.toHtml()) italicButton.performClick() - Assert.assertEquals("bolditalic", editText.toHtml()) + Assert.assertEquals("bolditalic", editText.toHtml()) italicButton.performClick() Assert.assertEquals("bolditalic", editText.toHtml()) @@ -679,13 +679,13 @@ class AztecToolbarTest { editText.setSelection(4, 8) italicButton.performClick() - Assert.assertEquals("
Div
Span
Hidden
", + Assert.assertEquals("
Div
Span
Hidden
", editText.toHtml()) editText.setSelection(9, 15) strikeThroughButton.performClick() - Assert.assertEquals("
Div
Span
Hidden
", + Assert.assertEquals("
Div
Span
Hidden
", editText.toHtml()) }