Skip to content

Commit 424d198

Browse files
authored
Remove the TextEditingContext (#284)
* it was a workaround used when the Input method implementation was incomplete. Signed-off-by: Boram Bae <[email protected]>
1 parent c473d61 commit 424d198

File tree

2 files changed

+16
-39
lines changed

2 files changed

+16
-39
lines changed

shell/platform/tizen/channels/text_input_channel.cc

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ TextInputChannel::TextInputChannel(
6565
// Set input method callbacks.
6666
input_method_context_->SetOnPreeditStart([this]() {
6767
FT_LOG(Debug) << "onPreeditStart";
68-
text_editing_context_.edit_status_ = EditStatus::kPreeditStart;
6968
active_model_->BeginComposing();
7069
});
7170

@@ -82,7 +81,6 @@ TextInputChannel::TextInputChannel(
8281
});
8382

8483
input_method_context_->SetOnPreeditEnd([this]() {
85-
text_editing_context_.edit_status_ = EditStatus::kPreeditEnd;
8684
FT_LOG(Debug) << "onPreeditEnd";
8785

8886
// Delete preedit-string, it will be committed.
@@ -99,7 +97,6 @@ TextInputChannel::TextInputChannel(
9997

10098
input_method_context_->SetOnCommit([this](std::string str) -> void {
10199
FT_LOG(Debug) << "OnCommit: str[" << str << "]";
102-
text_editing_context_.edit_status_ = EditStatus::kCommit;
103100
active_model_->AddText(str);
104101
if (active_model_->composing()) {
105102
active_model_->CommitComposing();
@@ -112,8 +109,7 @@ TextInputChannel::TextInputChannel(
112109
if (state == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
113110
// Fallback for HW back-key.
114111
input_method_context_->HideInputPanel();
115-
input_method_context_->ResetInputMethodContext();
116-
ResetTextEditingContext();
112+
Reset();
117113
is_software_keyboard_showing_ = false;
118114
} else {
119115
is_software_keyboard_showing_ = true;
@@ -145,8 +141,7 @@ void TextInputChannel::HandleMethodCall(
145141
input_method_context_->ShowInputPanel();
146142
} else if (method.compare(kHideMethod) == 0) {
147143
input_method_context_->HideInputPanel();
148-
input_method_context_->ResetInputMethodContext();
149-
ResetTextEditingContext();
144+
Reset();
150145
} else if (method.compare(kSetPlatformViewClient) == 0) {
151146
result->NotImplemented();
152147
return;
@@ -215,9 +210,7 @@ void TextInputChannel::HandleMethodCall(
215210

216211
active_model_ = std::make_unique<TextInputModel>();
217212
} else if (method.compare(kSetEditingStateMethod) == 0) {
218-
input_method_context_->ResetInputMethodContext();
219-
ResetTextEditingContext();
220-
213+
Reset();
221214
if (!method_call.arguments() || method_call.arguments()->IsNull()) {
222215
result->Error(kBadArgumentError, "Method invoked without args.");
223216
return;
@@ -322,7 +315,7 @@ bool TextInputChannel::FilterEvent(Ecore_Event_Key* event, bool is_down) {
322315
bool is_ime = true;
323316
// FIXME: Only for wearable.
324317
if (is_ime && strcmp(event->key, "Select") == 0) {
325-
text_editing_context_.is_in_select_mode_ = true;
318+
is_in_select_mode_ = true;
326319
FT_LOG(Debug) << "Entering select mode.";
327320
}
328321
#else
@@ -331,19 +324,17 @@ bool TextInputChannel::FilterEvent(Ecore_Event_Key* event, bool is_down) {
331324
#endif
332325

333326
if (ShouldNotFilterEvent(event->key, is_ime)) {
334-
ResetTextEditingContext();
335-
input_method_context_->ResetInputMethodContext();
336327
FT_LOG(Info) << "Force redirect an IME key event: " << event->keyname;
328+
Reset();
337329
return false;
338330
}
339331

340332
handled =
341333
input_method_context_->FilterEvent(event, is_ime ? "ime" : "", is_down);
342334

343335
#ifdef WEARABLE_PROFILE
344-
if (!handled && !strcmp(event->key, "Return") &&
345-
text_editing_context_.is_in_select_mode_) {
346-
text_editing_context_.is_in_select_mode_ = false;
336+
if (!handled && !strcmp(event->key, "Return") && is_in_select_mode_) {
337+
is_in_select_mode_ = false;
347338
handled = true;
348339
FT_LOG(Debug) << "Leaving select mode.";
349340
}
@@ -353,15 +344,6 @@ bool TextInputChannel::FilterEvent(Ecore_Event_Key* event, bool is_down) {
353344
}
354345

355346
void TextInputChannel::HandleUnfilteredEvent(Ecore_Event_Key* event) {
356-
text_editing_context_.edit_status_ = EditStatus::kNone;
357-
#ifdef MOBILE_PROFILE
358-
// FIXME: Only for mobile.
359-
if (text_editing_context_.edit_status_ == EditStatus::kPreeditEnd) {
360-
FT_LOG(Debug) << "Ignore a key event: " << event->keyname;
361-
ResetTextEditingContext();
362-
return;
363-
}
364-
#endif
365347
bool select = !strcmp(event->key, "Select");
366348
bool shift = event->modifiers & ECORE_SHIFT;
367349
bool needs_update = false;
@@ -403,8 +385,7 @@ void TextInputChannel::HandleUnfilteredEvent(Ecore_Event_Key* event) {
403385
IsAsciiPrintableKey(event->string[0])) {
404386
active_model_->AddCodePoint(event->string[0]);
405387
needs_update = true;
406-
} else if (key == "Return" ||
407-
(select && !text_editing_context_.is_in_select_mode_)) {
388+
} else if (key == "Return" || (select && !is_in_select_mode_)) {
408389
EnterPressed(active_model_.get(), select);
409390
return;
410391
} else {
@@ -429,13 +410,18 @@ void TextInputChannel::EnterPressed(TextInputModel* model, bool select) {
429410
channel_->InvokeMethod(kPerformActionMethod, std::move(args));
430411
}
431412

413+
void TextInputChannel::Reset() {
414+
is_in_select_mode_ = false;
415+
input_method_context_->ResetInputMethodContext();
416+
}
417+
432418
bool TextInputChannel::ShouldNotFilterEvent(std::string key, bool is_ime) {
433419
// Force redirect to HandleUnfilteredEvent(especially on TV)
434420
// If you don't do this, it will affects the input panel.
435421
// For example, when the left key of the input panel is pressed, the focus
436422
// of the input panel is shifted to left!
437423
// What we want is to move only the cursor on the text editor.
438-
if (is_ime && !text_editing_context_.is_in_select_mode_ &&
424+
if (is_ime && !is_in_select_mode_ &&
439425
(key == "Left" || key == "Right" || key == "Up" || key == "Down" ||
440426
key == "End" || key == "Home" || key == "BackSpace" || key == "Delete" ||
441427
key == "Select")) {

shell/platform/tizen/channels/text_input_channel.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020

2121
namespace flutter {
2222

23-
enum class EditStatus { kNone, kPreeditStart, kPreeditEnd, kCommit };
24-
25-
struct TextEditingContext {
26-
EditStatus edit_status_ = EditStatus::kNone;
27-
bool is_in_select_mode_ = false;
28-
};
29-
3023
class TextInputChannel {
3124
public:
3225
explicit TextInputChannel(
@@ -46,9 +39,7 @@ class TextInputChannel {
4639
bool FilterEvent(Ecore_Event_Key* event, bool is_down);
4740
void HandleUnfilteredEvent(Ecore_Event_Key* event);
4841
void EnterPressed(TextInputModel* model, bool select);
49-
void ResetTextEditingContext() {
50-
text_editing_context_ = TextEditingContext();
51-
}
42+
void Reset();
5243
bool ShouldNotFilterEvent(std::string key, bool is_ime);
5344

5445
std::unique_ptr<MethodChannel<rapidjson::Document>> channel_;
@@ -59,7 +50,7 @@ class TextInputChannel {
5950
bool is_software_keyboard_showing_ = false;
6051
std::string input_action_;
6152
std::string input_type_;
62-
TextEditingContext text_editing_context_;
53+
bool is_in_select_mode_ = false;
6354
};
6455

6556
} // namespace flutter

0 commit comments

Comments
 (0)