From a3fdad8ab096f2f1220a8c2f589a4f67a390b3d1 Mon Sep 17 00:00:00 2001 From: Chen Gong Date: Sat, 15 Jan 2022 10:30:21 +0800 Subject: [PATCH] fix(editor): `back_syllable` should reopen selected words --- src/rime/gear/editor.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rime/gear/editor.cc b/src/rime/gear/editor.cc index 27e0e276b..ca0612b44 100644 --- a/src/rime/gear/editor.cc +++ b/src/rime/gear/editor.cc @@ -133,20 +133,26 @@ void Editor::BackToPreviousInput(Context* ctx) { ctx->PopInput(); } -void Editor::BackToPreviousSyllable(Context* ctx) { +static bool pop_input_by_syllable(Context* ctx) { size_t caret_pos = ctx->caret_pos(); if (caret_pos == 0) - return; + return false; if (auto cand = ctx->GetSelectedCandidate()) { if (auto phrase = As(Candidate::GetGenuineCandidate(cand))) { size_t stop = phrase->spans().PreviousStop(caret_pos); if (stop != caret_pos) { ctx->PopInput(caret_pos - stop); - return; + return true; } } } - ctx->PopInput(); + return false; +} + +void Editor::BackToPreviousSyllable(Context* ctx) { + ctx->ReopenPreviousSelection() || + ((pop_input_by_syllable(ctx) || ctx->PopInput()) && + ctx->ReopenPreviousSegment()); } void Editor::DeleteCandidate(Context* ctx) {