diff --git a/services/code-server.nix b/services/code-server.nix index b21249b..2ded3f1 100644 --- a/services/code-server.nix +++ b/services/code-server.nix @@ -33,14 +33,25 @@ # Make the claude CLI available in code-server's integrated terminal. environment.systemPackages = [ pkgs.claude-code ]; - # Patch the Claude Code extension to add crossorigin="anonymous" to its - # stylesheet link — required for Firefox due to stricter CORS handling. - # Idempotent: sed won't match after the first apply. + # Patch the Claude Code extension for Firefox compatibility. + # Idempotent: sed patterns won't match after first apply. system.activationScripts.claude-code-firefox-fix.text = '' - for f in /home/fred/.local/share/code-server/extensions/anthropic.claude-code-*/extension.js; do - [ -f "$f" ] && ${pkgs.gnused}/bin/sed -i \ - 's|||' \ - "$f" + for d in /home/fred/.local/share/code-server/extensions/anthropic.claude-code-*/; do + [ -d "$d" ] || continue + # CORS fix: Firefox needs crossorigin on the stylesheet link. + ${pkgs.gnused}/bin/sed -i \ + 's|rel="stylesheet">|rel="stylesheet" crossorigin="anonymous">|g' \ + "$d/extension.js" + # Firefox contentEditable="plaintext-only" doesn't visually render + # newlines on Shift+Enter. Two fixes: + # 1. Intercept Shift+Enter to explicitly insert a line break. + ${pkgs.gnused}/bin/sed -i \ + 's|if(d.key==="Enter"&&!d.shiftKey)|if(d.key==="Enter"\&\&d.shiftKey){d.preventDefault();document.execCommand("insertLineBreak");T7();return}if(d.key==="Enter"\&\&!d.shiftKey)|' \ + "$d/webview/index.js" + # 2. Read innerText (converts
to \n) instead of textContent (ignores
). + ${pkgs.gnused}/bin/sed -i \ + 's|t\.current?.textContent|t.current?.innerText|g' \ + "$d/webview/index.js" done ''; };