Skip to content

Commit

Permalink
[linux] Fix text selection via Shift+Home/End (flutter#24623)
Browse files Browse the repository at this point in the history
Adds TextInputModel::SelectToBeginning/End() and applies when shift key is pressed.
  • Loading branch information
jpnurmi authored Mar 5, 2021
1 parent 2b47c37 commit 8c25ca1
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 2 deletions.
18 changes: 18 additions & 0 deletions shell/platform/common/text_input_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,24 @@ bool TextInputModel::MoveCursorToEnd() {
return true;
}

bool TextInputModel::SelectToBeginning() {
size_t min_pos = editable_range().start();
if (selection_.collapsed() && selection_.position() == min_pos) {
return false;
}
selection_ = TextRange(selection_.base(), min_pos);
return true;
}

bool TextInputModel::SelectToEnd() {
size_t max_pos = editable_range().end();
if (selection_.collapsed() && selection_.position() == max_pos) {
return false;
}
selection_ = TextRange(selection_.base(), max_pos);
return true;
}

bool TextInputModel::MoveCursorForward() {
// If there's a selection, move to the end of the selection.
if (!selection_.collapsed()) {
Expand Down
16 changes: 16 additions & 0 deletions shell/platform/common/text_input_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ class TextInputModel {
// Returns true if the cursor could be moved.
bool MoveCursorToEnd();

// Attempts to select text from the cursor position to the beginning.
//
// If composing is active, the selection is applied to the beginning of the
// composing range; otherwise, it is applied to the beginning of the text.
//
// Returns true if the selection could be applied.
bool SelectToBeginning();

// Attempts to select text from the cursor position to the end.
//
// If composing is active, the selection is applied to the end of the
// composing range; otherwise, it is moved to the end of the text.
//
// Returns true if the selection could be applied.
bool SelectToEnd();

// Gets the current text as UTF-8.
std::string GetText() const;

Expand Down
Loading

0 comments on commit 8c25ca1

Please sign in to comment.