Skip to content

Commit

Permalink
Hopefully fix input text selection quirks on iOS (mastodon#10463)
Browse files Browse the repository at this point in the history
Fix mastodon#10448 (hopefully)
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent 73f0920 commit a994435
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/javascript/packs/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,20 @@ function main() {
});

delegate(document, '.input-copy input', 'click', ({ target }) => {
target.focus();
target.select();
target.setSelectionRange(0, target.value.length);
});

delegate(document, '.input-copy button', 'click', ({ target }) => {
const input = target.parentNode.querySelector('.input-copy__wrapper input');

const oldReadOnly = input.readonly;

input.readonly = false;
input.focus();
input.select();
input.setSelectionRange(0, input.value.length);

try {
if (document.execCommand('copy')) {
Expand All @@ -213,6 +219,8 @@ function main() {
} catch (err) {
console.error(err);
}

input.readonly = oldReadOnly;
});
}

Expand Down

0 comments on commit a994435

Please sign in to comment.