Skip to content

Commit 475c7a4

Browse files
authored
fix caret typo and add more configurations (#271)
1 parent 184942e commit 475c7a4

File tree

8 files changed

+164
-143
lines changed

8 files changed

+164
-143
lines changed

assets/po/zh_CN.po

Lines changed: 100 additions & 92 deletions
Large diffs are not rendered by default.

macosfrontend/macosfrontend.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,14 @@ void MacosInputContext::updatePreeditImpl() {
271271
auto preedit =
272272
frontend_->instance()->outputFilter(this, inputPanel().clientPreedit());
273273
state_.preedit = preedit.toString();
274-
state_.cursorPos = preedit.cursor();
274+
state_.caretPos = preedit.cursor();
275275
}
276276

277277
std::string MacosInputContext::getState(bool accepted) {
278278
nlohmann::json j;
279279
j["commit"] = state_.commit;
280280
j["preedit"] = state_.preedit;
281-
j["cursorPos"] = state_.cursorPos;
281+
j["caretPos"] = state_.caretPos;
282282
j["dummyPreedit"] = state_.dummyPreedit;
283283
j["accepted"] = accepted;
284284
return j.dump();
@@ -288,17 +288,17 @@ void MacosInputContext::commitAndSetPreeditAsync() {
288288
auto state = state_;
289289
resetState();
290290
SwiftFrontend::commitAndSetPreeditAsync(client_, state.commit,
291-
state.preedit, state.cursorPos,
291+
state.preedit, state.caretPos,
292292
state.dummyPreedit);
293293
}
294294

295295
std::tuple<double, double, double>
296-
MacosInputContext::getCursorCoordinates(bool followCursor) {
296+
MacosInputContext::getCaretCoordinates(bool followCaret) {
297297
// Memorize to avoid jumping to origin on failure.
298298
static double x = 0, y = 0, height = 0;
299-
if (!SwiftFrontend::getCursorCoordinates(client_, followCursor, &x, &y,
300-
&height)) {
301-
FCITX_DEBUG() << "Failed to get cursor coordinates";
299+
if (!SwiftFrontend::getCaretCoordinates(client_, followCaret, &x, &y,
300+
&height)) {
301+
FCITX_DEBUG() << "Failed to get caret coordinates";
302302
}
303303
return std::make_tuple(x, y, height);
304304
}

macosfrontend/macosfrontend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class MacosFrontend : public AddonInstance {
109109
struct InputContextState {
110110
std::string commit;
111111
std::string preedit;
112-
int cursorPos;
112+
int caretPos;
113113
bool dummyPreedit;
114114
};
115115

@@ -127,7 +127,7 @@ class MacosInputContext : public InputContext {
127127
void forwardKeyImpl(const ForwardKeyEvent &key) override {}
128128
void updatePreeditImpl() override;
129129

130-
std::tuple<double, double, double> getCursorCoordinates(bool followCursor);
130+
std::tuple<double, double, double> getCaretCoordinates(bool followCaret);
131131
id client() { return client_; }
132132
std::string getAccentColor() { return accentColor_; }
133133

macosfrontend/macosfrontend.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ private var currentPreedit = ""
66

77
private let zeroWidthSpace = "\u{200B}"
88

9-
public var hasCursor = false
9+
public var hasCaret = false
1010

1111
private var controller: IMKInputController? = nil
1212

@@ -57,41 +57,41 @@ private func setPreedit(_ client: IMKTextInput, _ preedit: String, _ caretPosUtf
5757
}
5858

5959
public func commitAndSetPreeditSync(
60-
_ client: IMKTextInput, _ commit: String, _ preedit: String, _ cursorPos: Int,
60+
_ client: IMKTextInput, _ commit: String, _ preedit: String, _ caretPos: Int,
6161
_ dummyPreedit: Bool, focusOut: Bool = false
6262
) {
6363
if !commit.isEmpty {
6464
commitString(client, commit)
6565
}
6666
// Setting preedit on focus out may cause IMK stall for seconds. High possibility
67-
// to reproduce by having no cursor on a Safari page and Cmd+T to open a new Tab.
68-
if focusOut && !hasCursor {
67+
// to reproduce by having no caret on a Safari page and Cmd+T to open a new Tab.
68+
if focusOut && !hasCaret {
6969
return
7070
}
7171
// Without client preedit, Backspace bypasses IM in Terminal, every key
7272
// is both processed by IM and passed to client in iTerm, so we force a
7373
// dummy client preedit here.
74-
// Some apps also need it to get accurate cursor position to place candidate window.
74+
// Some apps also need it to get accurate caret position to place candidate window.
7575
// This is fine even when there is selected text. In Word, not using dummy preedit to
7676
// replace selected text will let Esc bypass IM. When using Shift+click to select, if
7777
// interval is too little, IM switch happens, but dummyPreedit is false in that case.
7878
if preedit.isEmpty && dummyPreedit {
7979
setPreedit(client, zeroWidthSpace, 0)
8080
} else {
81-
setPreedit(client, preedit, cursorPos)
81+
setPreedit(client, preedit, caretPos)
8282
}
8383
}
8484

8585
public func commitAndSetPreeditAsync(
86-
_ clientPtr: UnsafeMutableRawPointer, _ commit: String, _ preedit: String, _ cursorPos: Int,
86+
_ clientPtr: UnsafeMutableRawPointer, _ commit: String, _ preedit: String, _ caretPos: Int,
8787
_ dummyPreedit: Bool
8888
) {
8989
let client: AnyObject = Unmanaged.fromOpaque(clientPtr).takeUnretainedValue()
9090
guard let client = client as? IMKTextInput else {
9191
return
9292
}
9393
DispatchQueue.main.async {
94-
commitAndSetPreeditSync(client, commit, preedit, cursorPos, dummyPreedit)
94+
commitAndSetPreeditSync(client, commit, preedit, caretPos, dummyPreedit)
9595
}
9696
}
9797

@@ -105,9 +105,9 @@ public func commitAsync(_ clientPtr: UnsafeMutableRawPointer, _ commit: String)
105105
}
106106
}
107107

108-
public func getCursorCoordinates(
108+
public func getCaretCoordinates(
109109
_ clientPtr: UnsafeMutableRawPointer,
110-
_ followCursor: Bool,
110+
_ followCaret: Bool,
111111
_ x: UnsafeMutablePointer<Double>,
112112
_ y: UnsafeMutablePointer<Double>,
113113
_ height: UnsafeMutablePointer<Double>
@@ -117,22 +117,22 @@ public func getCursorCoordinates(
117117
return false
118118
}
119119
var rect = NSRect(x: 0, y: 0, width: 0, height: 0)
120-
// n characters have n+1 cursor positions, but character index only accepts 0 to n-1,
121-
// and passing n results in (0,0). So if cursor is in the end, go back and add 10px
120+
// n characters have n+1 caret positions, but character index only accepts 0 to n-1,
121+
// and passing n results in (0,0). So if caret is in the end, go back and add 10px
122122
let isEnd = u16pos == currentPreedit.count
123123
client.attributes(
124-
forCharacterIndex: followCursor ? (isEnd ? u16pos - 1 : u16pos) : 0,
124+
forCharacterIndex: followCaret ? (isEnd ? u16pos - 1 : u16pos) : 0,
125125
lineHeightRectangle: &rect)
126126
if rect.width == 0 && rect.height == 0 {
127-
hasCursor = false
127+
hasCaret = false
128128
return false
129129
}
130130
x.pointee = Double(NSMinX(rect))
131131
y.pointee = Double(NSMinY(rect))
132132
height.pointee = Double(rect.height)
133-
if followCursor && isEnd {
133+
if followCaret && isEnd {
134134
x.pointee += 10
135135
}
136-
hasCursor = true
136+
hasCaret = true
137137
return true
138138
}

src/controller.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import SwiftyJSON
88
struct SyncResponse: Codable {
99
let commit: String
1010
let preedit: String
11-
let cursorPos: Int
11+
let caretPos: Int
1212
let dummyPreedit: Bool
1313
let accepted: Bool
1414
}
@@ -66,7 +66,7 @@ class FcitxInputController: IMKInputController {
6666
return false
6767
}
6868
commitAndSetPreeditSync(
69-
client, response.commit, response.preedit, response.cursorPos, response.dummyPreedit,
69+
client, response.commit, response.preedit, response.caretPos, response.dummyPreedit,
7070
focusOut: focusOut)
7171
return response.accepted
7272
}
@@ -177,7 +177,7 @@ class FcitxInputController: IMKInputController {
177177
client.overrideKeyboard(withKeyboardNamed: "com.apple.keylayout.ABC")
178178
}
179179
// activateServer is called when app is in foreground but not necessarily a text field is selected.
180-
hasCursor = false
180+
hasCaret = false
181181
// Make sure status bar is updated on click password input, before first key event.
182182
let isPassword = getSecureInputInfo(isOnFocus: true)
183183
focus_in(uuid, isPassword)
@@ -190,7 +190,7 @@ class FcitxInputController: IMKInputController {
190190
let res = String(focus_out(uuid))
191191
// Maybe commit and clear preedit synchronously if user switches to ABC by Ctrl+Space.
192192
let _ = processRes(client, res, focusOut: true)
193-
hasCursor = false
193+
hasCaret = false
194194
}
195195

196196
override func menu() -> NSMenu! {

webpanel/webpanel.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ WebPanel::WebPanel(Instance *instance)
253253
void WebPanel::updateConfig() {
254254
window_->set_layout(config_.typography->layout.value());
255255
window_->set_theme(config_.basic->theme.value());
256-
window_->set_cursor_text(config_.cursor->style.value() == CursorStyle::Text
257-
? config_.cursor->text.value()
258-
: "");
256+
window_->set_caret_text(config_.caret->style.value() == CaretStyle::Text
257+
? config_.caret->text.value()
258+
: "");
259259
window_->set_highlight_mark_text(config_.highlight->markStyle.value() ==
260260
HighlightMarkStyle::Text
261261
? config_.highlight->markText.value()
@@ -351,7 +351,7 @@ void WebPanel::update(UserInterfaceComponent component,
351351
(writingMode ==
352352
candidate_window::writing_mode_t::vertical_lr);
353353
} else {
354-
// Allow -> to move cursor on horizontal+horizontal_tb.
354+
// Allow -> to move highlight on horizontal+horizontal_tb.
355355
f5m_is_linear_layout = false;
356356
f5m_is_vertical_rl = false;
357357
f5m_is_vertical_lr = false;
@@ -481,8 +481,8 @@ void WebPanel::showAsync(bool show) {
481481
// MacosInputContext::updatePreeditImpl is executed before
482482
// WebPanel::update, so in main thread preedit UI update
483483
// happens before here.
484-
auto [x, y, height] = ic->getCursorCoordinates(
485-
config_.basic->followCursor.value());
484+
auto [x, y, height] = ic->getCaretCoordinates(
485+
config_.basic->followCaret.value());
486486
window->show(x, y, height);
487487
}
488488
} else {

webpanel/webpanel.h

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ enum class PagingButtonsStyle { None, Arrow, Triangle };
2525
FCITX_CONFIG_ENUM_NAME_WITH_I18N(PagingButtonsStyle, N_("None"), N_("Arrow"),
2626
N_("Triangle"))
2727

28-
enum class CursorStyle { Blink, Static, Text };
29-
FCITX_CONFIG_ENUM_NAME_WITH_I18N(CursorStyle, N_("Blink"), N_("Static"),
28+
enum class CaretStyle { Blink, Static, Text };
29+
FCITX_CONFIG_ENUM_NAME_WITH_I18N(CaretStyle, N_("Blink"), N_("Static"),
3030
N_("Text"))
3131

3232
enum class HighlightMarkStyle { None, Bar, Text };
@@ -77,7 +77,7 @@ struct PluginAnnotation {
7777

7878
FCITX_CONFIGURATION(
7979
BasicConfig,
80-
Option<bool> followCursor{this, "FollowCursor", _("Follow cursor"), false};
80+
Option<bool> followCaret{this, "FollowCaret", _("Follow caret"), false};
8181
OptionWithAnnotation<candidate_window::theme_t,
8282
candidate_window::theme_tI18NAnnotation>
8383
theme{this, "Theme", _("Theme"), candidate_window::theme_t::system};
@@ -123,10 +123,16 @@ FCITX_CONFIGURATION(
123123
Option<Color> disabledPagingButtonColor{this, "DisabledPagingButtonColor",
124124
_("Disabled paging button color"),
125125
Color(127, 127, 127, 255)};
126-
Option<Color> preeditColor{this, "PreeditColor", _("Preedit color"),
127-
Color(0, 0, 0, 255)};
128-
Option<Color> preeditColorPreCursor{this, "PreeditColorPreCursor",
129-
_("Preedit color pre-cursor"),
126+
Option<Color> auxColor{this, "AuxColor", _("Indicator text color"),
127+
Color(0, 0, 0, 255)};
128+
Option<Color> preeditColorPreCaret{this, "PreeditColorPreCaret",
129+
_("Preedit color pre-caret"),
130+
Color(0, 0, 0, 255)};
131+
Option<Color> preeditColorCaret{this, "PreeditColorCaret",
132+
_("Preedit caret color"),
133+
Color(0, 0, 0, 255)};
134+
Option<Color> preeditColorPostCaret{this, "PreeditColorPostCaret",
135+
_("Preedit color post-caret"),
130136
Color(0, 0, 0, 255)};
131137
Option<Color> borderColor{this, "BorderColor", _("Border color"),
132138
Color(0, 0, 0, 255)};
@@ -172,10 +178,17 @@ FCITX_CONFIGURATION(
172178
Option<Color> disabledPagingButtonColor{this, "DisabledPagingButtonColor",
173179
_("Disabled paging button color"),
174180
Color(127, 127, 127, 255)};
175-
Option<Color> preeditColor{this, "PreeditColor", _("Preedit color"),
176-
Color(255, 255, 255, 255)};
177-
Option<Color> preeditColorPreCursor{this, "PreeditColorPreCursor",
178-
_("Preedit color pre-cursor"),
181+
182+
Option<Color> auxColor{this, "AuxColor", _("Indicator text color"),
183+
Color(255, 255, 255, 255)};
184+
Option<Color> preeditColorPreCaret{this, "PreeditColorPreCaret",
185+
_("Preedit color pre-caret"),
186+
Color(255, 255, 255, 255)};
187+
Option<Color> preeditColorCaret{this, "PreeditColorCaret",
188+
_("Preedit caret color"),
189+
Color(255, 255, 255, 255)};
190+
Option<Color> preeditColorPostCaret{this, "PreeditColorPostCaret",
191+
_("Preedit color post-caret"),
179192
Color(255, 255, 255, 255)};
180193
Option<Color> borderColor{this, "BorderColor", _("Border color"),
181194
Color(255, 255, 255, 255)};
@@ -267,9 +280,9 @@ FCITX_CONFIGURATION(
267280
ExternalOption systemFontDir{this, "SystemFontDir", _("System font dir"),
268281
""};);
269282

270-
FCITX_CONFIGURATION(CursorConfig,
271-
OptionWithAnnotation<CursorStyle, CursorStyleI18NAnnotation>
272-
style{this, "Style", _("Style"), CursorStyle::Blink};
283+
FCITX_CONFIGURATION(CaretConfig,
284+
OptionWithAnnotation<CaretStyle, CaretStyleI18NAnnotation>
285+
style{this, "Style", _("Style"), CaretStyle::Blink};
273286
Option<std::string> text{this, "Text", _("Text"), ""};);
274287

275288
FCITX_CONFIGURATION(
@@ -337,7 +350,7 @@ FCITX_CONFIGURATION(
337350
Option<ScrollConfig> scrollMode{this, "ScrollMode", _("Scroll mode")};
338351
Option<BackgroundConfig> background{this, "Background", _("Background")};
339352
Option<FontConfig> font{this, "Font", _("Font")};
340-
Option<CursorConfig> cursor{this, "Cursor", _("Cursor")};
353+
Option<CaretConfig> caret{this, "Caret", _("Caret")};
341354
Option<HighlightConfig> highlight{this, "Highlight", _("Highlight")};
342355
Option<Size> size{this, "Size", _("Size")};
343356
Option<Advanced> advanced{this, "Advanced", _("Advanced")};);

0 commit comments

Comments
 (0)