Commit 450764e5 authored by Daisuke Akatsuka's avatar Daisuke Akatsuka
Browse files

Bug 1826184: Show go-button even if pasting multiline text on urlbar r=adw

The direct reason why the go-button was hidden when pasting text is that
"usertyping" attribute will not be true.
https://searchfox.org/mozilla-central/rev/8433b62e54fd30663e82f090c4d31554531a2e66/browser/base/content/browser.css#754
When pasting data and removing white space or line break, call preventDefault().
https://searchfox.org/mozilla-central/rev/8433b62e54fd30663e82f090c4d31554531a2e66/browser/components/urlbar/UrlbarInput.sys.mjs#3504-3505
The other hand, if not removing any chars, _on_input() will be called because
don't call preventDefault(). And, the attribute is set in _on_input().
https://searchfox.org/mozilla-central/rev/8433b62e54fd30663e82f090c4d31554531a2e66/browser/components/urlbar/UrlbarInput.sys.mjs#3343

So, we set the attribute even if pasting data is changed as same as _on_input().

Differential Revision: https://phabricator.services.mozilla.com/D174576
parent 68d2df6f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3507,6 +3507,12 @@ export class UrlbarInput {
      this.inputField.value = oldStart + pasteData + oldEnd;
      this._untrimmedValue = this.inputField.value;

      if (this._untrimmedValue) {
        this.setAttribute("usertyping", "true");
      } else {
        this.removeAttribute("usertyping");
      }

      // Fix up cursor/selection:
      let newCursorPos = oldStart.length + pasteData.length;
      this.inputField.setSelectionRange(newCursorPos, newCursorPos);
+16 −0
Original line number Diff line number Diff line
@@ -126,6 +126,14 @@ const TEST_DATA = [
      type: UrlbarUtils.RESULT_TYPE.URL,
    },
  },
  {
    input: "\r\n\r\n\r\n\r\n\r\n",
    expected: {
      urlbar: "",
      autocomplete: "",
      type: UrlbarUtils.RESULT_TYPE.SEARCH,
    },
  },
];

add_setup(async function() {
@@ -186,6 +194,14 @@ async function assertResult(expected) {
    "Title of autocomplete is correct"
  );
  Assert.equal(result.type, expected.type, "Type of autocomplete is correct");

  if (gURLBar.value) {
    Assert.equal(gURLBar.getAttribute("usertyping"), "true");
    Assert.ok(BrowserTestUtils.is_visible(gURLBar.goButton));
  } else {
    Assert.ok(!gURLBar.hasAttribute("usertyping"));
    Assert.ok(BrowserTestUtils.is_hidden(gURLBar.goButton));
  }
}

async function paste(input) {