Skip to content

Commit 0ec7a2d

Browse files
committed
fix(chord_composer): invisible placeholder char prepended to output
1 parent 8e2826a commit 0ec7a2d

1 file changed

Lines changed: 5 additions & 16 deletions

File tree

src/rime/gear/chord_composer.cc

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <rime/schema.h>
1414
#include <rime/gear/chord_composer.h>
1515

16-
static const char* kZeroWidthSpace = "\xe2\x80\x8b"; // U+200B
17-
1816
namespace rime {
1917

2018
ChordComposer::ChordComposer(const Ticket& ticket) : Processor(ticket) {
@@ -108,8 +106,7 @@ ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
108106
if (pressed_.erase(ch) != 0 && pressed_.empty()) {
109107
FinishChord();
110108
}
111-
}
112-
else { // key down
109+
} else { // key down
113110
pressed_.insert(ch);
114111
bool updated = chord_.insert(ch).second;
115112
if (updated)
@@ -119,11 +116,6 @@ ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
119116
return kAccepted;
120117
}
121118

122-
inline static bool is_composing(Context* ctx) {
123-
return !ctx->composition().empty() &&
124-
!ctx->composition().back().HasTag("phony");
125-
}
126-
127119
ProcessResult ChordComposer::ProcessKeyEvent(const KeyEvent& key_event) {
128120
if (engine_->context()->get_option("ascii_mode")) {
129121
return kNoop;
@@ -135,7 +127,7 @@ ProcessResult ChordComposer::ProcessKeyEvent(const KeyEvent& key_event) {
135127
int ch = key_event.keycode();
136128
if (!is_key_up && ch >= 0x20 && ch <= 0x7e) {
137129
// save raw input
138-
if (!is_composing(engine_->context()) || !raw_sequence_.empty()) {
130+
if (engine_->context()->IsComposing() || !raw_sequence_.empty()) {
139131
raw_sequence_.push_back(ch);
140132
DLOG(INFO) << "update raw sequence: " << raw_sequence_;
141133
}
@@ -169,7 +161,6 @@ void ChordComposer::UpdateChord() {
169161
// add a placeholder segment
170162
// 1. to cheat ctx->IsComposing() == true
171163
// 2. to attach chord prompt to while chording
172-
ctx->set_input(kZeroWidthSpace);
173164
Segment placeholder(0, ctx->input().length());
174165
placeholder.tags.insert("phony");
175166
ctx->composition().AddSegment(placeholder);
@@ -213,18 +204,16 @@ void ChordComposer::ClearChord() {
213204
auto& last_segment = comp.back();
214205
if (comp.size() == 1 && last_segment.HasTag("phony")) {
215206
ctx->Clear();
216-
}
217-
else if (last_segment.HasTag("chord_prompt")) {
207+
} else if (last_segment.HasTag("chord_prompt")) {
218208
last_segment.prompt.clear();
219209
last_segment.tags.erase("chord_prompt");
220210
}
221211
}
222212

223213
void ChordComposer::OnContextUpdate(Context* ctx) {
224-
if (is_composing(ctx)) {
214+
if (ctx->IsComposing()) {
225215
composing_ = true;
226-
}
227-
else if (composing_) {
216+
} else if (composing_) {
228217
composing_ = false;
229218
if (!editing_chord_ || sending_chord_) {
230219
raw_sequence_.clear();

0 commit comments

Comments
 (0)