Skip to content

Commit f844bfd

Browse files
authored
Merge pull request #958 from wordpress-mobile/feature/add-code-toolbar-action
Add support for code inline tag and for preformat block
2 parents a675243 + df511d0 commit f844bfd

15 files changed

+180
-12
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11391139
AztecTextFormat.FORMAT_HEADING_3,
11401140
AztecTextFormat.FORMAT_HEADING_4,
11411141
AztecTextFormat.FORMAT_HEADING_5,
1142-
AztecTextFormat.FORMAT_HEADING_6,
1143-
AztecTextFormat.FORMAT_PREFORMAT -> blockFormatter.toggleHeading(textFormat)
1142+
AztecTextFormat.FORMAT_HEADING_6 -> blockFormatter.toggleHeading(textFormat)
11441143
AztecTextFormat.FORMAT_ITALIC,
11451144
AztecTextFormat.FORMAT_EMPHASIS,
11461145
AztecTextFormat.FORMAT_CITE,
@@ -1154,6 +1153,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11541153
AztecTextFormat.FORMAT_ALIGN_LEFT,
11551154
AztecTextFormat.FORMAT_ALIGN_CENTER,
11561155
AztecTextFormat.FORMAT_ALIGN_RIGHT -> return blockFormatter.toggleTextAlignment(textFormat)
1156+
AztecTextFormat.FORMAT_PREFORMAT -> blockFormatter.togglePreformat()
11571157
AztecTextFormat.FORMAT_QUOTE -> blockFormatter.toggleQuote()
11581158
AztecTextFormat.FORMAT_HORIZONTAL_RULE -> lineBlockFormatter.applyHorizontalRule()
11591159
else -> {

aztec/src/main/kotlin/org/wordpress/aztec/formatting/BlockFormatter.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ class BlockFormatter(editor: AztecText,
9191
}
9292
}
9393

