@@ -12,8 +12,9 @@ use std::path::PathBuf;
1212use wind_bridge:: handler:: { KeyEventData , MessageHandler } ;
1313use wind_config:: Config ;
1414use wind_coordinator:: Coordinator ;
15+ use wind_ipc:: protocol:: MOD_SHIFT ;
1516use wind_ipc:: protocol:: { EVENT_KEY_DOWN , MOD_CTRL } ;
16- use wind_keys:: keymap:: { VK_LEFT , VK_RIGHT } ;
17+ use wind_keys:: keymap:: { VK_BACKTICK , VK_LEFT , VK_RIGHT } ;
1718
1819fn data_dir ( ) -> PathBuf {
1920 PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "../../../build_dev/data" )
@@ -158,3 +159,56 @@ fn ctrl_left_without_composition_passes_through() {
158159 "没有编码时 Ctrl+← 归宿主(按词移动),实际: {act:?}"
159160 ) ;
160161}
162+
163+ /// Shift+←/→:总是单字符,是走到音节中间的精调通路。
164+ #[ test]
165+ fn shift_arrows_step_one_char ( ) {
166+ if !data_ready ( ) {
167+ return ;
168+ }
169+ let c = coord ( ) ;
170+ type_code ( & c, "nihao" ) ;
171+ c. handle_key_event ( & key ( VK_LEFT , MOD_SHIFT ) ) ;
172+ assert_eq ! ( c. debug_ui_caret_bytes( ) , 5 , "ni'ha|o:单字符" ) ;
173+ c. handle_key_event ( & key ( VK_LEFT , MOD_SHIFT ) ) ;
174+ assert_eq ! ( c. debug_ui_caret_bytes( ) , 4 , "ni'h|ao:单字符" ) ;
175+ left ( & c) ; // 缓冲 nih| 在音节中间 → 单字符,落到 ni|hao(显示串里在 ' 之前)
176+ assert_eq ! ( c. debug_ui_caret_bytes( ) , 2 , "音节中间 ← 仍是单字符" ) ;
177+ }
178+
179+ fn overlay_coord ( ) -> std:: sync:: Arc < Coordinator > {
180+ let mut cfg = Config :: default ( ) ;
181+ cfg. schema . available = vec ! [ "wubi86" . into( ) , "pinyin" . into( ) ] ;
182+ cfg. schema . active = "wubi86" . into ( ) ;
183+ cfg. input . default . chinese_mode = true ;
184+ Coordinator :: new_headless ( cfg, Some ( & data_dir ( ) ) )
185+ }
186+
187+ /// 临拼 overlay(`` ` `` 引导)与主路同一套:边界整音节跳、Ctrl 总是整音节、Shift 单字符。
188+ #[ test]
189+ fn temp_pinyin_overlay_follows_same_rules ( ) {
190+ if !data_ready ( ) || !data_dir ( ) . join ( "schemas/wubi86.schema.toml" ) . exists ( ) {
191+ return ;
192+ }
193+ let c = overlay_coord ( ) ;
194+ c. handle_key_event ( & key ( VK_BACKTICK , 0 ) ) ;
195+ type_code ( & c, "nihao" ) ;
196+ let end = c. debug_ui_caret_bytes ( ) ;
197+ left ( & c) ;
198+ assert_eq ! (
199+ c. debug_ui_caret_bytes( ) ,
200+ 3 ,
201+ "`ni|hao:边界整音节(前缀 ` 占 1)"
202+ ) ;
203+ assert ! ( end > 3 ) ;
204+ c. handle_key_event ( & key ( VK_RIGHT , MOD_SHIFT ) ) ;
205+ assert_eq ! ( c. debug_ui_caret_bytes( ) , 5 , "Shift+→ 单字符(`ni'h|)" ) ;
206+ c. handle_key_event ( & key ( VK_LEFT , MOD_CTRL ) ) ;
207+ assert_eq ! ( c. debug_ui_caret_bytes( ) , 3 , "Ctrl+← 音节中间也跳到边界" ) ;
208+ c. handle_key_event ( & key ( VK_LEFT , MOD_CTRL ) ) ;
209+ assert_eq ! ( c. debug_ui_caret_bytes( ) , 1 , "再 Ctrl+← 到开头" ) ;
210+ assert ! (
211+ c. debug_preedit( ) . starts_with( '`' ) ,
212+ "仍在临拼里,组合没被清掉"
213+ ) ;
214+ }
0 commit comments