How to customize a code editor tool? #2429
-
Can custom tool introduce third-party libraries? I want to use "react-textarea-code-editor" to make a code editor tool. Is it possible? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Absolutley! Check out the custom config example for an idea of how to implement a custom shape and tool. You can do normal React things in the component method of the shape util, so you can import any React libraries you want and render them in the return statement. Hope that helps, and feel free to show us what you've made in the tldraw discord. |
Beta Was this translation helpful? Give feedback.
-
Looks great already! So, I'm not sure how the CodeEditor component works but you might be having trouble with mouse events because the editor thinks you're trying to select or drag the shape instead of edit the code.Try adding an onPointer down prop to the CodeEditor component to stop the event from bubbling: <CodeEditor
// your other props
onPointerDown={(e) => e.stopPropagation()}
/> If you want to implement specific pointer behaviour for the tool then you'll want to edit the tool file, you can see in the custom config example that we indicate where you can add your code to handle a double click event. For an example of a tool that demonstrates more complex behaviour, take a look at the screenshot example. As for the store.getSnapshot() method, a shape's props are added to the store and are available via the getSnapshot method. Just make sure you add the text to the shape's props. Let me know if that works, and feel free to come back with any more questions. |
Beta Was this translation helpful? Give feedback.
Absolutley! Check out the custom config example for an idea of how to implement a custom shape and tool. You can do normal React things in the component method of the shape util, so you can import any React libraries you want and render them in the return statement. Hope that helps, and feel free to show us what you've made in the tldraw discord.