Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-6492: Keyboard support for redo and undo #903

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/bundle/Resources/encore/ibexa.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const layout = [
path.resolve(__dirname, '../public/js/scripts/helpers/middle.ellipsis.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/form.validation.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/form.error.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/system.helper.js'),
path.resolve(__dirname, '../public/js/scripts/admin.format.date.js'),
path.resolve(__dirname, '../public/js/scripts/core/draggable.js'),
path.resolve(__dirname, '../public/js/scripts/core/dropdown.js'),
Expand Down
78 changes: 78 additions & 0 deletions src/bundle/Resources/public/js/scripts/helpers/system.helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
(function (global, doc, ibexa) {
const { userAgent } = window.navigator;
const isWindows = () => {
return userAgent.includes('Windows');
};
const isMac = () => {
return userAgent.includes('Mac OS X');
};
const isLinux = () => {
return userAgent.includes('Linux');
};
const isShortcutWithLetter = (event, letter) => {
if (isMac()) {
return event.metaKey && event.key === letter;
}

if (isWindows() || isLinux()) {
return event.ctrlKey && event.key === letter;
}

return false;
};
const isUndoPressed = (event) => {
if (isMac()) {
return event.metaKey && !event.shiftKey && event.key === 'z';
}

if (isWindows() || isLinux()) {
return event.ctrlKey && event.key === 'y';
}

return false;
};

const isRedoPressed = (event) => {
if (isMac()) {
return event.metaKey && event.shiftKey && event.key === 'z';
}

if (isWindows() || isLinux()) {
return event.ctrlKey && event.key === 'y';
}

return false;
};
const isSavePressed = (event) => {
return isShortcutWithLetter(event, 's');
};
const isCopyPressed = (event) => {
return isShortcutWithLetter(event, 'c');
};
const isCutPressed = (event) => {
return isShortcutWithLetter(event, 'x');
};
const isPastePressed = (event) => {
return isShortcutWithLetter(event, 'v');
};
const isPrintPressed = (event) => {
return isShortcutWithLetter(event, 'p');
};
const isSelectAllPressed = (event) => {
return isShortcutWithLetter(event, 'a');
};

ibexa.addConfig('helpers.system', {
isWindows: isWindows(),
isMac: isMac(),
isLinux: isLinux(),
isUndoPressed,
isRedoPressed,
isSavePressed,
isCopyPressed,
isCutPressed,
isPastePressed,
isPrintPressed,
isSelectAllPressed,
});
})(window, window.document, window.ibexa);
Loading