Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Fixes #2430 Fix url bar bidirectional selection #3458

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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