Skip to content

Commit

Permalink
apply librime's new change_page api to turn candidate page
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Mar 24, 2024
1 parent 25f6612 commit 9db6fd3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/MyPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import getCaretCoordinates from 'textarea-caret'
import emojiRegex from 'emoji-regex'
import {
process,
selectCandidateOnCurrentPage
selectCandidateOnCurrentPage,
changePage
} from '../workerAPI'
import {
text,
Expand Down Expand Up @@ -188,6 +189,10 @@ async function input (rimeKey: string) {
return analyze(result, rimeKey)
}
async function onPageChange (backward: boolean) {
await changePage(backward)
}
// begin: code specific to Android Chromium
let androidChromium = false
let acStart = 0
Expand Down Expand Up @@ -414,7 +419,7 @@ defineExpose({
>
<n-icon
:component="CaretLeft"
@click="input('-')"
@click="onPageChange(false)"
/>
</n-button>
<n-button
Expand All @@ -423,7 +428,7 @@ defineExpose({
>
<n-icon
:component="CaretRight"
@click="input('=')"
@click="onPageChange(true)"
/>
</n-button>
</n-popover>
Expand Down
3 changes: 3 additions & 0 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,8 @@ expose({
},
selectCandidateOnCurrentPage (index: number): string {
return Module.ccall('select_candidate_on_current_page', 'string', ['number'], [index])
},
changePage (backward: boolean): void {
return Module.ccall('change_page', 'null', ['boolean'], [backward])
}
}, readyPromise)
2 changes: 2 additions & 0 deletions src/workerAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const setPageSize: (size: number) => Promise<void> = worker.register('setPageSiz
const deploy: () => Promise<void> = worker.register('deploy')
const process: (input: string) => Promise<RIME_RESULT> = worker.register('process')
const selectCandidateOnCurrentPage: (index: number) => Promise<string> = worker.register('selectCandidateOnCurrentPage')
const changePage: (backward: boolean) => Promise<void> = worker.register('changePage')
const resetUserDirectory: () => Promise<void> = worker.register('resetUserDirectory')
const FS = asyncFS(worker)

Expand All @@ -20,5 +21,6 @@ export {
deploy,
process,
selectCandidateOnCurrentPage,
changePage,
setIME
}
4 changes: 4 additions & 0 deletions wasm/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ const char *select_candidate_on_current_page(int index) {
return post_process();
}

void change_page(bool backward) {
rime_get_api()->change_page(session_id, backward);
}

void set_ime(const char *ime) {
if (rime_started) {
// Need to reset session when using F4 to select a schema
Expand Down

0 comments on commit 9db6fd3

Please sign in to comment.