Skip to content

Commit cff0136

Browse files
committedNov 29, 2024
added settings item
1 parent 9418a61 commit cff0136

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wljs-editor",
3-
"version": "1.2.9",
3+
"version": "1.3.0",
44
"description": "WLJS Code editor",
55
"scripts": {
66
"build": "node --max-old-space-size=8192 ./node_modules/.bin/rollup --config rollup.config.mjs",

‎src/Frontend.wl

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ BeginPackage["Notebook`Editor`", {
77
"JerryI`Misc`Events`",
88
"JerryI`WLX`",
99
"JerryI`WLX`Importer`",
10+
"JerryI`WLX`WebUI`",
1011
"JerryI`Misc`WLJS`Transport`",
11-
"Notebook`Editor`FrontendObject`"
12+
"Notebook`Editor`FrontendObject`",
13+
"JerryI`Notebook`AppExtensions`"
1214
}]
1315

1416
NotebookEditorChannel::usage = "used to transfer extra events"
@@ -19,6 +21,11 @@ Begin["`Internal`"]
1921
truncatedTemplate = ImportComponent[ FileNameJoin[{$InputFileName // DirectoryName // ParentDirectory, "templates", "truncated.wlx"}] ];
2022
truncatedTemplate = truncatedTemplate["Data"->"``", "Size"->"``"];
2123

24+
AppExtensions`TemplateInjection["SettingsFooter"] = ImportComponent[ FileNameJoin[{$InputFileName // DirectoryName // ParentDirectory, "templates", "Settings.wlx"}] ];
25+
26+
{loadSettings, storeSettings} = ImportComponent["Frontend/Settings.wl"];
27+
settings = <||>;
28+
2229
NotebookEditorChannel = CreateUUID[];
2330

2431
rootFolder = $InputFileName // DirectoryName;
@@ -102,11 +109,13 @@ evaluator = StandardEvaluator["Name" -> "Wolfram Evaluator", "InitKernel" -> in
102109

103110
init[k_] := Module[{},
104111
Print["Kernel init..."];
105-
With[{channel = NotebookEditorChannel, tt = truncatedTemplate},
112+
loadSettings[settings];
113+
114+
With[{channel = NotebookEditorChannel, tt = truncatedTemplate, charLim = Lookup[settings, "OutputCharactersLimit", 6000]},
106115
Kernel`Init[k,
107116
Print["Init internal communication"];
108117
Internal`Kernel`TruncatedOutputTemplate = tt;
109-
Notebook`Editor`$OutputCharactersLimit = 5000;
118+
Notebook`Editor`$OutputCharactersLimit = charLim;
110119
Internal`Kernel`CommunicationChannel = Internal`Kernel`Stdout[channel];
111120
];
112121
];

‎templates/Settings.wlx

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
3+
4+
parseInt[any_String] := ToExpression[any]
5+
parseInt[any_] := any
6+
7+
8+
9+
Component[OptionsPattern[]] := Module[{tempBuffer}, With[{
10+
update = CreateUUID[],
11+
settings = OptionValue["Settings"],
12+
log = OptionValue["Messager"],
13+
onsave = OptionValue["OnSave"],
14+
controller = CreateUUID[],
15+
16+
initialValues = Join[<|
17+
"OutputCharactersLimit" -> 6000
18+
|>, OptionValue["Settings"]]
19+
},
20+
21+
EventHandler[controller, {
22+
"Charlim" -> Function[value,
23+
If[NumericQ[parseInt[value]],
24+
onsave[<|"OutputCharactersLimit" -> parseInt[value]|>];
25+
EventFire[log, Notifications`NotificationMessage["Info"](*`*), "Restart of a Kernel required"];
26+
,
27+
EventFire[Messager, Notifications`NotificationMessage["Warning"](*`*), "Not a valid number!"];
28+
];
29+
]
30+
}];
31+
32+
With[{lim = initialValues["OutputCharactersLimit"]},
33+
34+
<li class="list-none px-0 py-4 sm:px-0">
35+
<div class="px-4 sm:px-0 pb-3 border-b border-gray-100">
36+
<h3 class="text-base font-semibold leading-7 text-gray-900 dark:text-gray-300">Editor settings</h3>
37+
<p class="mt-1 max-w-2xl text-sm leading-6 text-gray-500 dark:text-gray-500"></p>
38+
</div>
39+
<div class="mt-4">
40+
<span class="dark:text-gray-400">Output form</span>
41+
<div class="pb-2 mt-2 mt-5 gap-y-2 flex flex-col">
42+
<p class="text-sm text-gray-500">Sets the maximum character limit for the output before the output cell is truncated.</p>
43+
<div class="rounded-md px-3 pb-3 pt-2.5 shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-indigo-600">
44+
<label for="characterslimit" class="block text-xs font-medium text-gray-900 dark:text-gray-400">Characters limit</label>
45+
<input type="number" value="{lim}" min="3000" max="50000" step="100" id="characterslimit" class="block w-full border-0 p-0 dark:bg-gray-700 text-gray-900 dark:text-gray-300 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"/>
46+
<WebUIEventListener Id={"characterslimit"} Type={"blur"} Event={controller} Pattern={"Charlim"}/>
47+
</div>
48+
</div>
49+
</div>
50+
</li>
51+
]
52+
]]
53+
54+
Component

0 commit comments

Comments
 (0)
Please sign in to comment.