feat: Preserve UTF-8 BOM when editing files (Fix #1672)

- Add FileEncoding constants (UTF8, UTF8_BOM)
- Add detectFileBOM() to detect existing file encoding
- Modify writeTextFile() to support BOM option
- Add defaultFileEncoding configuration option
- Preserve BOM when editing existing files
- Use configured encoding for new files
- Add comprehensive tests (unit, integration, e2e)
- Update documentation

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
tanzhenxin 2026-02-01 10:32:20 +08:00
parent bd900d3668
commit 831d74dbfe
11 changed files with 472 additions and 16 deletions

View file

@ -244,6 +244,20 @@ const SETTINGS_SCHEMA = {
'Enable saving chat history to disk. Disabling this will also prevent --continue and --resume from working.',
showInDialog: false,
},
defaultFileEncoding: {
type: 'enum',
label: 'Default File Encoding',
category: 'General',
requiresRestart: false,
default: 'utf-8',
description:
'Default encoding for new files. Use "utf-8" (default) for UTF-8 without BOM, or "utf-8-bom" for UTF-8 with BOM. Only change this if your project specifically requires BOM.',
showInDialog: false,
options: [
{ value: 'utf-8', label: 'UTF-8 (without BOM)' },
{ value: 'utf-8-bom', label: 'UTF-8 with BOM' },
],
},
},
},
output: {