Replies: 7 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 |
Beta Was this translation helpful? Give feedback.
-
thanks a lot for the quick response. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
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);
}
} |
Beta Was this translation helpful? Give feedback.
-
Hi @andrienko Thanks for the detailed explanation and help provided! |
Beta Was this translation helpful? Give feedback.
-
any update? |
Beta Was this translation helpful? Give feedback.
-
@alexdima is this going to be tackled anytime soon? |
Beta Was this translation helpful? Give feedback.
-
monaco-editor version: 0.X.Y
Browser:
OS:
Steps or JS usage snippet reproducing the issue:
Beta Was this translation helpful? Give feedback.
All reactions