Skip to content

Commit

Permalink
fix(chord_composer): allow editor to define BackSpace key behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Feb 19, 2017
1 parent 2ab76bc commit 7f41f65
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions src/rime/gear/chord_composer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,7 @@ ProcessResult ChordComposer::ProcessFunctionKey(const KeyEvent& key_event) {
raw_sequence_.clear();
}
ClearChord();
} else if (ch == XK_BackSpace) {
// invalidate raw sequence
raw_sequence_.clear();
ClearChord();
if (DeleteLastSyllable()) {
return kAccepted;
}
} else if (ch == XK_Escape) {
} else if (ch == XK_BackSpace || ch == XK_Escape) {
// clear the raw sequence
raw_sequence_.clear();
ClearChord();
Expand Down Expand Up @@ -195,26 +188,6 @@ void ChordComposer::ClearChord() {
}
}

bool ChordComposer::DeleteLastSyllable() {
if (!engine_)
return false;
Context* ctx = engine_->context();
Composition& comp = ctx->composition();
const string& input(ctx->input());
size_t start = comp.empty() ? 0 : comp.back().start;
size_t caret_pos = ctx->caret_pos();
if (input.empty() || caret_pos <= start)
return false;
size_t deleted = 0;
for (; caret_pos > start; --caret_pos, ++deleted) {
if (deleted > 0 &&
delimiter_.find(input[caret_pos - 1]) != string::npos)
break;
}
ctx->PopInput(deleted);
return true;
}

void ChordComposer::OnContextUpdate(Context* ctx) {
if (ctx->IsComposing() && ctx->input() != kZeroWidthSpace) {
composing_ = true;
Expand Down

0 comments on commit 7f41f65

Please sign in to comment.