Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Will monaco support drag and drop option? Can anyone provide small example for that. #1050

Closed
reddys11 opened this issue Sep 4, 2018 · 7 comments
Labels
feature-request Request for new features or functionality
Milestone

Comments

@reddys11
Copy link

reddys11 commented Sep 4, 2018

monaco-editor version: 0.X.Y
Browser:
OS:
Steps or JS usage snippet reproducing the issue:

@alexdima
Copy link
Member

alexdima commented Sep 6, 2018

There is built-in support for drag & drop of text within the editor.

There is no built-in support for drag & drop of text from or to the editor. To simulate dragging into the editor, one could register mouse listeners from the outside and use getTargetAtClientPoint to figure out what the drop target is within the editor.

@reddys11
Copy link
Author

reddys11 commented Sep 6, 2018

thanks a lot for the quick response.

@PavelGriza
Copy link

thanks a lot for the quick response.

@reddys11 Did you manage to implement text dropping into the editor?
Could you please provide some details regarding it?

@alexandrudima, I am not quite experience with moncao editor, could you please help or describe in more detailed way.

Thanks in advance.

@andrienko
Copy link

andrienko commented Jun 5, 2019

Hello. After some tinkering I wrote a little helper for that:
https://gist.github.com/andrienko/a754de7e615fa01435a526c8b6d238cd
It even displays the position of the drop.

(It is made with React in mind, so you might want to adjust something)

Usage is simple - for each instance you just create a new drag provider, which you pass your onDrop handler and a function that returns your monaco editor instance:

const dragProvider = new MonacoDragNDropProvider( onDrop , () => editorInstance );

and then you add its props to your component that wraps monaco:

<div {...dragProvider.props}>
  {/* Your monaco div/component goes here */}
</div>

Might be buggy, but you get the idea. For an example of onDrop:

export const insertTextAtPos = (
  instance: IStandaloneCodeEditor,
  text,
  coords: [number, number] = [0, 0],
  placeCursor: boolean = false
) => {
  const range = new Range(coords[0], coords[1], coords[0], coords[1]);
  if (placeCursor) {
    const selection = new Selection(coords[0], coords[1], coords[0], coords[1]);
    instance.executeEdits('insert', [{ range, text, forceMoveMarkers: true }], [selection]);
    instance.focus();
  } else {
    instance.executeEdits('insert', [{ range, text, forceMoveMarkers: true }]);
  }
  instance.pushUndoStop();
};

const onDrop = (e: React.DragEvent, target: IMouseTarget, instance) => {
  const text = e.dataTransfer.getData('text');
  if (text && instance) {
    insertTextAtPos(instance, text, [target.position.lineNumber, target.position.column], true);
  }
}

@PavelGriza
Copy link

Hi @andrienko

Thanks for the detailed explanation and help provided!

@alexdima alexdima added the feature-request Request for new features or functionality label Dec 12, 2019
@alexdima alexdima added this to the Backlog milestone Dec 12, 2019
@abdurrahmanyildirim
Copy link

any update?

@afonsomatos
Copy link

@alexdima is this going to be tackled anytime soon?

@microsoft microsoft locked and limited conversation to collaborators Mar 8, 2023
@hediet hediet converted this issue into discussion #3755 Mar 8, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

6 participants