You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This binding maps a Y.Text to the Monaco editor (the editor that power VS Code).
Features
Shared Cursors
Example
import*asYfrom'yjs'import{WebsocketProvider}from'y-websocket'import{MonacoBinding}from'y-monaco'import*asmonacofrom'monaco-editor'constydocument=newY.Doc()constprovider=newWebsocketProvider(`${location.protocol==='http:' ? 'ws:' : 'wss:'}//localhost:1234`,'monaco',ydocument)consttype=ydocument.getText('monaco')consteditor=monaco.editor.create(document.getElementById('monaco-editor'),{value: '',// MonacoBinding overwrites this value with the content of typelanguage: "javascript"})// Bind Yjs to the editor modelconstmonacoBinding=newMonacoBinding(type,editor.getModel(),newSet([editor]),provider.awareness)
If the editor(s) are specified, MonacoBinding adjusts selections when remote changes happen. Awareness is an implementation of the awareness protocol of y-protocols/awareness. If Awareness is specified, MonacoBinding renders remote selections.
destroy()
Unregister all event listeners. This is automatically called when the model is disposed.
Styling
You can use the following CSS classes to style remote cursor selections:
yRemoteSelection
yRemoteSelectionHead
See demo/index.html for example styles. Additionally, you can enable per-user styling (e.g.: different colors per user). The recommended approach for this is to listen to awareness.on("update", () => ...)); and inject custom styles for every available clientId. You can use the following classnames for this:
yRemoteSelection-${clientId}
yRemoteSelectionHead-${clientId
(where ${clientId} is the Yjs clientId of the specific user).