Fix invalid selection handling in text plugins (flutter/engine#19899)
The Windows, Linux, and GLFW embeddings (which all share a common code ancestry) pass TextInput.setEditingState selection base and extents straight through to the shared text model class. The model expects those values to be valid, but the framework sends -1/-1 for "invalid" selections, which happen for some empty text cases (e.g., TextFieldController.clear()). This translates those invalid selection values to an empty selection at the start of the string, as expected by the model. Fixes https://github.com/flutter/flutter/issues/59140
This commit is contained in:
@@ -187,9 +187,13 @@ void TextInputPlugin::HandleMethodCall(
|
||||
"Selection base/extent values invalid.");
|
||||
return;
|
||||
}
|
||||
active_model_->SetEditingState(selection_base->value.GetInt(),
|
||||
selection_extent->value.GetInt(),
|
||||
text->value.GetString());
|
||||
// Flutter uses -1/-1 for invalid; translate that to 0/0 for the model.
|
||||
int base = selection_base->value.GetInt();
|
||||
int extent = selection_extent->value.GetInt();
|
||||
if (base == -1 && extent == -1) {
|
||||
base = extent = 0;
|
||||
}
|
||||
active_model_->SetEditingState(base, extent, text->value.GetString());
|
||||
} else {
|
||||
result->NotImplemented();
|
||||
return;
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
#include "flutter/shell/platform/linux/fl_text_input_plugin.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "flutter/shell/platform/common/cpp/text_input_model.h"
|
||||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h"
|
||||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static constexpr char kChannelName[] = "flutter/textinput";
|
||||
|
||||
static constexpr char kBadArgumentsError[] = "Bad Arguments";
|
||||
@@ -190,6 +190,10 @@ static FlMethodResponse* set_editing_state(FlTextInputPlugin* self,
|
||||
fl_value_get_int(fl_value_lookup_string(args, kSelectionBaseKey));
|
||||
int64_t selection_extent =
|
||||
fl_value_get_int(fl_value_lookup_string(args, kSelectionExtentKey));
|
||||
// Flutter uses -1/-1 for invalid; translate that to 0/0 for the model.
|
||||
if (selection_base == -1 && selection_extent == -1) {
|
||||
selection_base = selection_extent = 0;
|
||||
}
|
||||
|
||||
self->text_model->SetEditingState(selection_base, selection_extent, text);
|
||||
|
||||
|
||||
@@ -189,9 +189,13 @@ void TextInputPlugin::HandleMethodCall(
|
||||
"Selection base/extent values invalid.");
|
||||
return;
|
||||
}
|
||||
active_model_->SetEditingState(selection_base->value.GetInt(),
|
||||
selection_extent->value.GetInt(),
|
||||
text->value.GetString());
|
||||
// Flutter uses -1/-1 for invalid; translate that to 0/0 for the model.
|
||||
int base = selection_base->value.GetInt();
|
||||
int extent = selection_extent->value.GetInt();
|
||||
if (base == -1 && extent == -1) {
|
||||
base = extent = 0;
|
||||
}
|
||||
active_model_->SetEditingState(base, extent, text->value.GetString());
|
||||
} else {
|
||||
result->NotImplemented();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user