Repository navigation
Description
Description
Pasting plain-text clipboard content that consists only of whitespace does nothing in MarkText.
For example, if the document contains AB, placing the caret between A and B and pasting two normal spaces leaves the document unchanged. Non-whitespace plain text pasted through the same path works correctly.
This is surprising for a Markdown editor because spaces are valid text content. I also checked the same user action in Typora, where pasting two spaces between A and B correctly produces A B.
Steps to Reproduce
- Create or open a Markdown document containing only:
AB- Move the caret between
AandB:
A|B
- Put two normal spaces on the system clipboard.
On Windows, one reliable way to do this is:
Set-Clipboard -Value ' 'The quoted string contains two U+0020 space characters.
-
Return to MarkText and press
Ctrl+V. -
Without moving the caret, type
X.
Control Check
Repeat the same steps, but put xx on the clipboard instead:
Set-Clipboard -Value 'xx'Then paste at the same A|B caret position.
Expected Behavior
The pasted spaces should be inserted at the caret.
After pasting two spaces and then typing X, the document should become:
A XB
The equivalent immediate state after paste, before typing X, should be:
A B
Actual Behavior
The whitespace-only paste is ignored.
After pasting two spaces and then typing X, the document becomes:
AXB
This indicates that the two pasted spaces were not inserted.
The control check works correctly. Pasting xx at the same caret position produces:
AxxB
So this does not appear to be a general clipboard, focus, or Ctrl+V problem. The failure is specific to whitespace-only plain-text clipboard content.
Screenshots / Logs
No crash log is produced. This is a silent paste no-op.
The desktop beta appears to route this through the legacy Muya paste path:
packages/muyajs/lib/contentState/pasteCtrl.js
The relevant flow appears to be:
pasteHandler()reads the plain text fromevent.clipboardData.getData('text/plain').- With no HTML payload,
checkCopyType(html, text)classifies the clipboard asonlyMarkdown. - The paste handler parses the clipboard text as Markdown:
const stateFragments =
type === 'pasteAsPlainText' || copyType === 'onlyMarkdown'
? this.markdownToState(text)
: this.html2State(html)- For a string containing only spaces, Markdown parsing yields no fragments.
- The paste handler returns without inserting anything:
if (stateFragments.length <= 0) {
return
}That treats valid whitespace-only plain text as if the clipboard were empty.
A focused fix may need to distinguish between:
- truly empty clipboard text, such as
"" - non-empty clipboard text that is all whitespace, such as
" "or"\u00a0"
For normal paragraph/text insertion, the second case should be inserted literally instead of being discarded after Markdown parsing returns no block fragments.
There is also a similar guard in the newer Muya core paste implementation:
packages/muya/src/clipboard/paste.ts
where parsed paste handling returns early when markdown.trim().length === 0. That path appears to have the same risk for whitespace-only plain-text paste payloads.
Operating System
Windows
MarkText Version
0.20.0-beta.2
OS Version
Windows 11 Pro 10.0.26200
Reproducibility
- I can reliably reproduce this issue
Activity