Skip to content

Commit

Permalink
Fix tab key on hardware keyboard
Browse files Browse the repository at this point in the history
+ Add a whitelist of keys if you want them to be treated as shortcuts
  • Loading branch information
massivemadness committed Jun 11, 2022
1 parent 54ef0fe commit 261b9d7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.blacksquircle.ui.editorkit.widget.TextProcessor
class ShortcutsPlugin : EditorPlugin(PLUGIN_ID) {

var onShortcutListener: OnShortcutListener? = null
var shortcutKeyFilter = emptyList<Int>()

override fun onAttached(editText: TextProcessor) {
super.onAttached(editText)
Expand All @@ -45,7 +46,7 @@ class ShortcutsPlugin : EditorPlugin(PLUGIN_ID) {
)

// Shortcuts can be handled only if one of following keys is pressed
if (shortcut.ctrl || shortcut.shift || shortcut.alt) {
if (shortcut.ctrl || shortcut.shift || shortcut.alt || keyCode in shortcutKeyFilter) {
if (onShortcutListener.onShortcut(shortcut)) {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class TextProcessor @JvmOverloads constructor(
private const val TAG = "TextProcessor"
}

private val plugins = mutableListOf<EditorPlugin>()
private val plugins = hashSetOf<EditorPlugin>()

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class EditorFragment : Fragment(R.layout.fragment_editor), BackPressedHandler,
else -> false
}
}
shortcutKeyFilter = listOf(KeyEvent.KEYCODE_TAB)
}
}
binding.editor.plugins(pluginSupplier)
Expand Down

0 comments on commit 261b9d7

Please sign in to comment.