Skip to content

[Bug] Pasting whitespace-only plain text into a paragraph is ignored #4701

Closed

Description

@Renakoni

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

  1. Create or open a Markdown document containing only:
AB
  1. Move the caret between A and B:
A|B
  1. 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.

  1. Return to MarkText and press Ctrl+V.

  2. 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.

Image

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:

  1. pasteHandler() reads the plain text from event.clipboardData.getData('text/plain').
  2. With no HTML payload, checkCopyType(html, text) classifies the clipboard as onlyMarkdown.
  3. The paste handler parses the clipboard text as Markdown:
const stateFragments =
  type === 'pasteAsPlainText' || copyType === 'onlyMarkdown'
    ? this.markdownToState(text)
    : this.html2State(html)
  1. For a string containing only spaces, Markdown parsing yields no fragments.
  2. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions