Skip to content

Commit

Permalink
feat: Synchronize Android host undo/redo controls
Browse files Browse the repository at this point in the history
Communicate undo/redo availability state to Android host app.
  • Loading branch information
dcalhoun committed Jan 8, 2025
1 parent beaefbc commit 007bb41
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ class GutenbergView : WebView {

private var onFileChooserRequested: ((Intent, Int) -> Unit)? = null
private var contentChangeListener: ContentChangeListener? = null
private var historyChangeListener: HistoryChangeListener? = null
private var openMediaLibraryListener: OpenMediaLibraryListener? = null
private var editorDidBecomeAvailableListener: EditorAvailableListener? = null

fun setContentChangeListener(listener: ContentChangeListener) {
contentChangeListener = listener
}

fun setHistoryChangeListener(listener: HistoryChangeListener) {
historyChangeListener = listener
}

fun setOpenMediaLibraryListener(listener: OpenMediaLibraryListener) {
openMediaLibraryListener = listener
}
Expand Down Expand Up @@ -263,6 +268,10 @@ class GutenbergView : WebView {
fun onContentChanged(title: String, content: String)
}

interface HistoryChangeListener {
fun onHistoryChanged(hasUndo: Boolean, hasRedo: Boolean)
}

sealed class Value {
data class Single(val value: Int): Value()
data class Multiple(val values: IntArray): Value() {
Expand Down Expand Up @@ -329,6 +338,11 @@ class GutenbergView : WebView {
}, false)
}

@JavascriptInterface
fun onEditorHistoryChanged(hasUndo: Boolean, hasRedo: Boolean) {
historyChangeListener?.onHistoryChanged(hasUndo, hasRedo)
}

@JavascriptInterface
fun onBlocksChanged(isEmpty: Boolean) {
if(isEmpty) {
Expand Down Expand Up @@ -400,6 +414,7 @@ class GutenbergView : WebView {
clearConfig()
this.stopLoading()
contentChangeListener = null
historyChangeListener = null
editorDidBecomeAvailable = null
filePathCallback = null
onFileChooserRequested = null
Expand Down

0 comments on commit 007bb41

Please sign in to comment.