Skip to content

fix(paste): replace selected blocks on pasting#1996

Open
kaaaaaaaaaaai wants to merge 22 commits intocodex-team:nextfrom
kaaaaaaaaaaai:fix/#1705
Open

fix(paste): replace selected blocks on pasting#1996
kaaaaaaaaaaai wants to merge 22 commits intocodex-team:nextfrom
kaaaaaaaaaaai:fix/#1705

Conversation

@kaaaaaaaaaaai
Copy link
Contributor

@kaaaaaaaaaaai kaaaaaaaaaaai commented Mar 11, 2022

Resolves #1705

I always use products. And I was stressed about this issue, so I tried a fix. And I'm here to discuss solutions.

Maybe a caret issue...? and it did not work without _deley

If you think you can figure out the cause, please let me know and I will fix it.

Tasks

  • Writing Tests
     _.delay(() => {
        document.execCommand(
          'insertHTML',
          false,
          clean(content.innerHTML, currentToolSanitizeConfig)
        );
      }, 20)();

@hiepxanh
Copy link

hiepxanh commented Apr 8, 2022

hello, anybody here?

@robonetphy robonetphy self-assigned this Apr 13, 2022
@robonetphy
Copy link
Member

robonetphy commented Apr 21, 2022

@kaaaaaaaaaaai, Thanks for creating the PR for the issue and sorry for the late response.
Can you pls update the test case according to your pr so we can go for merge.
I guess you just need to increase this time.

@robonetphy robonetphy changed the title fix: can't relplace text when paste command with multi selected blocks(#1705) fix: can't replace text when paste command with multi selected blocks(#1705) Apr 28, 2022
@robonetphy robonetphy requested review from gohabereg and neSpecc April 28, 2022 19:25
BlockManager.setCurrentBlockByChildNode(block.holder);
BlockManager.currentBlock.currentInput = element;

return new Promise<void>((resolve) => {
Copy link
Member

Choose a reason for hiding this comment

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

why do we need the delay and the Promise?

Copy link
Member

Choose a reason for hiding this comment

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

this moment still looks like a not ideal solution. Please, describe the problem you are solving

@kaaaaaaaaaaai
Copy link
Contributor Author

@robonetphy @neSpecc
thank you response.

i try! I'll do my best to contribute!

BlockManager.setCurrentBlockByChildNode(block.holder);
BlockManager.currentBlock.currentInput = element;

return new Promise<void>((resolve) => {
Copy link
Member

Choose a reason for hiding this comment

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

this moment still looks like a not ideal solution. Please, describe the problem you are solving

*/
private setCallback(): void {
this.listeners.on(this.Editor.UI.nodes.holder, 'paste', this.handlePasteEvent);
this.listeners.on(document, 'paste', this.handlePasteEvent);
Copy link
Member

Choose a reason for hiding this comment

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

Have you tested pasting on a page that has several editor instances? You can test on the example-multiple.html page

Copy link
Member

@robonetphy robonetphy May 23, 2022

Choose a reason for hiding this comment

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

Yup it's not working but then we need to think about it

Copy link
Member

Choose a reason for hiding this comment

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

Fixed

@robonetphy
Copy link
Member

robonetphy commented May 23, 2022

@neSpecc about the promise we added into the caret.ts, if you check here
Currently, there is a delay during the caret set process since we are trying to replace the entire or partial content of the editor we need to do the following steps:

  1. Remove all the selected blocks.
  2. add a new empty default block.
  3. set the caret to it (need a promise to wait for the caret to set).
  4. add all the clipboard contents

@kaaaaaaaaaaai
Copy link
Contributor Author

That's right! That's what I wanted to say :)))))

Comment on lines +441 to +442
if (!BlockSelection.anyBlockSelected) {
return;
Copy link
Member

Choose a reason for hiding this comment

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

seems like the previous behavior is disabled at all.

/**
* process multi-block selection paste.
*/
dataTransfer = await this.processMultiBlockSelection(dataTransfer);
Copy link
Member

Choose a reason for hiding this comment

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

anyBlockSelected does not guarantee that there are several blocks. There could be the single block selected.

const { BlockManager, Caret } = this.Editor;

/** Remove all the selected blocks */
const nextBlockIndex = BlockManager.removeSelectedBlocks();
Copy link
Member

Choose a reason for hiding this comment

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

i think it should be somewhere inside processDataTransfer

Comment on lines +657 to +658
/** Create copy of the clipboard since new default block insertion change the event.*/
const clipboard = _.copyClipboard(dataTransfer);
Copy link
Member

Choose a reason for hiding this comment

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

it is not clear. how adding a new block affects data in a clipboard?

@neSpecc
Copy link
Member

neSpecc commented Feb 18, 2023

Lack of tests

@neSpecc neSpecc changed the title fix: can't replace text when paste command with multi selected blocks(#1705) fix(paste): replace selected blocks on pasting Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Ctl A twice + Ctl-V doesn’t replace the whole content of the page

5 participants