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

Replace text block on paste if empty #2271

Merged
merged 1 commit into from
Aug 22, 2017
Merged

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Aug 7, 2017

This PR fixes pasting in an empty paragraph. At the moment this would "split" the empty paragraph and paste the blocks in between, resulting in an empty block above and below the pasted blocks. Instead, we should replace the current block.

@ellatrix ellatrix added this to the Beta 0.8.0 milestone Aug 7, 2017
@ellatrix ellatrix force-pushed the fix/paste-empty-paragraph branch from 3c94376 to df273e9 Compare August 7, 2017 17:51
@codecov
Copy link

codecov bot commented Aug 7, 2017

Codecov Report

Merging #2271 into master will decrease coverage by 0.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2271      +/-   ##
==========================================
- Coverage   29.01%   28.99%   -0.02%     
==========================================
  Files         167      167              
  Lines        5060     5063       +3     
  Branches      835      836       +1     
==========================================
  Hits         1468     1468              
- Misses       3053     3055       +2     
- Partials      539      540       +1
Impacted Files Coverage Δ
blocks/editable/index.js 11.29% <0%> (-0.15%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5f191a...bb086d1. Read the comment docs.

@ellatrix ellatrix self-assigned this Aug 8, 2017
}

// We must wait for TinyMCE to clean up paste containers after this event.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any concerns?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think TinyMCE is doing this asynchronously, so setTimeout is a bit of a hack. Instead can we make sure this logic is only triggered after TinyMCE completes its cleaning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest to use instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it in TinyMCE doing the cleaning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduth I don't see a good solution for either timeout. There's no event after removing that content and before event.defaultPrevented. There's also no specific paste event after insertion. CC @spocke.

}

// We must wait for TinyMCE to clean up paste containers after this event.
window.setTimeout( () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setTimeout is a common global between DOM APIs and Node, we shouldn't need window.?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like being explicit sorry :)


// We must wait for TinyMCE to clean up paste containers after this event.
window.setTimeout( () => {
const rootNode = this.editor.getBody();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work okay if component unmounts between time setTimeout is called and callback is invoked?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noting :) What's the best check for that? this.editor?

@aduth
Copy link
Member

aduth commented Aug 9, 2017

Repeating steps from #2180, except with two paragraphs instead of one from Lipsum, the initial paragraph is not stripped, and an error is logged:

patterns.js:184 Uncaught TypeError: Cannot read property 'normalize' of null

@ellatrix ellatrix force-pushed the fix/paste-empty-paragraph branch from 85612f2 to 69ccb98 Compare August 9, 2017 15:16
@mtias mtias modified the milestones: Beta 0.9.0, Beta 0.8.0 Aug 14, 2017
@ellatrix ellatrix requested review from mtias and aduth August 16, 2017 19:01
@ellatrix
Copy link
Member Author

What's the status here? We cannot really improve without a better MCE event.

@androb
Copy link
Contributor

androb commented Aug 16, 2017

@iseulde how important is this? we could get a new event on the list to look at (sorry if this has been discussed elsewhere already)

@ellatrix
Copy link
Member Author

@androb I'm not sure... More important if it blocks this PR. :)

@jasmussen
Copy link
Contributor

This works for me 👍 👍

I'm seeing an issue with the cover image block being "externally modified" on paste, but I believe that's a separate issue.

@ellatrix
Copy link
Member Author

No idea how that's related.

Cross link: https://wordpress.slack.com/archives/C02QB2JS7/p1503060598000155

@mtias mtias modified the milestones: 0.10.0, Beta 0.9.0 Aug 18, 2017
@ellatrix ellatrix force-pushed the fix/paste-empty-paragraph branch from 69ccb98 to bb086d1 Compare August 22, 2017 20:45
@ellatrix
Copy link
Member Author

Concerns addressed.

@ellatrix ellatrix merged commit b214201 into master Aug 22, 2017
@ellatrix ellatrix deleted the fix/paste-empty-paragraph branch August 22, 2017 20:46
@ellatrix ellatrix restored the fix/paste-empty-paragraph branch August 22, 2017 20:46
@ellatrix ellatrix deleted the fix/paste-empty-paragraph branch August 22, 2017 20:46
ceyhun pushed a commit that referenced this pull request Jun 17, 2020
…_not_merged

Fix merged of text blocks when a style is active.
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.

5 participants