don't intercept pastes inside citation ids#1060
Conversation
The generic markdown / html paste handlers were consuming pastes that occur inside a cite_id mark, preventing the cite mark's own paste handler from offering to insert a citation when a DOI is pasted after '@'. On Windows this made DOI paste citations entirely unreachable, since the html paste handler consumes any paste carrying text/html there. Addresses rstudio/rstudio#18295
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Avoids adding new external devDependencies (vitest, jsdom) for a test runner: the vscode extension suite is the only test harness exercised by CI, and the paste handlers import cleanly in the extension host (prosemirror-view guards its DOM access at import time). The 'editor' workspace package is added as a devDependency of the extension for the test's imports.
There was a problem hiding this comment.
The tests look reasonable to me, I left one comment. Ran the tests locally on mac and they passed. I checked out this PR and on Mac VSCode I tried out typing @ and pasting a DOI in the visual editor, and it successfully searched for a DOI; So the functionality seems unaffected on Mac, as it should be.
I'm giving my approval, but I do think you should await manual verification on windows before merging @kevinushey .
An aside
I believe this to either be my incompetence or a separate issue, but: this functionality seems to always fail to look up the DOI, screenshot attached. Thought I'd put that here in case its somehow relevant.
|
I think the issue you were seeing was because the tests used the canonical example DOI (10.1000/182, the DOI Handbook), which resolves to a landing page but doesn't have citation metadata behind it -- so the lookup gets HTML instead of CSL JSON. I've updated the tests to use a real Crossref DOI and left a comment explaining this. |
|
When I type @ and paste the updated DOI (10.1038/nature12373) it gets looked up properly now! Thanks |
|
Hmmmm something seems to be going wrong with the basic roundtrip test in the Quarto pre-release @cscheid . Could this have to do with the new pandoc changes? |
Addresses rstudio/rstudio#18295
Problem
In the visual editor on Windows, typing
@and pasting a DOI (e.g.https://doi.org/10.1000/182) does nothing, whereas on Linux/macOS the editor offers to look up the DOI and insert a citation.Cause
ProseMirror consults
handlePasteplugins in registration order, and the generic paste extension (behaviors/paste.ts) is registered before the cite mark'spaste_cite_doiplugin. Inside acite_idmark the generic handlers form a pincer that preventspaste_cite_doifrom ever running on Windows:text/html(e.g. a DOI copied from a browser page) are consumed bypasteHtmlHandler'sisWindows()branch (the workaround for ProseMirror freezing on multi-paragraph pastes).pasteMarkdownHandler(the cite marks don't setnoInputRules, soallowMarkdownPastereturns true inside a citation). This variant also affects macOS and Linux.Since
isWindows()keys off the user agent, this affects any Windows client, including browsers connecting to a Linux server.Fix
Both generic handlers now return
falsewhen the selection is inside acite_idmark, allowing the cite mark's own paste handler to process the paste (insert the DOI, offer to insert a citation, or fall back to a plain-text insert for non-DOI content).Tests
Added
apps/vscode/src/test/editor-paste.test.tscovering the fixed cases plus the preserved behaviors (Office content and Windowstext/htmlpastes outside citations are still handled, plain text outside citations is still pasted as markdown). The 3 regression cases fail without the fix.The tests live in the vscode extension suite (rather than
packages/editor, whose jest-style tests undertest/apiare orphaned -- no runner is configured for them, andtest/README.mdnotes their fixtures no longer work) because it is the only harness exercised by CI, and this avoids adding a new test runner dependency. The tests exercise the editor package directly and don't use the vscode API; the only dependency change is adding theeditorworkspace package as a devDependency of the extension.Verified
tsc --noEmitand the panmirror bundle build pass. Manual verification on Windows is still pending.