[SOLVED] Duplication when pasting


I’m trying to do a smartPaste, which will evaluate if the selected area is a valid area to paste the target content. The problem is when the area selected is just the cursor’s text position, it is pasting twice.

I reduced the problem to a simpler one which I believe it is the source of the bug I am facing. So, the reduced problem is: when the user paste some content, I want the text to be inserted only on the position x:51 y:51, canceling the original transaction and doing only the new transaction on the target position.

I am using EditorView.domEventHandlers to get the clipboard content and dispatch the changes.

Is there a solution for that? Could anyone help me, please? Here it is the code:

const pasteOnlyOnSpecificPosition = () => EditorView.domEventHandlers({
  paste(event:any, view:any)

    const clipboardData = event.clipboardData || (window as any).clipboardData;
    const pastedData = clipboardData.getData('Text');
              from: 51, 
              to: 51, 
              insert: pastedData 

const App = () => {

  const initialCode = 
  `read-only line 1
read-only line 2
read-only line 3
<Here you can modify>
read-only line 4` 

return (<CodeEditor onView={console.log} initialDocValue={initialCode} extensions={[basicSetup, pasteOnlyOnSpecificPosition() ]} />);

export default App;

Return true from your paste handler.

1 Like

It is working now! Thanks for the support!