Skip to content

Commit 43646eb

Browse files
committed
hidePanel API to fix f5j auto expand
1 parent 770188c commit 43646eb

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

page/api.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
hoverables,
2424
panel,
2525
preedit,
26+
theme,
2627
} from './selector'
2728
import {
2829
setAccentColor,
@@ -117,6 +118,10 @@ const arrowBack = common.replace('{}', '0 0 24 24').replace('{}', 'M16.62 2.99a1
117118
const arrowForward = common.replace('{}', '0 0 24 24').replace('{}', 'M7.38 21.01c.49.49 1.28.49 1.77 0l8.31-8.31a.996.996 0 0 0 0-1.41L9.15 2.98c-.49-.49-1.28-.49-1.77 0s-.49 1.28 0 1.77L14.62 12l-7.25 7.25c-.48.48-.48 1.28.01 1.76z')
118119

119120
function setCandidates(cands: Candidate[], highlighted: number, markText: string, pageable: boolean, hasPrev: boolean, hasNext: boolean, scrollState: SCROLL_STATE, scrollStart: boolean, scrollEnd: boolean) {
121+
if (cands.length) {
122+
// Auto layout requires display: not none so that getBoundingClientRect works.
123+
theme.classList.remove('fcitx-hidden')
124+
}
120125
const isVertical = hoverables.classList.contains('fcitx-vertical')
121126
resetMouseMoveState()
122127
hideContextmenu()
@@ -267,12 +272,21 @@ function updateElement(element: Element, innerHTML: string) {
267272
}
268273

269274
function updateInputPanel(preeditHTML: string, auxUpHTML: string, auxDownHTML: string) {
275+
if (preeditHTML || auxUpHTML || auxDownHTML) {
276+
theme.classList.remove('fcitx-hidden')
277+
}
270278
hideContextmenu()
271279
updateElement(preedit, preeditHTML)
272280
updateElement(auxUp, auxUpHTML)
273281
updateElement(auxDown, auxDownHTML)
274282
}
275283

284+
function hidePanel() {
285+
updateInputPanel('', '', '')
286+
setCandidates([], -1, '', false, false, false, SCROLL_NONE, false, false)
287+
theme.classList.add('fcitx-hidden')
288+
}
289+
276290
function copyHTML() {
277291
const html = document.documentElement.outerHTML
278292
fcitx._copyHTML(html)
@@ -298,6 +312,7 @@ hoverables.addEventListener('wheel', (e) => {
298312
fcitx.setCandidates = setCandidates
299313
fcitx.setLayout = setLayout
300314
fcitx.updateInputPanel = updateInputPanel
315+
fcitx.hidePanel = hidePanel
301316
fcitx.resize = resize
302317
fcitx.setTheme = setTheme
303318
fcitx.setAccentColor = setAccentColor

page/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ declare global {
143143
setCandidates: (cands: Candidate[], highlighted: number, markText: string, pageable: boolean, hasPrev: boolean, hasNext: boolean, scrollState: SCROLL_STATE, scrollStart: boolean, scrollEnd: boolean) => void
144144
setLayout: (layout: LAYOUT) => void
145145
updateInputPanel: (preeditHTML: string, auxUpHTML: string, auxDownHTML: string) => void
146+
hidePanel: () => void
146147
resize: (new_epoch: number, dx: number, dy: number, dragging: boolean, hasContextmenu: boolean) => void
147148
setTheme: (theme: 0 | 1 | 2) => void
148149
setAccentColor: (color: number | null | string) => void

src/platform/macos.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,7 @@ static void setViewCornerRadius(NSView *view, CGFloat width, CGFloat height,
313313
[window setIsVisible:NO];
314314
hidden_ = true;
315315
epoch += 1;
316-
invoke_js("updateInputPanel", "", "", "");
317-
invoke_js("setCandidates", std::vector<Candidate>(), -1, "", false, false,
318-
false, scroll_state_t::none, false, false);
316+
invoke_js("hidePanel");
319317
}
320318

321319
void WebviewCandidateWindow::write_clipboard(const std::string &html) {

0 commit comments

Comments
 (0)