mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-15 06:22:45 +00:00
add home, end and select word toolbar keys, fixes #409
This commit is contained in:
parent
e8e4354600
commit
c9d52e8090
13 changed files with 74 additions and 6 deletions
|
@ -68,7 +68,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.SELECT_ALL, ToolbarKey.CLEAR_CLIPBOARD, ToolbarKey.ONE_HANDED)
|
||||
listOf(ToolbarKey.LEFT, ToolbarKey.RIGHT, ToolbarKey.COPY, ToolbarKey.SELECT_WORD, ToolbarKey.SELECT_ALL, ToolbarKey.CLEAR_CLIPBOARD, ToolbarKey.ONE_HANDED)
|
||||
.forEach { toolbarKeys.add(createToolbarKey(context, keyboardAttr, it)) }
|
||||
keyboardAttr.recycle()
|
||||
}
|
||||
|
|
|
@ -641,8 +641,16 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
|||
}
|
||||
|
||||
public void selectAll() {
|
||||
if (!isConnected()) return;
|
||||
mIC.performContextMenuAction(android.R.id.selectAll);
|
||||
// the rest is done via LatinIME.onUpdateSelection
|
||||
}
|
||||
|
||||
public void selectWord(final SpacingAndPunctuations spacingAndPunctuations, final int scriptId) {
|
||||
if (!isConnected()) return;
|
||||
if (mExpectedSelStart != mExpectedSelEnd) return; // already something selected
|
||||
final TextRange range = getWordRangeAtCursor(spacingAndPunctuations, scriptId, false);
|
||||
if (range == null) return;
|
||||
mIC.setSelection(mExpectedSelStart - range.getNumberOfCharsInWordBeforeCursor(), mExpectedSelStart + range.getNumberOfCharsInWordAfterCursor());
|
||||
}
|
||||
|
||||
public void copyText() {
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.dslul.openboard.inputmethod.latin.common;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.dslul.openboard.inputmethod.annotations.UsedForTesting;
|
||||
import org.dslul.openboard.inputmethod.latin.BuildConfig;
|
||||
|
||||
public final class Constants {
|
||||
|
@ -229,6 +228,9 @@ public final class Constants {
|
|||
public static final int CODE_REDO = -30;
|
||||
public static final int CODE_TOGGLE_AUTOCORRECT = -31;
|
||||
public static final int CODE_TOGGLE_INCOGNITO = -32;
|
||||
public static final int CODE_HOME = -33;
|
||||
public static final int CODE_END = -34;
|
||||
public static final int CODE_SELECT_WORD = -35;
|
||||
// Code value representing the code is not specified.
|
||||
public static final int CODE_UNSPECIFIED = -200;
|
||||
|
||||
|
|
|
@ -709,6 +709,9 @@ public final class InputLogic {
|
|||
case Constants.CODE_SELECT_ALL:
|
||||
mConnection.selectAll();
|
||||
break;
|
||||
case Constants.CODE_SELECT_WORD:
|
||||
mConnection.selectWord(inputTransaction.getMSettingsValues().mSpacingAndPunctuations, currentKeyboardScriptId);
|
||||
break;
|
||||
case Constants.CODE_COPY:
|
||||
mConnection.copyText();
|
||||
break;
|
||||
|
@ -730,6 +733,12 @@ public final class InputLogic {
|
|||
case Constants.CODE_REDO:
|
||||
sendDownUpKeyEventWithMetaState(KeyEvent.KEYCODE_Z, KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON);
|
||||
break;
|
||||
case Constants.CODE_HOME:
|
||||
sendDownUpKeyEvent(KeyEvent.KEYCODE_MOVE_HOME);
|
||||
break;
|
||||
case Constants.CODE_END:
|
||||
sendDownUpKeyEvent(KeyEvent.KEYCODE_MOVE_END);
|
||||
break;
|
||||
case Constants.CODE_SHORTCUT:
|
||||
// switching to shortcut IME, shift state, keyboard,... is handled by LatinIME,
|
||||
// {@link KeyboardSwitcher#onEvent(Event)}, or {@link #onPressKey(int,int,boolean)} and {@link #onReleaseKey(int,boolean)}.
|
||||
|
|
|
@ -11,7 +11,6 @@ import org.dslul.openboard.inputmethod.latin.R
|
|||
import org.dslul.openboard.inputmethod.latin.common.Constants.*
|
||||
import org.dslul.openboard.inputmethod.latin.settings.Settings
|
||||
import org.dslul.openboard.inputmethod.latin.utils.ToolbarKey.*
|
||||
import java.util.EnumSet
|
||||
|
||||
fun createToolbarKey(context: Context, keyboardAttr: TypedArray, key: ToolbarKey): ImageButton {
|
||||
val button = ImageButton(context, null, R.attr.suggestionWordStyle)
|
||||
|
@ -50,6 +49,9 @@ fun getCodeForToolbarKey(key: ToolbarKey) = when (key) {
|
|||
REDO -> CODE_REDO
|
||||
INCOGNITO -> CODE_TOGGLE_INCOGNITO
|
||||
AUTOCORRECT -> CODE_TOGGLE_AUTOCORRECT
|
||||
FULL_LEFT -> CODE_HOME
|
||||
FULL_RIGHT -> CODE_END
|
||||
SELECT_WORD -> CODE_SELECT_WORD
|
||||
CLEAR_CLIPBOARD -> null // not managed via code input
|
||||
}
|
||||
|
||||
|
@ -69,18 +71,22 @@ private fun getStyleableIconId(key: ToolbarKey) = when (key) {
|
|||
INCOGNITO -> R.styleable.Keyboard_iconIncognitoKey
|
||||
AUTOCORRECT -> R.styleable.Keyboard_iconLanguageSwitchKey
|
||||
CLEAR_CLIPBOARD -> R.styleable.Keyboard_iconClearClipboardKey
|
||||
FULL_LEFT -> R.styleable.Keyboard_iconFullLeft
|
||||
FULL_RIGHT -> R.styleable.Keyboard_iconFullRight
|
||||
SELECT_WORD -> R.styleable.Keyboard_iconSelectWord
|
||||
}
|
||||
|
||||
// names need to be aligned with resources strings (using lowercase of key.name)
|
||||
enum class ToolbarKey {
|
||||
VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, COPY, ONE_HANDED, LEFT, RIGHT, UP, DOWN, INCOGNITO, AUTOCORRECT, CLEAR_CLIPBOARD
|
||||
VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, ONE_HANDED, LEFT, RIGHT, UP, DOWN,
|
||||
FULL_LEFT, FULL_RIGHT, INCOGNITO, AUTOCORRECT, CLEAR_CLIPBOARD
|
||||
}
|
||||
|
||||
fun toToolbarKeyString(keys: Collection<ToolbarKey>) = keys.joinToString(";") { it.name }
|
||||
|
||||
val defaultToolbarPref = entries.filterNot { it == CLEAR_CLIPBOARD }.joinToString(";") {
|
||||
when (it) {
|
||||
INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED -> "${it.name},false"
|
||||
INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED, FULL_LEFT, FULL_RIGHT -> "${it.name},false"
|
||||
else -> "${it.name},true"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue