Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content Not Refreshed Correctly when Modifying Pasted Content in Callbacks #1107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chadrschroeder
Copy link

Fixes #1103.

When pasting plain text content or a URL, if you modify the content in a trix-change or trix-paste callback, the changes aren't reflected in the editor after the paste is finished. The changes are reflected later if you start to type in the editor.

This pull request updates how the render is performed to match other areas like this.

…aste and trix-change callbacks are refreshed in the editor when pasting plain text
@danielnc
Copy link

Bump to see what are the plans to get this merged and/or a workaround based on issue #1103

@jondkinney
Copy link

I'm seeing this as well and have a feature where I want to copy some text from a spot in my UI and paste it into Trix to be processed as another instance of an existing ContentAttachment. However, because of this bug, it doesn't work until you press space or type another character, as described above.

I ended up working around this by having the copy feature write HTML to the clipboard even though I really only need plain text. For whatever reason Trix does process the paste with HTML properly.

function copyDateTag(button) {
  const taskDiv = button.closest('.task-date-tag');
  const pastableString = taskDiv.querySelector('.pastable-date-tag-string');
  
  const content = `${pastableString.textContent.trim()}`;
  
  // Need to use HTML because if you paste plain text into Trix it will not
  // process the pasted content as a ContentAttachment until another char
  // is pressed. See https://github.com/basecamp/trix/pull/1107
  const clipboardItem = new ClipboardItem({
    'text/html': new Blob([content], { type: 'text/html' }),
    'text/plain': new Blob([content], { type: 'text/plain' })
  });

  navigator.clipboard.write([clipboardItem])
    .then(() => {
      // Update button text while preserving the icon
      const originalText = button.innerHTML;
      const icon = button.querySelector('svg').outerHTML;
      button.innerHTML = `${icon} Copied!`;
      setTimeout(() => {
        button.innerHTML = originalText;
      }, 2000);
    })
    .catch(error => console.error('Failed to copy:', error));
}

But it'd be nice to get this one merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content Not Refreshed Correctly for pasteEventHasPlainTextOnly Special Case
3 participants