From 4dce8d9ab44bc71d6ea9f87a0bcd1ea6e3022846 Mon Sep 17 00:00:00 2001 From: Marcin Panek Date: Fri, 20 Oct 2023 12:58:13 +0200 Subject: [PATCH] Feature: Paste from markdown PoC. --- .../ckeditor5-markdown-gfm/src/markdown.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/ckeditor5-markdown-gfm/src/markdown.ts b/packages/ckeditor5-markdown-gfm/src/markdown.ts index 82d4da205eb..e58ea8e5512 100644 --- a/packages/ckeditor5-markdown-gfm/src/markdown.ts +++ b/packages/ckeditor5-markdown-gfm/src/markdown.ts @@ -9,6 +9,8 @@ import { Plugin, type Editor } from 'ckeditor5/src/core'; import GFMDataProcessor from './gfmdataprocessor'; +import type { ClipboardPipeline, ClipboardInputTransformationEvent } from 'ckeditor5/src/clipboard'; +import type { ViewDocumentKeyDownEvent } from 'ckeditor5/src/engine'; /** * The GitHub Flavored Markdown (GFM) plugin. @@ -31,4 +33,31 @@ export default class Markdown extends Plugin { public static get pluginName() { return 'Markdown' as const; } + + /** + * @inheritDoc + */ + public init(): void { + const editor = this.editor; + const view = editor.editing.view; + const viewDocument = view.document; + + const clipboardPipeline: ClipboardPipeline = editor.plugins.get( 'ClipboardPipeline' ); + + let shiftPressed = false; + + this.listenTo( viewDocument, 'keydown', ( evt, data ) => { + shiftPressed = data.shiftKey; + } ); + + this.listenTo( clipboardPipeline, 'inputTransformation', ( evt, data ) => { + if ( data.dataTransfer.getData( 'text/html' ) || shiftPressed ) { + return; + } + + const dataStr = data.dataTransfer.getData( 'text/plain' ); + + data.content = editor.data.processor.toView( dataStr ); + } ); + } }