Skip to content

Commit b48b419

Browse files
author
Yogesh Prajapati
committed
fix(v1.4.1): F5 Run File works again — fix AMD-loader script ordering + PTY routing
The Run File (F5) feature has been broken since the AMD-loader regression: 1. UMD libraries (xterm, xterm-addon-fit, mermaid, diff) loaded AFTER monaco-editor/vs/loader.js were eaten by Monaco's global define(), so window.Terminal was undefined and the integrated terminal silently failed to render. Reordered to load all UMD libs BEFORE vs/loader.js, matching the marked.umd.js pattern. 2. runCurrentFile() was spawning a separate cmd.exe via the run-command IPC and piping output to terminal id 0 — but the visible PowerShell terminal is a node-pty session with its own id, so output went nowhere. Now types the run command directly into the existing PTY, which gives live stdout/stderr in the visible panel and proper cwd. 3. CSP relaxed: worker-src adds 'self' (Monaco can now spawn its workerMain.js from file://, removing the "falling back to main thread, may cause UI freezes" warning). script-src adds 'unsafe-inline' so the inline mermaid.initialize() block executes. Verified: F5 on test.py now types `cd "<dir>"; python "<file>"` into the live PowerShell PTY and shows real Python output / tracebacks.
1 parent d6bfd53 commit b48b419

4 files changed

Lines changed: 28 additions & 15 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "notepp",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Note++ - A powerful text editor",
55
"main": "src/main.js",
66
"author": "Yogesh Prajapati",

src/index.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'; font-src 'self' data:; worker-src blob: data:; img-src 'self' data: blob:;">
5+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'; font-src 'self' data:; worker-src 'self' blob: data:; img-src 'self' data: blob:;">
66
<title>new 1 - Note++</title>
77
<link rel="stylesheet" href="style.css">
88
<link rel="stylesheet" href="../node_modules/xterm/css/xterm.css">
@@ -1099,10 +1099,16 @@ <h3>🔒 Encryption</h3>
10991099
}
11001100
</script>
11011101

1102-
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
1102+
<!-- All UMD libs MUST load BEFORE vs/loader.js — Monaco's AMD loader installs
1103+
a global define() that hijacks any UMD script loaded after it, causing
1104+
e.g. "Terminal is not defined" / "Can only have one anonymous define call". -->
11031105
<script src="../node_modules/xterm/lib/xterm.js"></script>
11041106
<script src="../node_modules/xterm-addon-fit/lib/xterm-addon-fit.js"></script>
11051107
<script src="../node_modules/mermaid/dist/mermaid.min.js"></script>
1108+
<script src="../node_modules/diff/dist/diff.min.js"></script>
1109+
1110+
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
1111+
11061112
<script>
11071113
// Initialize mermaid with startOnLoad:false so we control rendering
11081114
if (window.mermaid) {
@@ -1115,7 +1121,6 @@ <h3>🔒 Encryption</h3>
11151121
}
11161122
</script>
11171123
<script src="crypto.js"></script>
1118-
<script src="../node_modules/diff/dist/diff.min.js"></script>
11191124
<script src="lsp-client.js"></script>
11201125
<script src="renderer.js"></script>
11211126
</body>

src/renderer.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,12 +1894,13 @@ async function runCurrentFile() {
18941894
if (tab.dirty) await saveTabFile(tab);
18951895
if (!tab.filePath) { showToast('Save the file first'); return; }
18961896

1897-
openTerminal();
1898-
18991897
const fp = tab.filePath;
19001898
const ext = fp.split('.').pop().toLowerCase();
19011899
const cwd = fp.replace(/[\\/][^\\/]+$/, '');
19021900

1901+
// Per-extension runner. Each entry returns the command line to type into
1902+
// the integrated PTY (PowerShell on Windows). We deliberately reuse the
1903+
// existing terminal so the user sees live stdout/stderr in the same panel.
19031904
const runners = {
19041905
py: `python "${fp}"`, python: `python "${fp}"`,
19051906
js: `node "${fp}"`, mjs: `node "${fp}"`,
@@ -1909,8 +1910,9 @@ async function runCurrentFile() {
19091910
go: `go run "${fp}"`,
19101911
rs: `cargo run`,
19111912
sh: `bash "${fp}"`,
1912-
ps1: `powershell.exe -File "${fp}"`,
1913-
bat: `"${fp}"`,
1913+
ps1: `& "${fp}"`, // PowerShell call operator handles spaces in path
1914+
bat: `& "${fp}"`,
1915+
cmd: `& "${fp}"`,
19141916
java: `java "${fp}"`,
19151917
r: `Rscript "${fp}"`,
19161918
lua: `lua "${fp}"`,
@@ -1919,12 +1921,18 @@ async function runCurrentFile() {
19191921
const cmd = runners[ext];
19201922
if (!cmd) { showToast(`No runner configured for .${ext}`); return; }
19211923

1922-
if (term) {
1923-
term.writeln(`\x1b[33m> Running: ${cmd}\x1b[0m`);
1924-
term.writeln('');
1925-
}
1924+
// Open the terminal panel and wait for the PTY to actually be alive
1925+
// (terminalCreate is async — sending input before it resolves is a no-op).
1926+
await openTerminal();
1927+
// openTerminal returns immediately if the term already exists; if it just
1928+
// created one, the create IPC was fired inside a 50 ms setTimeout, so give
1929+
// it a beat before typing into the PTY on first launch.
1930+
await new Promise(r => setTimeout(r, 80));
19261931

1927-
await window.electronAPI.runCommand(cmd, cwd);
1932+
// PowerShell: cd to the file's folder, then run. `;` chains regardless of
1933+
// exit code so we always see the result. CR (\r) submits the line.
1934+
const line = `cd "${cwd}"; ${cmd}\r`;
1935+
await window.electronAPI.terminalInput(terminalId, line);
19281936
}
19291937

19301938
// ===== Status Bar =====

0 commit comments

Comments
 (0)