Skip to content

Build your personal knowledge base with Trilium Notes

fix(kbd): don't carry keyboard-marker formatting onto the next paragraph

Elian Doran522e363706d7
diff --git a/packages/ckeditor5-keyboard-marker/src/kbdediting.ts b/packages/ckeditor5-keyboard-marker/src/kbdediting.ts
index 7c119d22fd..be9cd35833 100644
--- a/packages/ckeditor5-keyboard-marker/src/kbdediting.ts
+++ b/packages/ckeditor5-keyboard-marker/src/kbdediting.ts
@@ -28,7 +28,7 @@ export default class KbdEditing extends Plugin {
editor.model.schema.extend( '$text', { allowAttributes: KBD } );
editor.model.schema.setAttributeProperties( KBD, {
isFormatting: true,
- copyOnEnter: true
+ copyOnEnter: false
} );
// Enable two-step caret movement so the user can arrow out of the kbd element.
diff --git a/packages/ckeditor5-keyboard-marker/tests/kbd.ts b/packages/ckeditor5-keyboard-marker/tests/kbd.ts
new file mode 100644
index 0000000000..29bde4a189
--- /dev/null
+++ b/packages/ckeditor5-keyboard-marker/tests/kbd.ts
@@ -0,0 +1,72 @@
+import { ClassicEditor, Paragraph } from 'ckeditor5';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { icons, Kbd, KbdEditing, KbdUI } from '../src/index.js';
+
+describe( 'Kbd', () => {
+ let editorElement: HTMLDivElement, editor: ClassicEditor;
+
+ beforeEach( async () => {
+ editorElement = document.createElement( 'div' );
+ document.body.appendChild( editorElement );
+
+ editor = await ClassicEditor.create( editorElement, {
+ plugins: [ Paragraph, Kbd ],
+ licenseKey: 'GPL'
+ } );
+ } );
+
+ afterEach( async () => {
+ editorElement.remove();
+
+ await editor.destroy();
+ } );
+
+ it( 'loads the glue plugin and its editing/UI parts', () => {
+ expect( editor.plugins.get( Kbd ) ).toBeInstanceOf( Kbd );
+ expect( editor.plugins.get( KbdEditing ) ).toBeInstanceOf( KbdEditing );
+ expect( editor.plugins.get( KbdUI ) ).toBeInstanceOf( KbdUI );
+ expect( Kbd.pluginName ).toBe( 'Kbd' );
+ expect( icons.kbdIcon ).toContain( '<svg' );
+ } );
+
+ it( 'allows the kbd attribute on text and marks it as formatting', () => {
+ expect( editor.model.schema.checkAttribute( '$text', 'kbd' ) ).toBe( true );
+
+ // Regression guard: kbd is a discrete inline token, so pressing Enter must NOT
+ // carry the formatting onto the next paragraph (mirrors inline `code`, unlike bold/italic).
+ expect( editor.model.schema.getAttributeProperties( 'kbd' ) ).toEqual( {
+ isFormatting: true,
+ copyOnEnter: false
+ } );
+ } );
+
+ it( 'downcasts the kbd attribute to a <kbd> element with spellcheck disabled', () => {
+ editor.setData( '<p>Ctrl</p>' );
+
+ const root = editor.model.document.getRoot();
+ editor.model.change( writer => {
+ writer.setSelection( root?.getChild( 0 ) ?? null, 'in' );
+ } );
+ editor.execute( 'kbd' );
+
+ expect( editor.getData() ).toBe( '<p><kbd spellcheck="false">Ctrl</kbd></p>' );
+ } );
+
+ it( 'upcasts a <kbd> element back to the kbd attribute', () => {
+ editor.setData( '<p>Press <kbd spellcheck="false">Ctrl</kbd>.</p>' );
+
+ expect( editor.getData() ).toBe( '<p>Press <kbd spellcheck="false">Ctrl</kbd>.</p>' );
+ } );
+
+ it( 'registers the toolbar button bound to the command', () => {
+ const button = editor.ui.componentFactory.create( 'kbd' );
+ const command = editor.commands.get( 'kbd' );
+
+ expect( button.isToggleable ).toBe( true );
+ expect( button.isOn ).toBe( false );
+
+ button.fire( 'execute' );
+
+ expect( command?.value ).toBe( true );
+ } );
+} );