Skip to content

Shift_L and Shift_R cannot be distinguished in ascii_composer - shared shift_key_pressed_ state #1116

@xiaoqing2265

Description

@xiaoqing2265

Bug Description

When configuring Shift_R: noop and Shift_L: commit_code, pressing Right Shift + ' to input paired quotes still triggers input method switching. The expected behavior is that only Left Shift should toggle ascii_mode.

Environment

  • OS: macOS 15+ (Sequoia)
  • Rime frontend: Squirrel
  • librime version: 1.13.0

Configuration

# default.custom.yaml
patch:
  ascii_composer/switch_key/Shift_L: commit_code
  ascii_composer/switch_key/Shift_R: noop

##Root Cause Analysis
In src/rime/gear/ascii_composer.cc, there is a single shift_key_pressed_ boolean variable that doesn't distinguish between Left and Right Shift:

// ascii_composer.h
bool shift_key_pressed_ = false;  // Shared state, doesn't track L/R

// ascii_composer.cc - key down
if (is_shift)
    shift_key_pressed_ = true;  // Doesn't record which Shift was pressed

// ascii_composer.cc - key up
if (is_shift && shift_key_pressed_ && now < toggle_expired_) {
    ToggleAsciiModeWithKey(ch);  // Uses actual keycode (XK_Shift_L or XK_Shift_R)
}

The code correctly uses XK_Shift_L / XK_Shift_R keycodes to distinguish Left/Right in ToggleAsciiModeWithKey(), but the shift_key_pressed_ state variable conflates both.

Proposed Fix

Split shift_key_pressed_ into shift_l_pressed_ and shift_r_pressed_:

// ascii_composer.h
bool shift_l_pressed_ = false;
bool shift_r_pressed_ = false;

// ascii_composer.cc - key down
if (ch == XK_Shift_L)
    shift_l_pressed_ = true;
else if (ch == XK_Shift_R)
    shift_r_pressed_ = true;

// ascii_composer.cc - key up
if (key_event.release()) {
    if ((ch == XK_Shift_L && shift_l_pressed_) ||
        (ch == XK_Shift_R && shift_r_pressed_)) {
        if (now < toggle_expired_) {
            ToggleAsciiModeWithKey(ch);
        }
    }
    if (ch == XK_Shift_L) shift_l_pressed_ = false;
    if (ch == XK_Shift_R) shift_r_pressed_ = false;
}

Steps to Reproduce

1.Configure Shift_R: noop and Shift_L: commit_code
2.Deploy Rime
3.In. any app, switch to Chinese input mode
4.Press Right Shift + ' to input paired quote "
5.Observe that input method switches to English (unexpected)

Expected Behavior

Only Left Shift should trigger the mode switch. Right Shift + punctuation should not change the input mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions