Skip to content

Commit

Permalink
Override the keyboard shortcut (⌘S) for saving
Browse files Browse the repository at this point in the history
  • Loading branch information
okmttdhr committed Dec 13, 2023
1 parent faf91f4 commit 8f09760
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,31 @@ export const LivePreviewUpgradeModal: FC< { themeId: string; upgradePlan: () =>
e.stopPropagation();
setIsThemeUpgradeModalOpen( true );
};
const overrideSaveButton = ( selector: string ) => {

const overrideSaveButtonClick = ( selector: string ) => {
const button = document.querySelector( selector );
if ( button ) {
button.textContent = __( 'Upgrade now', 'wpcom-live-preview' );
button.addEventListener( 'click', handler );
}
};
if ( canvasMode === 'view' ) {
overrideSaveButton( SAVE_HUB_SAVE_BUTTON_SELECTOR );
overrideSaveButtonClick( SAVE_HUB_SAVE_BUTTON_SELECTOR );
return;
}
if ( canvasMode === 'edit' ) {
overrideSaveButton( HEADER_SAVE_BUTTON_SELECTOR );
overrideSaveButtonClick( HEADER_SAVE_BUTTON_SELECTOR );
return;
}

// Override the keyboard shortcut (⌘S) for saving.
document.addEventListener( 'keydown', function ( event ) {
if ( event.key === 's' && ( event.metaKey || event.ctrlKey ) ) {
event.preventDefault();
handler( event );
}
} );

return () => {
document
.querySelector( SAVE_HUB_SAVE_BUTTON_SELECTOR )
Expand Down

0 comments on commit 8f09760

Please sign in to comment.