Skip to content
Open
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
10 changes: 1 addition & 9 deletions src/editor/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 })
}
})
}
Expand Down Expand Up @@ -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

Expand Down
38 changes: 38 additions & 0 deletions test/system/plain_text_paste_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading