Skip to content

Commit

Permalink
perf: enhance ascii mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tumuyan committed Apr 21, 2022
1 parent 5008d36 commit bacd46d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/assets/rime/trime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ preset_keyboards:
letter:
__include: /preset_keyboards/default
ascii_mode: 1
reset_ascii_mode: true #显示键盘时重置为ascii_mode指定的状态
lock: false
qwerty0:
name: 預設36鍵
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/ime/core/Trime.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public void bindKeyboardToInputView() {
* a sentence.
*/
private void dispatchCapsStateToInputView() {
if ((isAutoCaps || Rime.isAsciiMode())
if ((isAutoCaps && Rime.isAsciiMode())
&& (mainKeyboardView != null && !mainKeyboardView.isCapsOn())) {
mainKeyboardView.setShifted(false, activeEditorInstance.getCursorCapsMode() != 0);
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/osfans/trime/ime/keyboard/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class Keyboard {
/** Keyboard mode, or zero, if none. */
private int mAsciiMode;

private boolean resetAsciiMode;

// Variables for pre-computing nearest keys.
private String mLabelTransform;
private int mCellWidth;
Expand Down Expand Up @@ -195,6 +197,7 @@ public Keyboard(Context context, String name) {
mAsciiMode = YamlUtils.INSTANCE.getInt(keyboardConfig, "ascii_mode", 1);
if (mAsciiMode == 0)
mAsciiKeyboard = YamlUtils.INSTANCE.getString(keyboardConfig, "ascii_keyboard", "");
resetAsciiMode = YamlUtils.INSTANCE.getBoolean(keyboardConfig, "reset_ascii_mode", false);
mLock = YamlUtils.INSTANCE.getBoolean(keyboardConfig, "lock", false);
int columns = YamlUtils.INSTANCE.getInt(keyboardConfig, "columns", 30);
int defaultWidth =
Expand Down Expand Up @@ -588,6 +591,10 @@ public boolean getAsciiMode() {
return mAsciiMode != 0;
}

public boolean isResetAsciiMode() {
return resetAsciiMode;
}

public String getAsciiKeyboard() {
return mAsciiKeyboard;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,9 @@ class KeyboardSwitcher {
currentId = if (id.isValidId()) id else 0
}

public fun getCurrentKeyboardName(): String {
return keyboardNames.get(currentId)
}

private fun Int.isValidId() = this in keyboards.indices
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ class TextInputManager private constructor() :
it.switchToKeyboard(keyboardType)
}
Rime.get(trime)

// style/reset_ascii_mode指定了弹出键盘时是否重置ASCII状态。
// 键盘的reset_ascii_mode指定了重置时是否重置到keyboard的ascii_mode描述的状态。
if (shouldResetAsciiMode && keyboardSwitcher.currentKeyboard.isResetAsciiMode) {
tempAsciiMode = keyboardSwitcher.currentKeyboard.asciiMode
}
tempAsciiMode?.let { Rime.setOption("ascii_mode", it) }
isComposable = isComposable && !Rime.isEmpty()
if (!trime.onEvaluateInputViewShown()) {
Expand Down

0 comments on commit bacd46d

Please sign in to comment.