diff --git a/e2e-tests/editor.spec.ts b/e2e-tests/editor.spec.ts index 65fb6de47b..2c16fac94b 100644 --- a/e2e-tests/editor.spec.ts +++ b/e2e-tests/editor.spec.ts @@ -495,7 +495,7 @@ test('press escape when link/image dialog is open, should restore focus to input // Press enter to open the link dialog await page.keyboard.press('Enter') - await expect(page.locator(`[data-modal-name="input"]`)).toBeVisible() + await expect(page.locaitor(`[data-modal-name="input"]`)).toBeVisible() // Press escape; should close link dialog and restore focus to the block textarea await page.keyboard.press('Escape') diff --git a/e2e-tests/paste.spec.ts b/e2e-tests/paste.spec.ts new file mode 100644 index 0000000000..4859bfeaf2 --- /dev/null +++ b/e2e-tests/paste.spec.ts @@ -0,0 +1,15 @@ +import { expect } from '@playwright/test' +import { test } from './fixtures' +import { createRandomPage, enterNextBlock, lastBlock, modKey } from './utils' +import { dispatch_kb_events } from './util/keyboard-events' +import * as kb_events from './util/keyboard-events' + +test('property text deleted on Ctrl+C when its value mixes [[link]] and other text #9100', async ({ page, block }) => { + await createRandomPage(page) + + await block.mustType('category:: [[A]] and [[B]] test') + + await page.keyboard.press(modKey + '+c', { delay: 10 }) + + await expect(page.locator('textarea >> nth=0')).toHaveValue('category:: [[A]] and [[B]] test') +}) diff --git a/src/main/frontend/handler/paste.cljs b/src/main/frontend/handler/paste.cljs index 966accabf0..2ae65968b8 100644 --- a/src/main/frontend/handler/paste.cljs +++ b/src/main/frontend/handler/paste.cljs @@ -97,11 +97,11 @@ (defn- markdown-blocks? [text] - (util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text)) + (boolean (util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text))) (defn- org-blocks? [text] - (util/safe-re-find #"(?m)^\s*\*+\s+" text)) + (boolean (util/safe-re-find #"(?m)^\s*\*+\s+" text))) (defn- paste-copied-blocks-or-text ;; todo: logseq/whiteboard-shapes is now text/html @@ -218,8 +218,6 @@ (let [clipboard-data (gobj/get e "clipboardData") html (.getData clipboard-data "text/html") text (.getData clipboard-data "text")] - (prn {:html html - :text text}) (cond (and (string/blank? text) (string/blank? html)) (paste-file-if-exists id e) diff --git a/src/test/frontend/handler/paste_test.cljs b/src/test/frontend/handler/paste_test.cljs index 7fa95f57e1..0718a1b6c8 100644 --- a/src/test/frontend/handler/paste_test.cljs +++ b/src/test/frontend/handler/paste_test.cljs @@ -173,3 +173,25 @@ :files files}})] (is (= files (js->clj @pasted-file))) (reset))))) + +(deftest-async editor-on-paste-prefer-text-blocks-to-html + (let [actual-blocks (atom nil) + ;; Simplified version of block attributes that are copied + expected-blocks [{:block/content "Test node"} + {:block/content "Notes\nid:: 6422ec75-85c7-4e09-9a4d-2a1639a69b2f"}] + html "bold text" + text "- Test node\n\t- Notes\nid:: 6422ec75-85c7-4e09-9a4d-2a1639a69b2f"] + (test-helper/with-reset + reset + [state/get-input (constantly #js {:value "block"}) + ;; paste-copied-blocks-or-text mocks below + util/stop (constantly nil) + html-parser/convert (constantly "**bold text**") + paste-handler/get-copied-blocks (constantly (p/resolved nil)) + state/get-edit-block (constantly {}) + editor-handler/paste-blocks (fn [blocks _] (reset! actual-blocks blocks))] + (p/let [_ ((paste-handler/editor-on-paste! nil) + #js {:clipboardData #js {:getData (fn [kind] + (if (= kind "text/html") html text))}})] + (is (= expected-blocks (map #(select-keys % [:block/content]) @actual-blocks))) + (reset)))))