Skip to content

Commit 408c2e6

Browse files
committed
feat: custom to fix candidate box
1 parent 1d5abbe commit 408c2e6

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

Lib/RabbitCommon.ahk

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class RabbitConfig {
150150
static global_ascii := false
151151
static preset_process_ascii := Map()
152152
static schema_icon := Map()
153+
static fix_candidate_box := false
153154

154155
static load() {
155156
global rime
@@ -179,6 +180,9 @@ class RabbitConfig {
179180
rime.config_end(iter)
180181
}
181182

183+
if rime.config_test_get_bool(config, "fix_candidate_box", &result)
184+
RabbitConfig.fix_candidate_box := !!result
185+
182186
rime.config_close(config)
183187

184188
if !schema_list := rime.get_schema_list()

Rabbit.ahk

+29-17
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ ProcessKey(key, mask, this_hotkey) {
362362
}
363363

364364
if context := rime.get_context(session_id) {
365+
static prev_show := false
366+
static prev_x := 4
367+
static prev_y := 4
365368
if context.composition.length > 0 {
366369
DetectHiddenWindows True
367370
local start_menu := WinActive("ahk_class Windows.UI.Core.CoreWindow ahk_exe StartMenuExperienceHost.exe")
@@ -380,37 +383,46 @@ ProcessKey(key, mask, this_hotkey) {
380383
}
381384
if !show_at_left_top && GetCaretPos(&caret_x, &caret_y, &caret_w, &caret_h) {
382385
box.Build(context, &box_width, &box_height)
383-
new_x := caret_x + caret_w
384-
new_y := caret_y + caret_h + 4
385-
386-
hWnd := WinExist("A")
387-
hMon := MonitorManage.MonitorFromWindow(hWnd)
388-
info := MonitorManage.GetMonitorInfo(hMon)
389-
if info {
390-
if new_x + box_width > info.work.right
391-
new_x := info.work.right - box_width
392-
if new_y + box_height > info.work.bottom
393-
new_y := caret_y - 4 - box_height
386+
if RabbitConfig.fix_candidate_box && prev_show {
387+
new_x := prev_x
388+
new_y := prev_y
394389
} else {
395-
workspace_width := SysGet(16) ; SM_CXFULLSCREEN
396-
workspace_height := SysGet(17) ; SM_CYFULLSCREEN
397-
if new_x + box_width > workspace_width
398-
new_x := workspace_width - box_width
399-
if new_y + box_height > workspace_height
400-
new_y := caret_y - 4 - box_height
390+
new_x := caret_x + caret_w
391+
new_y := caret_y + caret_h + 4
392+
393+
hWnd := WinExist("A")
394+
hMon := MonitorManage.MonitorFromWindow(hWnd)
395+
info := MonitorManage.GetMonitorInfo(hMon)
396+
if info {
397+
if new_x + box_width > info.work.right
398+
new_x := info.work.right - box_width
399+
if new_y + box_height > info.work.bottom
400+
new_y := caret_y - 4 - box_height
401+
} else {
402+
workspace_width := SysGet(16) ; SM_CXFULLSCREEN
403+
workspace_height := SysGet(17) ; SM_CYFULLSCREEN
404+
if new_x + box_width > workspace_width
405+
new_x := workspace_width - box_width
406+
if new_y + box_height > workspace_height
407+
new_y := caret_y - 4 - box_height
408+
}
401409
}
402410
if !last_is_hide
403411
box.Show("AutoSize NA x" . new_x . " y" . new_y)
412+
prev_x := new_x
413+
prev_y := new_y
404414
} else if !show_at_left_top {
405415
has_selected := GetCompositionText(context.composition, &pre_selected, &selected, &post_selected)
406416
preedit_text := pre_selected
407417
if has_selected
408418
preedit_text := preedit_text . "[" . selected "]" . post_selected
409419
ToolTip(preedit_text . "`r`n" . GetMenuText(context.menu))
410420
}
421+
prev_show := true
411422
} else {
412423
ToolTip()
413424
box.Show("Hide")
425+
prev_show := false
414426
}
415427
rime.free_context(context)
416428
}

schemas/rabbit.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ app_options:
2020

2121
# Use global ascii mode
2222
global_ascii: false
23+
24+
# Always show candidate box at top-left corner
25+
fix_candidate_box: false

0 commit comments

Comments
 (0)