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

heading shortcuts #116

Merged
merged 4 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
/node_modules
/vendor
node_modules
/.env
.env
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Added the “Word Limit” field setting. ([#107](https://github.com/craftcms/ckeditor/issues/107))
- Added the “List Plugin” CKEditor config setting. ([#112](https://github.com/craftcms/ckeditor/issues/112), [#122](https://github.com/craftcms/ckeditor/pull/122))
- Added keyboard shortcuts for switching the heading type for a given block. ([#106](https://github.com/craftcms/ckeditor/issues/106), [#116](https://github.com/craftcms/ckeditor/pull/116))
- CKEditor config edit pages now have a “Save and continue editing” alternative submit action, and the <kbd>Command</kbd>/<kbd>Ctrl</kbd> + <kbd>S</kbd> keyboard shortcut now redirects back to the edit page. ([#108](https://github.com/craftcms/ckeditor/discussions/108))
- CKEditor config edit pages now have a “Save as a new config” alternative submit action. ([#110](https://github.com/craftcms/ckeditor/discussions/110))
- The `ckeditor/convert` action will now find and convert `craft\fields\MissingField` instances that were meant to be Redactor fields.
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js.map

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions src/web/assets/ckeditor/src/ckeditor5-craftcms.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,52 @@ const trackChangesInSourceMode = function (editor) {
});
};

const headingShortcuts = function (editor, config) {
if (config.heading !== undefined) {
var headingOptions = config.heading.options;

if (headingOptions.find((x) => x.view === 'h1') !== undefined) {
editor.keystrokes.set('Ctrl+Alt+1', () =>
editor.execute('heading', {value: 'heading1'}),
);
}

if (headingOptions.find((x) => x.view === 'h2') !== undefined) {
editor.keystrokes.set('Ctrl+Alt+2', () =>
editor.execute('heading', {value: 'heading2'}),
);
}

if (headingOptions.find((x) => x.view === 'h3') !== undefined) {
editor.keystrokes.set('Ctrl+Alt+3', () =>
editor.execute('heading', {value: 'heading3'}),
);
}

if (headingOptions.find((x) => x.view === 'h4') !== undefined) {
editor.keystrokes.set('Ctrl+Alt+4', () =>
editor.execute('heading', {value: 'heading4'}),
);
}

if (headingOptions.find((x) => x.view === 'h5') !== undefined) {
editor.keystrokes.set('Ctrl+Alt+5', () =>
editor.execute('heading', {value: 'heading5'}),
);
}

if (headingOptions.find((x) => x.view === 'h6') !== undefined) {
editor.keystrokes.set('Ctrl+Alt+6', () =>
editor.execute('heading', {value: 'heading6'}),
);
}

if (headingOptions.find((x) => x.model === 'paragraph') !== undefined) {
editor.keystrokes.set('Ctrl+Alt+p', 'paragraph');
}
}
};

export const pluginNames = () => allPlugins.map((p) => p.pluginName);

export const create = async function (element, config) {
Expand Down Expand Up @@ -365,5 +411,10 @@ export const create = async function (element, config) {
trackChangesInSourceMode(editor, SourceEditing);
}

// shortcuts for headings & paragraph
if (plugins.includes(Heading)) {
headingShortcuts(editor, config);
}

return editor;
};
Loading