@@ -31,6 +31,11 @@ export function setHighlightMarkText(text: string) {
3131 markText = text
3232}
3333
34+ let caretText = ''
35+ export function setCaretText ( text : string ) {
36+ caretText = text
37+ }
38+
3439export function moveHighlight ( from : Element | null , to : Element | null ) {
3540 from ?. classList . remove ( 'fcitx-highlighted' )
3641 to ?. classList . add ( 'fcitx-highlighted' )
@@ -204,28 +209,55 @@ export function setCandidates(cands: Candidate[], highlighted: number, pageable:
204209 }
205210}
206211
207- function updateElement ( element : Element , innerHTML : string ) {
208- if ( innerHTML === '' ) {
212+ function updateElement ( element : Element , formatted : [ string , number ] [ ] ) {
213+ element . innerHTML = ''
214+ if ( formatted . length === 0 ) {
209215 element . classList . add ( 'fcitx-hidden' )
210216 }
211217 else {
212- element . innerHTML = innerHTML
218+ for ( const [ text , _ ] of formatted ) { // Ignore format for now.
219+ const child = div ( )
220+ child . textContent = text
221+ element . appendChild ( child )
222+ }
213223 element . classList . remove ( 'fcitx-hidden' )
214224 }
215225}
216226
217- export function updateInputPanel ( preeditHTML : string , auxUpHTML : string , auxDownHTML : string ) {
218- if ( preeditHTML || auxUpHTML || auxDownHTML ) {
227+ export function updateInputPanel ( formattedPreCaret : [ string , number ] [ ] , hasCaret : boolean , formattedPostCaret : [ string , number ] [ ] , formattedAuxUp : [ string , number ] [ ] , formattedAuxDown : [ string , number ] [ ] ) {
228+ const hasPreedit = formattedPreCaret . length || formattedPostCaret . length
229+ if ( hasPreedit || formattedAuxUp . length || formattedAuxDown . length ) {
219230 theme . classList . remove ( 'fcitx-hidden' )
220231 }
221232 hideContextmenu ( )
222- updateElement ( preedit , preeditHTML )
223- updateElement ( auxUp , auxUpHTML )
224- updateElement ( auxDown , auxDownHTML )
233+
234+ const preCaret = preedit . querySelector ( '.fcitx-pre-caret' ) as HTMLElement
235+ const caret = preedit . querySelector ( '.fcitx-caret' ) as HTMLElement
236+ const postCaret = preedit . querySelector ( '.fcitx-post-caret' ) as HTMLElement
237+
238+ updateElement ( preCaret , formattedPreCaret )
239+ if ( hasCaret ) {
240+ caret . textContent = caretText
241+ if ( caretText ) {
242+ caret . classList . remove ( 'fcitx-no-text' )
243+ }
244+ else {
245+ caret . classList . add ( 'fcitx-no-text' )
246+ }
247+ }
248+ updateElement ( postCaret , formattedPostCaret )
249+ if ( hasPreedit ) {
250+ preedit . classList . remove ( 'fcitx-hidden' )
251+ }
252+ else {
253+ preedit . classList . add ( 'fcitx-hidden' )
254+ }
255+ updateElement ( auxUp , formattedAuxUp )
256+ updateElement ( auxDown , formattedAuxDown )
225257}
226258
227259export function hidePanel ( ) {
228- updateInputPanel ( '' , '' , '' )
260+ updateInputPanel ( [ ] , false , [ ] , [ ] , [ ] )
229261 setCandidates ( [ ] , - 1 , false , false , false , SCROLL_NONE , false , false )
230262 theme . classList . add ( 'fcitx-hidden' )
231263}
0 commit comments