Skip to content

Commit

Permalink
Support indent and outdent
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Jun 13, 2024
1 parent f8562fe commit 988bae6
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ internal class JsBridge(

fun removeFormat() = execCommand(OtherCommand.REMOVE_FORMAT)

fun indent() = execCommand(OtherCommand.INDENT)

fun outdent() = execCommand(OtherCommand.OUTDENT)

fun setTextColor(color: JsColor) = execCommand(StatusCommand.TEXT_COLOR, color)

fun setTextBackgroundColor(color: JsColor) = execCommand(StatusCommand.BACKGROUND_COLOR, color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class RichHtmlEditorWebView @JvmOverloads constructor(
fun toggleSubscript() = jsBridge.toggleSubscript()
fun toggleSuperscript() = jsBridge.toggleSuperscript()
fun removeFormat() = jsBridge.removeFormat()
fun indent() = jsBridge.indent()
fun outdent() = jsBridge.outdent()
fun setTextColor(@ColorInt color: Int) = jsBridge.setTextColor(JsColor(color))
fun setTextBackgroundColor(@ColorInt color: Int) = jsBridge.setTextBackgroundColor(JsColor(color))
fun setFontSize(@IntRange(from = 1, to = 7) fontSize: Int) = jsBridge.setFontSize(fontSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ enum class StatusCommand(override val argumentName: String, val statusType: Stat

enum class OtherCommand(override val argumentName: String) : ExecCommand {
REMOVE_FORMAT("removeFormat"),
INDENT("indent"),
OUTDENT("outdent"),
}

interface ExecCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class EditorSampleFragment : Fragment() {
unorderedList.setOnClickListener { editor.toggleUnorderedList() }
buttonSubscript.setOnClickListener { editor.toggleSubscript() }
buttonSuperscript.setOnClickListener { editor.toggleSuperscript() }
buttonOutdent.setOnClickListener { editor.outdent() }
buttonIndent.setOnClickListener { editor.indent() }

buttonExportHtml.setOnClickListener { editor.exportHtml { html -> Log.d("editor", "Output html: $html") } }

Expand Down
13 changes: 13 additions & 0 deletions sample/src/main/res/drawable/ic_indent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="#000000"
android:viewportWidth="960"
android:viewportHeight="960">

<path
android:fillColor="@android:color/white"
android:pathData="M160,840Q143,840 131.5,828.5Q120,817 120,800Q120,783 131.5,771.5Q143,760 160,760L800,760Q817,760 828.5,771.5Q840,783 840,800Q840,817 828.5,828.5Q817,840 800,840L160,840ZM480,680Q463,680 451.5,668.5Q440,657 440,640Q440,623 451.5,611.5Q463,600 480,600L800,600Q817,600 828.5,611.5Q840,623 840,640Q840,657 828.5,668.5Q817,680 800,680L480,680ZM480,520Q463,520 451.5,508.5Q440,497 440,480Q440,463 451.5,451.5Q463,440 480,440L800,440Q817,440 828.5,451.5Q840,463 840,480Q840,497 828.5,508.5Q817,520 800,520L480,520ZM480,360Q463,360 451.5,348.5Q440,337 440,320Q440,303 451.5,291.5Q463,280 480,280L800,280Q817,280 828.5,291.5Q840,303 840,320Q840,337 828.5,348.5Q817,360 800,360L480,360ZM160,200Q143,200 131.5,188.5Q120,177 120,160Q120,143 131.5,131.5Q143,120 160,120L800,120Q817,120 828.5,131.5Q840,143 840,160Q840,177 828.5,188.5Q817,200 800,200L160,200ZM154,606Q144,616 132,611Q120,606 120,592L120,368Q120,354 132,349Q144,344 154,354L266,466Q272,472 272,480Q272,488 266,494L154,606Z" />

</vector>
13 changes: 13 additions & 0 deletions sample/src/main/res/drawable/ic_outdent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="#000000"
android:viewportWidth="960"
android:viewportHeight="960">

<path
android:fillColor="@android:color/white"
android:pathData="M160,840Q143,840 131.5,828.5Q120,817 120,800Q120,783 131.5,771.5Q143,760 160,760L800,760Q817,760 828.5,771.5Q840,783 840,800Q840,817 828.5,828.5Q817,840 800,840L160,840ZM480,680Q463,680 451.5,668.5Q440,657 440,640Q440,623 451.5,611.5Q463,600 480,600L800,600Q817,600 828.5,611.5Q840,623 840,640Q840,657 828.5,668.5Q817,680 800,680L480,680ZM480,520Q463,520 451.5,508.5Q440,497 440,480Q440,463 451.5,451.5Q463,440 480,440L800,440Q817,440 828.5,451.5Q840,463 840,480Q840,497 828.5,508.5Q817,520 800,520L480,520ZM480,360Q463,360 451.5,348.5Q440,337 440,320Q440,303 451.5,291.5Q463,280 480,280L800,280Q817,280 828.5,291.5Q840,303 840,320Q840,337 828.5,348.5Q817,360 800,360L480,360ZM160,200Q143,200 131.5,188.5Q120,177 120,160Q120,143 131.5,131.5Q143,120 160,120L800,120Q817,120 828.5,131.5Q840,143 840,160Q840,177 828.5,188.5Q817,200 800,200L160,200ZM246,606L134,494Q128,488 128,480Q128,472 134,466L246,354Q256,344 268,349Q280,354 280,368L280,592Q280,606 268,611Q256,616 246,606Z" />

</vector>
14 changes: 14 additions & 0 deletions sample/src/main/res/layout/fragment_editor_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@
android:layout_height="wrap_content"
app:icon="@drawable/ic_superscript" />

<com.google.android.material.button.MaterialButton
android:id="@+id/buttonOutdent"
style="@style/EditorButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:icon="@drawable/ic_outdent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/buttonIndent"
style="@style/EditorButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:icon="@drawable/ic_indent" />

</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</HorizontalScrollView>
Expand Down

0 comments on commit 988bae6

Please sign in to comment.