darabos commited on
Commit
035da30
·
1 Parent(s): f4c0ab7

Always use Linux line endings in Monaco.

Browse files
lynxkite-app/src/lynxkite_app/crdt.py CHANGED
@@ -100,7 +100,7 @@ class CodeWebsocketServer(WorkspaceWebsocketServer):
100
  if len(text) == 0:
101
  if os.path.exists(name):
102
  with open(name, encoding="utf-8") as f:
103
- text += f.read()
104
  room = pycrdt_websocket.YRoom(
105
  ystore=ystore, ydoc=ydoc, exception_handler=ws_exception_handler
106
  )
@@ -279,9 +279,9 @@ async def execute(name: str, ws_crdt: pycrdt.Map, ws_pyd: workspace.Workspace, d
279
 
280
 
281
  async def code_changed(name: str, changes: pycrdt.TextEvent, text: pycrdt.Text):
282
- text = text.strip() + "\n"
283
  with open(name, "w", encoding="utf-8") as f:
284
- f.write(text)
285
 
286
 
287
  @contextlib.asynccontextmanager
 
100
  if len(text) == 0:
101
  if os.path.exists(name):
102
  with open(name, encoding="utf-8") as f:
103
+ text += f.read().replace("\r\n", "\n")
104
  room = pycrdt_websocket.YRoom(
105
  ystore=ystore, ydoc=ydoc, exception_handler=ws_exception_handler
106
  )
 
279
 
280
 
281
  async def code_changed(name: str, changes: pycrdt.TextEvent, text: pycrdt.Text):
282
+ contents = str(text).strip() + "\n"
283
  with open(name, "w", encoding="utf-8") as f:
284
+ f.write(contents)
285
 
286
 
287
  @contextlib.asynccontextmanager
lynxkite-app/web/src/Code.tsx CHANGED
@@ -54,6 +54,7 @@ export default function Code() {
54
  path!,
55
  yDocRef.current,
56
  );
 
57
  monacoBindingRef.current = new yMonacoRef.current.MonacoBinding(
58
  text,
59
  editorRef.current.getModel()!,
 
54
  path!,
55
  yDocRef.current,
56
  );
57
+ editorRef.current.getModel()!.setEOL(0); // https://github.com/yjs/y-monaco/issues/6
58
  monacoBindingRef.current = new yMonacoRef.current.MonacoBinding(
59
  text,
60
  editorRef.current.getModel()!,