94+
fun togglePreformat() {
95+
if (!containsPreformat()) {
96+
if (containsOtherHeadings(AztecTextFormat.FORMAT_PREFORMAT)) {
97+
switchHeadingToPreformat()
98+
} else {
99+
applyBlockStyle(AztecTextFormat.FORMAT_PREFORMAT)
100+
}
101+
} else {
102+
removeEntireBlock(AztecPreformatSpan::class.java)
103+
}
104+
}
105+
94106
fun toggleHeading(textFormat: ITextFormat) {
95107
when (textFormat) {
96108
AztecTextFormat.FORMAT_HEADING_1,
@@ -118,15 +130,6 @@ class BlockFormatter(editor: AztecText,
118130

119131
removeBlockStyle(AztecTextFormat.FORMAT_PREFORMAT)
120132
}
121-
AztecTextFormat.FORMAT_PREFORMAT -> {
122-
if (!containsPreformat()) {
123-
if (containsOtherHeadings(AztecTextFormat.FORMAT_PREFORMAT)) {
124-
switchHeadingToPreformat()
125-
} else {
126-
applyBlockStyle(textFormat)
127-
}
128-
}
129-
}
130133
else -> {
131134
}
132135
}

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/ToolbarAction.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ enum class ToolbarAction constructor(
9090
ToolbarActionType.OTHER,
9191
setOf(AztecTextFormat.FORMAT_LINK),
9292
R.layout.format_bar_button_link),
93+
CODE(
94+
R.id.format_bar_button_code,
95+
R.drawable.format_bar_button_code_selector,
96+
ToolbarActionType.INLINE_STYLE,
97+
setOf(AztecTextFormat.FORMAT_CODE),
98+
R.layout.format_bar_button_code),
99+
PREFORMAT(
100+
R.id.format_bar_button_pre,
101+
R.drawable.format_bar_button_pre_selector,
102+
ToolbarActionType.BLOCK_STYLE,
103+
setOf(AztecTextFormat.FORMAT_PREFORMAT),
104+
R.layout.format_bar_button_pre),
93105
HORIZONTAL_RULE(
94106
R.id.format_bar_button_horizontal_rule,
95107
R.drawable.format_bar_button_horizontal_rule_selector,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:width="24dp"
5+
android:height="24dp"
6+
android:viewportWidth="24"
7+
android:viewportHeight="24">
8+
<group
9+
android:pivotX="12"
10+
android:pivotY="12"
11+
android:scaleX="0.7"
12+
android:scaleY="0.7">
13+
<path
14+
android:fillColor="?attr/toolbarIconNormalColor"
15+
android:pathData="M20.8 10.7l-4.3-4.3-1.1 1.1 4.3 4.3c0.1 0.1 0.1 0.3 0 0.4l-4.3 4.3 1.1 1.1 4.3-4.3c0.7-0.8 0.7-1.9 0-2.6zM4.2 11.8l4.3-4.3-1-1-4.3 4.3c-0.7 0.7-0.7 1.8 0 2.5l4.3 4.3 1.1-1.1-4.3-4.3c-0.2-0.1-0.2-0.3-0.1-0.4z" />
16+
</group>
17+
18+
</vector>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:width="24dp"
5+
android:height="24dp"
6+
android:viewportWidth="24"
7+
android:viewportHeight="24">
8+
<group
9+
android:pivotX="12"
10+
android:pivotY="12"
11+
android:scaleX="0.7"
12+
android:scaleY="0.7">
13+
<path
14+
android:fillColor="?attr/toolbarIconDisabledColor"
15+
android:pathData="M20.8 10.7l-4.3-4.3-1.1 1.1 4.3 4.3c0.1 0.1 0.1 0.3 0 0.4l-4.3 4.3 1.1 1.1 4.3-4.3c0.7-0.8 0.7-1.9 0-2.6zM4.2 11.8l4.3-4.3-1-1-4.3 4.3c-0.7 0.7-0.7 1.8 0 2.5l4.3 4.3 1.1-1.1-4.3-4.3c-0.2-0.1-0.2-0.3-0.1-0.4z" />
16+
</group>
17+
18+
</vector>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:width="24dp"
5+
android:height="24dp"
6+
android:viewportWidth="24"
7+
android:viewportHeight="24">
8+
<group
9+
android:pivotX="12"
10+
android:pivotY="12"
11+
android:scaleX="0.7"
12+
android:scaleY="0.7">
13+
<path
14+
android:fillColor="?attr/toolbarIconHighlightColor"
15+
android:pathData="M20.8 10.7l-4.3-4.3-1.1 1.1 4.3 4.3c0.1 0.1 0.1 0.3 0 0.4l-4.3 4.3 1.1 1.1 4.3-4.3c0.7-0.8 0.7-1.9 0-2.6zM4.2 11.8l4.3-4.3-1-1-4.3 4.3c-0.7 0.7-0.7 1.8 0 2.5l4.3 4.3 1.1-1.1-4.3-4.3c-0.2-0.1-0.2-0.3-0.1-0.4z" />
16+
</group>
17+
18+
</vector>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
tools:targetApi="lollipop">
6+
7+
<item android:drawable="@drawable/format_bar_button_code_disabled" android:state_enabled="false" />
8+
<item android:drawable="@drawable/format_bar_button_code_highlighted" android:state_checked="true" />
9+
<item android:drawable="@drawable/format_bar_button_code_highlighted" android:state_focused="true" />
10+
<item android:drawable="@drawable/format_bar_button_code" />
11+
12+
</animated-selector>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:width="24dp"
5+
android:height="24dp"
6+
android:tint="?attr/toolbarIconNormalColor"
7+
android:viewportWidth="24"
8+
android:viewportHeight="24">
9+
<group
10+
android:pivotX="12"
11+
android:pivotY="12"
12+
android:scaleX="0.7"
13+
android:scaleY="0.7">
14+
<path
15+
android:fillColor="@color/white"
16+
android:pathData="M18 4H6c-1.1 0-2 0.9-2 2v12c0 1.1 0.9 2 2 2h12c1.1 0 2-0.9 2-2V6c0-1.1-0.9-2-2-2zm0.5 14c0 0.3-0.2 0.5-0.5 0.5H6c-0.3 0-0.5-0.2-0.5-0.5V6c0-0.3 0.2-0.5 0.5-0.5h12c0.3 0 0.5 0.2 0.5 0.5v12zM7 16.5h6V15H7v1.5zm4-4h6V11h-6v1.5zM9 11H7v1.5h2V11zm6 5.5h2V15h-2v1.5z" />
17+
18+
</group>
19+
20+
</vector>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:width="24dp"
5+
android:height="24dp"
6+
android:tint="?attr/toolbarIconDisabledColor"
7+
android:viewportWidth="24"
8+
android:viewportHeight="24">
9+
<group
10+
android:pivotX="12"
11+
android:pivotY="12"
12+
android:scaleX="0.7"
13+
android:scaleY="0.7">
14+
<path
15+
android:fillColor="@color/white"
16+
android:pathData="M18 4H6c-1.1 0-2 0.9-2 2v12c0 1.1 0.9 2 2 2h12c1.1 0 2-0.9 2-2V6c0-1.1-0.9-2-2-2zm0.5 14c0 0.3-0.2 0.5-0.5 0.5H6c-0.3 0-0.5-0.2-0.5-0.5V6c0-0.3 0.2-0.5 0.5-0.5h12c0.3 0 0.5 0.2 0.5 0.5v12zM7 16.5h6V15H7v1.5zm4-4h6V11h-6v1.5zM9 11H7v1.5h2V11zm6 5.5h2V15h-2v1.5z" />
17+
18+
</group>
19+
20+
</vector>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:width="24dp"
5+
android:height="24dp"
6+
android:tint="?attr/toolbarIconHighlightColor"
7+
android:viewportWidth="24"
8+
android:viewportHeight="24">
9+
<group
10+
android:pivotX="12"
11+
android:pivotY="12"
12+
android:scaleX="0.7"
13+
android:scaleY="0.7">
14+
<path
15+
android:fillColor="@color/white"
16+
android:pathData="M18 4H6c-1.1 0-2 0.9-2 2v12c0 1.1 0.9 2 2 2h12c1.1 0 2-0.9 2-2V6c0-1.1-0.9-2-2-2zm0.5 14c0 0.3-0.2 0.5-0.5 0.5H6c-0.3 0-0.5-0.2-0.5-0.5V6c0-0.3 0.2-0.5 0.5-0.5h12c0.3 0 0.5 0.2 0.5 0.5v12zM7 16.5h6V15H7v1.5zm4-4h6V11h-6v1.5zM9 11H7v1.5h2V11zm6 5.5h2V15h-2v1.5z" />
17+
18+
</group>
19+
20+
</vector>

0 commit comments

Comments
 (0)