From f915e464688c12b491a4e0fa7225a69b1a1802d6 Mon Sep 17 00:00:00 2001 From: codokie <151087174+codokie@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:05:53 +0300 Subject: [PATCH] cut toolbar key (#678) --- .../keyboard/clipboard/ClipboardHistoryView.kt | 2 +- .../keyboard/keyboard/internal/KeyboardIconsSet.java | 2 ++ .../keyboard/latin/inputlogic/InputLogic.java | 9 +++++++++ .../helium314/keyboard/latin/utils/ToolbarUtils.kt | 6 ++++-- app/src/main/res/drawable/sym_keyboard_cut.xml | 12 ++++++++++++ app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/keyboard-icons-holo.xml | 1 + app/src/main/res/values/keyboard-icons-lxx-light.xml | 1 + app/src/main/res/values/keyboard-icons-rounded.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/drawable/sym_keyboard_cut.xml diff --git a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt index bb733a474..7e8ae9f8b 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt @@ -69,7 +69,7 @@ class ClipboardHistoryView @JvmOverloads constructor( // even when state is activated, the not activated color is set // in suggestionStripView the same thing works correctly, wtf? // need to properly fix it (and maybe undo the inverted isActivated) when adding a toggle key - listOf(ToolbarKey.LEFT, ToolbarKey.RIGHT, ToolbarKey.COPY, ToolbarKey.CLEAR_CLIPBOARD, ToolbarKey.SELECT_WORD, ToolbarKey.SELECT_ALL, ToolbarKey.CLOSE_HISTORY) + listOf(ToolbarKey.LEFT, ToolbarKey.RIGHT, ToolbarKey.COPY, ToolbarKey.CUT, ToolbarKey.CLEAR_CLIPBOARD, ToolbarKey.SELECT_WORD, ToolbarKey.SELECT_ALL, ToolbarKey.CLOSE_HISTORY) .forEach { toolbarKeys.add(createToolbarKey(context, keyboardAttr, it)) } keyboardAttr.recycle() } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardIconsSet.java b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardIconsSet.java index b07709d9d..58b375597 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardIconsSet.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardIconsSet.java @@ -52,6 +52,7 @@ public final class KeyboardIconsSet { public static final String NAME_CLIPBOARD_ACTION_KEY = "clipboard_action_key"; public static final String NAME_CLIPBOARD_NORMAL_KEY = "clipboard_normal_key"; public static final String NAME_CLEAR_CLIPBOARD_KEY = "clear_clipboard_key"; + public static final String NAME_CUT_KEY = "cut_key"; public static final String NAME_NUMPAD_KEY = "numpad_key"; public static final String NAME_START_ONEHANDED_KEY = "start_onehanded_mode_key"; public static final String NAME_STOP_ONEHANDED_KEY = "stop_onehanded_mode_key"; @@ -89,6 +90,7 @@ public final class KeyboardIconsSet { NAME_CLIPBOARD_ACTION_KEY, R.styleable.Keyboard_iconClipboardActionKey, NAME_CLIPBOARD_NORMAL_KEY, R.styleable.Keyboard_iconClipboardNormalKey, NAME_CLEAR_CLIPBOARD_KEY, R.styleable.Keyboard_iconClearClipboardKey, + NAME_CUT_KEY, R.styleable.Keyboard_iconCutKey, NAME_NUMPAD_KEY, R.styleable.Keyboard_iconNumpadKey, NAME_START_ONEHANDED_KEY, R.styleable.Keyboard_iconStartOneHandedMode, NAME_STOP_ONEHANDED_KEY, R.styleable.Keyboard_iconStopOneHandedMode, diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java index ac51dd806..8e70a4c8f 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -716,6 +716,15 @@ private void handleFunctionalEvent(final Event event, final InputTransaction inp case KeyCode.CLIPBOARD_COPY: mConnection.copyText(); break; + case KeyCode.CLIPBOARD_CUT: + if (mConnection.hasSelection()) { + mConnection.copyText(); + final Event backspaceEvent = LatinIME.createSoftwareKeypressEvent(KeyCode.DELETE, + event.getMX(), event.getMY(), event.isKeyRepeat()); + handleBackspaceEvent(backspaceEvent, inputTransaction, currentKeyboardScript); + inputTransaction.setDidAffectContents(); + } + break; case KeyCode.ARROW_LEFT: sendDownUpKeyEvent(KeyEvent.KEYCODE_DPAD_LEFT); break; diff --git a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt index 54f29f491..1edb9e6b4 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt @@ -43,6 +43,7 @@ fun getCodeForToolbarKey(key: ToolbarKey) = when (key) { CLIPBOARD -> KeyCode.CLIPBOARD SELECT_ALL -> KeyCode.CLIPBOARD_SELECT_ALL COPY -> KeyCode.CLIPBOARD_COPY + CUT -> KeyCode.CLIPBOARD_CUT ONE_HANDED -> if (Settings.getInstance().current.mOneHandedModeEnabled) KeyCode.STOP_ONE_HANDED_MODE else KeyCode.START_ONE_HANDED_MODE LEFT -> KeyCode.ARROW_LEFT RIGHT -> KeyCode.ARROW_RIGHT @@ -65,6 +66,7 @@ private fun getStyleableIconId(key: ToolbarKey) = when (key) { CLIPBOARD -> R.styleable.Keyboard_iconClipboardNormalKey SELECT_ALL -> R.styleable.Keyboard_iconSelectAll COPY -> R.styleable.Keyboard_iconCopyKey + CUT -> R.styleable.Keyboard_iconCutKey ONE_HANDED -> R.styleable.Keyboard_iconStartOneHandedMode LEFT -> R.styleable.Keyboard_iconArrowLeft RIGHT -> R.styleable.Keyboard_iconArrowRight @@ -92,7 +94,7 @@ fun getToolbarIconByName(name: String, context: Context): Drawable? { // names need to be aligned with resources strings (using lowercase of key.name) enum class ToolbarKey { - VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, ONE_HANDED, LEFT, RIGHT, UP, DOWN, + VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, CUT, ONE_HANDED, LEFT, RIGHT, UP, DOWN, FULL_LEFT, FULL_RIGHT, INCOGNITO, AUTOCORRECT, CLEAR_CLIPBOARD, CLOSE_HISTORY } @@ -100,7 +102,7 @@ fun toToolbarKeyString(keys: Collection) = keys.joinToString(";") { val defaultToolbarPref = entries.filterNot { it == CLEAR_CLIPBOARD || it == CLOSE_HISTORY }.joinToString(";") { when (it) { - INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED, FULL_LEFT, FULL_RIGHT -> "${it.name},false" + INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED, FULL_LEFT, FULL_RIGHT, CUT -> "${it.name},false" else -> "${it.name},true" } } diff --git a/app/src/main/res/drawable/sym_keyboard_cut.xml b/app/src/main/res/drawable/sym_keyboard_cut.xml new file mode 100644 index 000000000..d1fdaf208 --- /dev/null +++ b/app/src/main/res/drawable/sym_keyboard_cut.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index e9e4103fd..bb0c40edd 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -260,6 +260,7 @@ + diff --git a/app/src/main/res/values/keyboard-icons-holo.xml b/app/src/main/res/values/keyboard-icons-holo.xml index afb7fc3f3..e6dd92501 100644 --- a/app/src/main/res/values/keyboard-icons-holo.xml +++ b/app/src/main/res/values/keyboard-icons-holo.xml @@ -29,6 +29,7 @@ @drawable/sym_keyboard_clipboard_holo @drawable/sym_keyboard_clipboard_holo @drawable/sym_keyboard_copy + @drawable/sym_keyboard_cut @drawable/sym_keyboard_clear_clipboard_holo @drawable/sym_keyboard_start_onehanded_holo @drawable/sym_keyboard_stop_onehanded_holo diff --git a/app/src/main/res/values/keyboard-icons-lxx-light.xml b/app/src/main/res/values/keyboard-icons-lxx-light.xml index 6dfaa8c6d..a2868674f 100644 --- a/app/src/main/res/values/keyboard-icons-lxx-light.xml +++ b/app/src/main/res/values/keyboard-icons-lxx-light.xml @@ -34,6 +34,7 @@ @drawable/sym_keyboard_clipboard_lxx @drawable/sym_keyboard_clipboard_lxx @drawable/sym_keyboard_copy + @drawable/sym_keyboard_cut @drawable/sym_keyboard_clear_clipboard_lxx @drawable/sym_keyboard_start_onehanded_lxx @drawable/sym_keyboard_stop_onehanded_lxx diff --git a/app/src/main/res/values/keyboard-icons-rounded.xml b/app/src/main/res/values/keyboard-icons-rounded.xml index c7f0f4ef7..ad66ba327 100644 --- a/app/src/main/res/values/keyboard-icons-rounded.xml +++ b/app/src/main/res/values/keyboard-icons-rounded.xml @@ -33,6 +33,7 @@ @drawable/sym_keyboard_clipboard_rounded @drawable/sym_keyboard_clipboard_rounded @drawable/sym_keyboard_copy_rounded + @drawable/sym_keyboard_cut @drawable/sym_keyboard_clear_clipboard_rounded @drawable/sym_keyboard_start_onehanded_rounded @drawable/sym_keyboard_stop_onehanded_rounded diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6103af717..e1ce7785b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -229,6 +229,7 @@ Select toolbar keys @android:string/copy + Cut Clipboard Clear clipboard Voice input