Skip to content

Commit

Permalink
Merge pull request #116 from craftcms/feature/106-heading-shortcuts
Browse files Browse the repository at this point in the history
heading shortcuts
  • Loading branch information
brandonkelly authored Aug 12, 2023
2 parents c658741 + 1e87982 commit 300f792
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
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;
};

0 comments on commit 300f792

Please sign in to comment.