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
Comments
|
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 |
|
thanks a lot for the quick response. |
@reddys11 Did you manage to implement text dropping into the editor? @alexandrudima, I am not quite experience with moncao editor, could you please help or describe in more detailed way. Thanks in advance. |
|
Hello. After some tinkering I wrote a little helper for that: (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 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 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);
}
} |
|
Hi @andrienko Thanks for the detailed explanation and help provided! |
|
any update? |
|
@alexdima is this going to be tackled anytime soon? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
monaco-editor version: 0.X.Y
Browser:
OS:
Steps or JS usage snippet reproducing the issue:
The text was updated successfully, but these errors were encountered: