Skip to content

Commit eb6f8f4

Browse files
committed
fixed CRLF on windows
1 parent 4025be7 commit eb6f8f4

5 files changed

Lines changed: 46 additions & 22 deletions

File tree

Components/ExtendedTopbar.wlx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ timedSaveButton[client_, localController_, controls_, parameters_] := With[{clon
5050

5151
taskFile = SetInterval[(
5252
EventFire[controls, "CheckFileHash", <|"Client"->client|>];
53-
), 3000];
53+
), 4000];
5454

5555
EventHandler[clonedControls, {"Save" -> Function[Null,
5656
EventFire[localController, "Reset", <|"Client"->client|>];

Components/Topbar.wlx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ timedSaveButton[client_, localController_, controls_, parameters_] := With[{clon
4848

4949
taskFile = SetInterval[(
5050
EventFire[controls, "CheckFileHash", <|"Client"->client|>];
51-
), 3000];
51+
), 4000];
5252

5353
reset;
5454

Kernel/FileFormat.wl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ BeginPackage["CoffeeLiqueur`Notebook`FileFormat`"];
33
readNotebook;
44
writeNotebook;
55

6-
endOfLine = EndOfLine;
6+
endOfLine = EndOfLine | "\r";
7+
newLine[1] = "\n" | "\r\n";
8+
newLine[2] = "\n\n" | "\r\n\r\n";
79

810
Begin["`Private`"];
911

@@ -301,7 +303,7 @@ readNotebook[stream_, timeout_:10] := Module[
301303
With[
302304
{
303305
testIfEnd = Function[p,
304-
StringMatchQ[ReadString[file, "\n", TimeConstraint -> timeout], StartOfString ~~ p ~~ "%" ~~ ___]
306+
StringMatchQ[ReadString[file, newLine[1], TimeConstraint -> timeout], StartOfString ~~ p ~~ "%" ~~ ___]
305307
]
306308
}
307309
,
@@ -341,7 +343,7 @@ readNotebook[stream_, timeout_:10] := Module[
341343
ReadString[
342344
file
343345
,
344-
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ "Cells" ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ "\n"..
346+
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ "Cells" ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ newLine[1]..
345347
,
346348
TimeConstraint -> timeout
347349
]
@@ -355,7 +357,7 @@ readNotebook[stream_, timeout_:10] := Module[
355357
ReadString[
356358
file
357359
,
358-
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ "\n"
360+
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ newLine[1]
359361
,
360362
TimeConstraint -> timeout
361363
]
@@ -366,7 +368,7 @@ readNotebook[stream_, timeout_:10] := Module[
366368
Return[$Failed]
367369
];
368370
temp = parseMiniYAML[StringTrim[temp]];
369-
buffer = ReadString[file, "\n\n" ~~ StartOfLine ~~ "%" ~~ Repeated["-", {16, 100}] ~~ "%", TimeConstraint -> timeout];
371+
buffer = ReadString[file, newLine[2] ~~ StartOfLine ~~ "%" ~~ Repeated["-", {16, 100}] ~~ "%", TimeConstraint -> timeout];
370372
If[FailureQ[buffer],
371373
Return[$Failed]
372374
];
@@ -378,7 +380,7 @@ readNotebook[stream_, timeout_:10] := Module[
378380
ReadString[
379381
file
380382
,
381-
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ "\n"
383+
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ newLine[1]
382384
,
383385
TimeConstraint -> timeout
384386
]
@@ -389,7 +391,7 @@ readNotebook[stream_, timeout_:10] := Module[
389391
Return[$Failed]
390392
];
391393
temp = parseMiniYAML[StringTrim[temp]];
392-
buffer = ReadString[file, "\n\n" ~~ StartOfLine ~~ "%" ~~ Repeated["-", {16, 100}] ~~ "%", TimeConstraint -> timeout];
394+
buffer = ReadString[file, newLine[2] ~~ StartOfLine ~~ "%" ~~ Repeated["-", {16, 100}] ~~ "%", TimeConstraint -> timeout];
393395
If[FailureQ[buffer],
394396
Return[$Failed]
395397
];
@@ -408,7 +410,7 @@ readNotebook[stream_, timeout_:10] := Module[
408410
ReadString[
409411
file
410412
,
411-
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ field ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ "\n"..
413+
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ field ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ newLine[1]..
412414
,
413415
TimeConstraint -> timeout
414416
]
@@ -422,7 +424,7 @@ readNotebook[stream_, timeout_:10] := Module[
422424
ReadString[
423425
file
424426
,
425-
(StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ "\n") | (StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%EndOf" ~~ field ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ "\n")
427+
(StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ newLine[1]) | (StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%EndOf" ~~ field ~~ "%" ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ newLine[1])
426428
,
427429
TimeConstraint -> timeout
428430
]
@@ -436,7 +438,7 @@ readNotebook[stream_, timeout_:10] := Module[
436438
keys[field] = Association[]; Continue[];
437439
];
438440
temp = parseMiniYAML[StringTrim[temp]];
439-
buffer = ReadString[file, "\n\n" ~~ StartOfLine ~~ "%" ~~ Repeated["-", {16, 100}] ~~ "%", TimeConstraint -> timeout];
441+
buffer = ReadString[file, newLine[2] ~~ StartOfLine ~~ "%" ~~ Repeated["-", {16, 100}] ~~ "%", TimeConstraint -> timeout];
440442
If[FailureQ[buffer],
441443
Return[$Failed]
442444
];
@@ -448,7 +450,7 @@ readNotebook[stream_, timeout_:10] := Module[
448450
ReadString[
449451
file
450452
,
451-
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ "\n"
453+
StartOfLine ~~ "%" ~~ Repeated["-", {17, 100}] ~~ Repeated["-", {17, 100}] ~~ "%" ~~ endOfLine ~~ newLine[1]
452454
,
453455
TimeConstraint -> timeout
454456
]
@@ -459,7 +461,7 @@ readNotebook[stream_, timeout_:10] := Module[
459461
Return[$Failed]
460462
];
461463
temp = parseMiniYAML[StringTrim[temp]];
462-
buffer = ReadString[file, "\n\n" ~~ StartOfLine ~~ "%" ~~ Repeated["-", {16, 100}] ~~ "%", TimeConstraint -> timeout];
464+
buffer = ReadString[file, newLine[2] ~~ StartOfLine ~~ "%" ~~ Repeated["-", {16, 100}] ~~ "%", TimeConstraint -> timeout];
463465
If[FailureQ[buffer],
464466
Return[$Failed]
465467
];

modules/wljs-editor/src/RemoteCells.wl

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ createNotebook[uid_] := With[{notebook = nb`NotebookObj["Hash" -> uid]},
2727
]
2828

2929
createNotebook[uid_, kernel_] := With[{notebook = nb`NotebookObj["Hash" -> uid]},
30-
notebook["Evaluator"] = kernel["Container"];
30+
notebook["AutoconnectKernel"] = kernel["Hash"];
3131
saveNotebook[Null, uid]
3232
]
3333

@@ -65,6 +65,28 @@ exportNotebook[notebook_, savingPath_, "wln"] := With[{stream = OpenWrite[saving
6565
Close[stream];
6666
]
6767

68+
saveNotebook[path_, uid_, kernelDir_] := With[{
69+
notebook = nb`HashMap[uid]
70+
},
71+
{
72+
savingPath = If[path === Null,
73+
If[StringQ[notebook["Path"] ],
74+
notebook["Path"],
75+
FileNameJoin[{$TemporaryDirectory, ((Internal`NoWR`RandomWord[])<>(Internal`NoWR`RandomWord[]))<>".wln"}]
76+
]
77+
,
78+
path
79+
]
80+
},
81+
SetDirectory[kernelDir];
82+
With[{res = exportNotebook[notebook, savingPath, FileExtension[savingPath] ] },
83+
ResetDirectory[];
84+
res
85+
]
86+
]
87+
88+
saveNotebook[path_, uid_, Null] := saveNotebook[path, uid]
89+
6890
saveNotebook[path_, uid_] := With[{
6991
notebook = nb`HashMap[uid]
7092
},
@@ -293,10 +315,10 @@ EventHandler[NotebookEditorChannel // EventClone,
293315
],
294316

295317
"CreateNotebook" -> Function[assoc,
296-
With[{ uid = assoc["Hash"]},
318+
With[{ uid = assoc["Hash"], kernel = GenericKernel`HashMap[assoc["Kernel"] ]},
297319
Echo["Creating notebook..."];
298320
With[{},
299-
createNotebook[uid];
321+
createNotebook[uid, kernel];
300322
saveNotebook[Null, uid];
301323
]
302324

@@ -327,10 +349,10 @@ EventHandler[NotebookEditorChannel // EventClone,
327349
],
328350

329351
"SaveNotebook" -> Function[assoc,
330-
With[{ uid = assoc["Hash"], path = assoc["Path"]},
352+
With[{ uid = assoc["Hash"], path = assoc["Path"], kernelDir = Lookup[assoc, "KernelDirectory", Null]},
331353
Echo["Saving notebook..."];
332354
With[{},
333-
saveNotebook[path, uid];
355+
saveNotebook[path, uid, kernelDir];
334356
]
335357

336358
];

modules/wljs-editor/src/RemoteCellsKernel.wl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,19 @@ NotebookOpen[path_ | File[path_], opts: OptionsPattern[] ] := With[{notebook = W
232232
Options[NotebookOpen] = {"Window" :> CurrentWindow[], Visible->True}
233233

234234
NotebookSave[RemoteNotebook[uid_] ] := (
235-
EventFire[Internal`Kernel`CommunicationChannel, "SaveNotebook", <|"Hash"->uid, "Path"->Null|>];
235+
EventFire[Internal`Kernel`CommunicationChannel, "SaveNotebook", <|"Hash"->uid, "Path"->Null, "KernelDirectory"->Directory[]|>];
236236
RemoteNotebook[uid]
237237
)
238238

239239
CreateNotebook[_] := CreateNotebook[]
240240

241241
CreateNotebook[] := With[{uid = CreateUUID[]},
242-
EventFire[Internal`Kernel`CommunicationChannel, "CreateNotebook", <|"Hash"->uid, "Path"->Null|>];
242+
EventFire[Internal`Kernel`CommunicationChannel, "CreateNotebook", <|"Hash"->uid, "Path"->Null, "Kernel"->Internal`Kernel`Hash|>];
243243
RemoteNotebook[uid]
244244
]
245245

246246
NotebookSave[RemoteNotebook[uid_], path_String | File[path_String] ] := (
247-
EventFire[Internal`Kernel`CommunicationChannel, "SaveNotebook", <|"Hash"->uid, "Path"->path|>];
247+
EventFire[Internal`Kernel`CommunicationChannel, "SaveNotebook", <|"Hash"->uid, "Path"->path, "KernelDirectory"->Directory[]|>];
248248
RemoteNotebook[uid]
249249
)
250250

0 commit comments

Comments
 (0)