1- import { onCleanup } from "solid-js" ;
1+ import { observable , onCleanup } from "solid-js" ;
22import { CodeMirror } from "@solid-codemirror/codemirror" ;
3+ import { Compartment , EditorState } from "@codemirror/state" ;
34
5+ import { projectAccess } from "@features/colab/stores" ;
46import { getNodeByPath } from "@features/file-explorer/stores" ;
57import { FileNodeKind } from "@features/file-explorer/types" ;
8+ import { AccessLevel } from "@features/ws/types" ;
69
710import { rustExtensions , syncExtension , syncExtensionListener } from "../utils" ;
811import { setEditingFiles , syncFiles } from "../stores" ;
@@ -16,6 +19,7 @@ export interface CodeEditorProps {
1619
1720export function CodeEditor ( props : CodeEditorProps ) {
1821 const [ file , _ ] = getNodeByPath ( props . file ) ;
22+ const readOnly = new Compartment ( ) ;
1923
2024 if ( file . kind == FileNodeKind . Folder ) {
2125 throw new Error ( "Really?? Edit a folder?" ) ;
@@ -33,11 +37,20 @@ export function CodeEditor(props: CodeEditorProps) {
3337 value = { syncFiles [ props . file ] }
3438 extensions = { [
3539 ...rustExtensions ( styles ) ,
40+ readOnly . of ( [ ] ) ,
3641 syncExtension ( file . data ) ,
3742 ] }
3843 onEditorMount = { ( editor ) => {
3944 editor . setTabFocusMode ( true ) ;
4045 syncExtensionListener ( editor , file . data . fullPath ) ;
46+
47+ observable ( projectAccess ) . subscribe ( ( access ) => {
48+ editor . dispatch ( {
49+ effects : readOnly . reconfigure (
50+ EditorState . readOnly . of ( access !== AccessLevel . Editor ) ,
51+ ) ,
52+ } ) ;
53+ } ) ;
4154 } }
4255 />
4356 ) ;
0 commit comments