Skip to content

Conversation

@AIksyer
Copy link

@AIksyer AIksyer commented Sep 5, 2025

fix #1672 The candidate box is in the wrong position
add lastCandidateCount to manage sticky state in WeaselPanel

The conditions for resetting the sticky state:

  1. When the input session ends (ctx.empty() is true)
  2. When the input position changes significantly (the position change exceeds the threshold)
  3. When the content of the candidate window is empty

@AIksyer
Copy link
Author

AIksyer commented Sep 5, 2025

DebugBefore

DebugBefore

DebugAfter

DebugAfter

@fxliang
Copy link
Contributor

fxliang commented Sep 5, 2025

还要要用形码测试,比如五笔,menu_size: 6,编码逐渐增加之后候选变少的情况下,m_sticky依然生效(同一次合成过程不会因为候选数量上下晃动)

另外,要lint,安装clang-format 18,用.\clang-format.ps1 -n格式化代码

@AIksyer
Copy link
Author

AIksyer commented Sep 5, 2025

@fxliang 我不知道该如何测试,我不会五笔,所以可能需要你来测试,目前拼音方案使用正常。

@AIksyer
Copy link
Author

AIksyer commented Sep 5, 2025

另外,我使用clang-format 19.1.1发现SystemTraySDK.cpp WeaselService.cpp imesetup.cpp存在格式问题,如果允许,我将push到仓库

@fxliang
Copy link
Contributor

fxliang commented Sep 9, 2025

另外,我使用clang-format 19.1.1发现SystemTraySDK.cpp WeaselService.cpp imesetup.cpp存在格式问题,如果允许,我将push到仓库

linter 不会频繁改,还是会保留在clang-format 18上

@AIksyer
Copy link
Author

AIksyer commented Sep 9, 2025

目前我使用全拼和小鹤双拼没发现bug,形码输入有待测试。

@fxliang
Copy link
Contributor

fxliang commented Nov 26, 2025

diff --git a/WeaselUI/WeaselPanel.cpp b/WeaselUI/WeaselPanel.cpp
index 58f16dc..76e0e6e 100644
--- a/WeaselUI/WeaselPanel.cpp
+++ b/WeaselUI/WeaselPanel.cpp
@@ -57,6 +57,7 @@ WeaselPanel::WeaselPanel(weasel::UI& ui)
       m_style(ui.style()),
       m_ostyle(ui.ostyle()),
       m_candidateCount(0),
+      m_lastCandidateCount(0),
       m_current_zhung_icon(),
       m_inputPos(CRect()),
       m_sticky(false),
@@ -133,6 +134,12 @@ void WeaselPanel::Refresh() {
   bool should_show_icon =
       (m_status.ascii_mode || !m_status.composing || !m_ctx.aux.empty());
   m_candidateCount = (BYTE)m_ctx.cinfo.candies.size();
+  // When the candidate window changes from having content to having no content,
+  // reset the sticky state
+  if (m_lastCandidateCount > 0 && m_candidateCount == 0) {
+    m_sticky = false;
+  }
+  m_lastCandidateCount = m_candidateCount;
   // check if to hide candidates window
   // show tips status, two kind of situation: 1) only aux strings, don't care
   // icon status; 2)only icon(ascii mode switching)
@@ -1121,6 +1128,22 @@ void WeaselPanel::MoveTo(RECT const& rc) {
   if (!m_layout)
     return;  // avoid handling nullptr in _RepositionWindow
   m_redraw_by_monitor_change = false;
+  // The conditions for resetting the sticky state:
+  // 1. When the input session ends (ctx.empty() is true)
+  // 2. When the input position changes significantly (the position change
+  // exceeds the threshold)
+  bool should_reset_sticky =
+      (m_ctx.empty() || (abs(rc.left - m_inputPos.left) > 50) ||
+       (abs(rc.bottom - m_inputPos.bottom) > 50));
+  if (should_reset_sticky && m_sticky) {
+    m_sticky = false;
+    // Force reposition the window
+    m_inputPos = rc;
+    m_inputPos.OffsetRect(0, 6);
+    _RepositionWindow(true);
+    RedrawWindow();
+    return;
+  }
   // if ascii_tip_follow_cursor set, move tip icon to mouse cursor
   if (m_style.ascii_tip_follow_cursor && m_ctx.empty() &&
       (!m_status.composing) && m_layout->ShouldDisplayStatusIcon()) {
diff --git a/WeaselUI/WeaselPanel.h b/WeaselUI/WeaselPanel.h
index 478e798..0be5e1f 100644
--- a/WeaselUI/WeaselPanel.h
+++ b/WeaselUI/WeaselPanel.h
@@ -134,6 +134,7 @@ class WeaselPanel

   CRect rcw;
   BYTE m_candidateCount;
+  BYTE m_lastCandidateCount;

   bool hide_candidates;
   bool m_sticky;

这样应该简单一点,试过形码候选减少的时候m_sticky符合预期的表现

(m_ctx.cinfo.candies.empty() && !m_status.composing) 这个条件成立的时候,基本上就是tip显示(WeaselServer中调用),即(!m_ctx.aux.empty() && !m_status.composing),这个状态下m_sticky是不是reset通常影响不大了,可以先不改看看表现

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

notepad衍生记事本候选框位置问题

2 participants