Skip to content

Commit 0ba1706

Browse files
committed
drop pugixml
1 parent 3a474b9 commit 0ba1706

File tree

15 files changed

+90
-107
lines changed

15 files changed

+90
-107
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
[submodule "webview"]
22
path = webview
33
url = https://github.com/fcitx-contrib/webview
4-
[submodule "pugixml"]
5-
path = pugixml
6-
url = https://github.com/zeux/pugixml

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ elseif(EMSCRIPTEN)
3333
set(LIBS nlohmann_json::nlohmann_json)
3434
endif()
3535

36-
include_directories(pugixml/src)
37-
3836
if(NOT "${WKWEBVIEW_PROTOCOL}" STREQUAL "")
3937
add_definitions(-DWKWEBVIEW_PROTOCOL="${WKWEBVIEW_PROTOCOL}")
4038
add_definitions(-DWEBVIEW_WWW_PATH="${WEBVIEW_WWW_PATH}")

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Execute the following JavaScript code to show candidates and more:
3232
fcitx.setCandidates([
3333
{ text: "虚假的", label: "1", comment: "comment", actions: [{ "id": 1, "text": "删词" }] },
3434
{ text: "🀄", label: "2", comment: "", actions: [] },
35-
{ text: "candidates", label: "3", comment: "", actions: [] }], 0, "",
35+
{ text: "candidates", label: "3", comment: "", actions: [] }], 0,
3636
true, false, true, 0, false, false)
3737

3838
// Set writing mode. 0=horizontal-tb, 1=vertical-rl, 2=vertical-lr.
@@ -43,7 +43,7 @@ fcitx.setLayout(1)
4343

4444
// Show aux-up.
4545
fcitx.setCandidates([], -1)
46-
fcitx.updateInputPanel("", "A", "")
46+
fcitx.updateInputPanel([], false, [], [["A", 0]], [])
4747

4848
// Set theme to 0=system (default), 1=light or 2=dark.
4949
fcitx.setTheme(1)

include/utility.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,4 @@ template <typename T> function_traits<T> make_function_traits(const T &) {
4949
return function_traits<T>();
5050
}
5151

52-
std::string escape_html(const std::string &content);
5352
std::string base64(const std::string &s);

include/webview_candidate_window.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ enum format_t {
3030
Italic = (1 << 8),
3131
};
3232

33-
template <typename T> using formatted = std::vector<std::pair<T, int>>;
33+
using formatted = std::vector<std::pair<std::string, int>>;
3434

3535
enum class blur_t { none = 0, system = 1, blur = 2, liquid_glass = 3 };
3636

@@ -116,9 +116,8 @@ class WebviewCandidateWindow {
116116
#endif
117117

118118
// Below are allowed to be called from any thread.
119-
void update_input_panel(const formatted<std::string> &preedit, int caret,
120-
const formatted<std::string> &auxUp,
121-
const formatted<std::string> &auxDown);
119+
void update_input_panel(formatted preedit, int caret, formatted auxUp,
120+
formatted auxDown);
122121
void set_candidates(std::vector<Candidate> candidates, int highlighted,
123122
scroll_state_t scroll_state, bool scroll_start,
124123
bool scroll_end);
@@ -133,8 +132,6 @@ class WebviewCandidateWindow {
133132
highlight_callback = callback;
134133
}
135134

136-
void set_caret_text(const std::string &text) { caret_text_ = text; }
137-
138135
void set_page_callback(std::function<void(bool)> callback) {
139136
page_callback = callback;
140137
}
@@ -178,9 +175,11 @@ class WebviewCandidateWindow {
178175
std::string app_accent_color_ = "";
179176
layout_t layout_ = layout_t::horizontal;
180177
writing_mode_t writing_mode_ = writing_mode_t::horizontal_tb;
181-
std::string preedit_;
182-
std::string auxUp_;
183-
std::string auxDown_;
178+
formatted preeditPreCaret_;
179+
bool hasCaret_ = false;
180+
formatted preeditPostCaret_;
181+
formatted auxUp_;
182+
formatted auxDown_;
184183
std::vector<Candidate> candidates_;
185184
int highlighted_ = -1;
186185
scroll_state_t scroll_state_;
@@ -196,7 +195,6 @@ class WebviewCandidateWindow {
196195
std::function<void(int, int)> scroll_callback = [](int, int) {};
197196
std::function<void(int index)> ask_actions_callback = [](int) {};
198197
std::function<void(int index, int id)> action_callback = [](int, int) {};
199-
std::string caret_text_ = "";
200198
std::string system_ = "";
201199
int version_ = 0;
202200
bool pageable_ = false;

page/customize.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { distribution } from './distribution'
22
import { fixGhostStripe } from './ghost-stripe'
3-
import { setHighlightMarkText } from './panel'
3+
import { setCaretText, setHighlightMarkText } from './panel'
44
import { setAnimation, setScrollParams } from './scroll'
55
import { theme } from './selector'
66
import {
@@ -247,6 +247,7 @@ export function setStyle(style: string) {
247247

248248
// Caret
249249
setBlink(j.Caret.Style === 'Blink')
250+
setCaretText(j.Caret.Style === 'Text' ? j.Caret.Text : '')
250251

251252
// Highlight
252253
setHoverBehavior(j.Highlight.HoverBehavior)

page/global.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ declare global {
7272
}
7373
Caret: {
7474
Style: 'Blink' | 'Static' | 'Text'
75+
Text: string
7576
}
7677
Highlight: {
7778
MarkStyle: 'None' | 'Bar' | 'Text'
@@ -143,7 +144,7 @@ declare global {
143144
setHost: (system: string, version: number) => void
144145
setCandidates: (cands: Candidate[], highlighted: number, pageable: boolean, hasPrev: boolean, hasNext: boolean, scrollState: SCROLL_STATE, scrollStart: boolean, scrollEnd: boolean) => void
145146
setLayout: (layout: LAYOUT) => void
146-
updateInputPanel: (preeditHTML: string, auxUpHTML: string, auxDownHTML: string) => void
147+
updateInputPanel: (preCaret: [string, number][], hasCaret: boolean, postCaret: [string, number][], auxUp: [string, number][], auxDown: [string, number][]) => void
147148
hidePanel: () => void
148149
resize: (new_epoch: number, dx: number, dy: number, dragging: boolean, hasContextmenu: boolean) => void
149150
setTheme: (theme: 0 | 1 | 2) => void

page/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
<div class="fcitx-panel-blur">
3737
<div class="fcitx-header">
3838
<div class="fcitx-aux-up fcitx-hidden"></div>
39-
<div class="fcitx-preedit fcitx-hidden"></div>
39+
<div class="fcitx-preedit fcitx-hidden">
40+
<div class="fcitx-pre-caret"></div>
41+
<div class="fcitx-caret"></div>
42+
<div class="fcitx-post-caret"></div>
43+
</div>
4044
</div>
4145
<div class="fcitx-aux-down fcitx-hidden"></div>
4246
<div class="fcitx-hoverables fcitx-horizontal"></div>

page/panel.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3439
export 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

227259
export function hidePanel() {
228-
updateInputPanel('', '', '')
260+
updateInputPanel([], false, [], [], [])
229261
setCandidates([], -1, false, false, false, SCROLL_NONE, false, false)
230262
theme.classList.add('fcitx-hidden')
231263
}

pugixml

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)