Skip to content

refactor: remove uses of execCommand()#7246

Open
ElectricalBoy wants to merge 6 commits intomainfrom
js-impl-updates
Open

refactor: remove uses of execCommand()#7246
ElectricalBoy wants to merge 6 commits intomainfrom
js-impl-updates

Conversation

@ElectricalBoy
Copy link
Collaborator

Summary

This PR removes existing uses of Document.execCommand() (deprecated)

How did you test this change?

browser dev tools

@ElectricalBoy ElectricalBoy requested review from a team as code owners March 13, 2026 08:16
@ElectricalBoy ElectricalBoy added the javascript Changes to JavaScript files label Mar 13, 2026
Copy link
Collaborator

@hjpalpha hjpalpha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable on phone

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes “select all / copy to clipboard” behaviors by removing deprecated Document.execCommand() usage and switching to Selection + navigator.clipboard APIs in the commons JS utilities.

Changes:

  • Refactors Selectall to select text via DOM Ranges and copy via navigator.clipboard.writeText, along with updated wrapper/button styling.
  • Updates CopyToClipboard to use navigator.clipboard.writeText and error-notify when unsupported.
  • Adds types-mediawiki to devDependencies.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
stylesheets/commons/Selectall.scss Updates layout styles to match the new wrapper/button structure (removes textarea-overlay approach).
javascript/commons/Selectall.js Replaces textarea + execCommand('copy') flow with Range selection and Clipboard API copy.
javascript/commons/CopyToClipboard.js Removes execCommand fallback and relies on Clipboard API with user notification on lack of support.
package.json Adds types-mediawiki dev dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +24 to +30
createSelectButton() {
const selectButton = document.createElement( 'button' );
selectButton.classList.add( 'btn' );
selectButton.classList.add( 'btn-secondary' );
selectButton.innerHTML = 'Select';
selectButton.addEventListener( 'click', () => this.selectElementText() );
return selectButton;
}

this.selectElementText();
await navigator.clipboard.writeText( this.element.innerText );
}

this.selectElementText();
await navigator.clipboard.writeText( this.element.innerText );
Comment on lines +23 to 24
await navigator.clipboard.writeText( rawText );
liquipedia.copytoclipboard.showNotification( parent );
liquipedia.copytoclipboard.selectAndCopy();
liquipedia.copytoclipboard.removeInputBox();
if ( !navigator.clipboard || !navigator.clipboard.writeText ) {
mw.notify( 'This browser does not support copying text to the clipboard.', { type: 'error' } );
Comment on lines +26 to +27
"stylelint-scss": "^7.x.x",
"types-mediawiki": "^2.0.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Changes to JavaScript files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants