Skip to content

Commit

Permalink
Fix url bar bidirectional selection (#3458)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jun 4, 2020
1 parent 1e0c49a commit 7c8a997
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void initialize(Context aContext) {
mBinding.urlEditText.setOnSelectionChangedCallback((start, end) -> {
if (mSelectionMenu != null) {
boolean hasCopy = mSelectionMenu.hasAction(GeckoSession.SelectionActionDelegate.ACTION_COPY);
boolean showCopy = end > start;
boolean showCopy = end != start;
if (hasCopy != showCopy) {
showSelectionMenu();

Expand All @@ -212,12 +212,6 @@ private void initialize(Context aContext) {
}
});

mBinding.urlEditText.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
if (mLongPressed) {
hideSelectionMenu();
}
});

// Set a filter to provide domain autocomplete results
mBinding.urlEditText.setOnFilterListener(this::domainAutocompleteFilter);

Expand Down Expand Up @@ -502,7 +496,7 @@ public boolean onDoubleTapEvent(MotionEvent motionEvent) {

private void showSelectionMenu() {
Collection<String> actions = new HashSet<>();
if (mBinding.urlEditText.getSelectionEnd() > mBinding.urlEditText.getSelectionStart()) {
if (mBinding.urlEditText.getSelectionEnd() != mBinding.urlEditText.getSelectionStart()) {
actions.add(GeckoSession.SelectionActionDelegate.ACTION_CUT);
actions.add(GeckoSession.SelectionActionDelegate.ACTION_COPY);
}
Expand Down Expand Up @@ -586,11 +580,13 @@ private float getSelectionCenterX() {
start = ViewUtils.GetLetterPositionX(mBinding.urlEditText, mBinding.urlEditText.getSelectionStart(), true);
}
float end = start;
if (mBinding.urlEditText.getSelectionEnd() > mBinding.urlEditText.getSelectionStart()) {
if (mBinding.urlEditText.getSelectionEnd() >= 0) {
end = ViewUtils.GetLetterPositionX(mBinding.urlEditText, mBinding.urlEditText.getSelectionEnd(), true);
}
if (end < start) {
float tmp = end;
end = start;
start = tmp;
}
return start + (end - start) * 0.5f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ public static void placeSelection(@NonNull EditText aView, int offset1, int offs
return;
}

int start = Math.min(offset1, offset2);
int end = Math.max(offset1, offset2);
aView.setSelection(start, end);
aView.setSelection(offset1, offset2);
}

static class StickyClickListener implements View.OnTouchListener {
Expand Down

0 comments on commit 7c8a997

Please sign in to comment.