diff --git a/src/editor/clipboard.js b/src/editor/clipboard.js index 0c2268f10..825c1aa6f 100644 --- a/src/editor/clipboard.js +++ b/src/editor/clipboard.js @@ -4,7 +4,6 @@ import { nextFrame } from "../helpers/timing_helper" import { addBlockSpacing, dispatch, parseHtml } from "../helpers/html_helper" import { $isCodeNode } from "@lexical/code" import { $createTextNode, $getSelection, $isParagraphNode, $isRangeSelection, $onUpdate, COMMAND_PRIORITY_NORMAL, PASTE_COMMAND, PASTE_TAG, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND } from "lexical" -import { $insertDataTransferForRichText } from "@lexical/clipboard" import { $createLinkNode, $isLinkNode, $toggleLink } from "@lexical/link" import { ListenerBin } from "../helpers/listener_helper" import NodeInserter from "./contents/node_inserter" @@ -148,7 +147,7 @@ export default class Clipboard { } else if (this.editorElement.supportsMarkdown) { this.#pasteMarkdown(text) } else { - this.#pasteRichText(clipboardData) + this.contents.insertText(text, { tag: PASTE_TAG }) } }) } @@ -226,13 +225,6 @@ export default class Clipboard { && Array.from(paragraph.childNodes).every((node) => node.nodeType === Node.TEXT_NODE || node.nodeName === "BR") } - #pasteRichText(clipboardData) { - this.editor.update(() => { - const selection = $getSelection() - $insertDataTransferForRichText(clipboardData, selection, this.editor) - }, { tag: PASTE_TAG }) - } - #handlePastedFiles(clipboardData) { if (!this.editorElement.supportsAttachments) return false diff --git a/test/system/plain_text_paste_test.rb b/test/system/plain_text_paste_test.rb new file mode 100644 index 000000000..bc4c6e417 --- /dev/null +++ b/test/system/plain_text_paste_test.rb @@ -0,0 +1,38 @@ +require "application_system_test_case" + +class PlainTextPasteTest < ApplicationSystemTestCase + PASTED_TEXT = "Plain text pasted from the clipboard" + MODIFIER = RUBY_PLATFORM.include?("darwin") ? :command : :control + + test "pastes plain text when markdown is disabled" do + visit new_post_path(markdown_disabled: 1) + paste_from_clipboard PASTED_TEXT + + find_editor.within_contents do + assert_text PASTED_TEXT + end + end + + test "pastes plain text in a plain-text-only editor" do + visit new_post_path(rich_text_disabled: 1) + paste_from_clipboard PASTED_TEXT + + find_editor.within_contents do + assert_text PASTED_TEXT + end + end + + private + def paste_from_clipboard(text) + copy_to_clipboard text + + find_editor.click + find_editor.content_element.send_keys [ MODIFIER, "v" ] + end + + def copy_to_clipboard(text) + title = find_field("Post title") + title.set text + title.send_keys [ MODIFIER, "a" ], [ MODIFIER, "c" ] + end +end