CadQuery / CQ-editor

CadQuery GUI editor based on PyQT
Apache License 2.0
757 stars 116 forks source link

Attempt to use original encoding on save. Default to UTF-8 on new files (#351) #356

Closed voneiden closed 2 years ago

voneiden commented 2 years ago

There would also be the option to return None from determine_encoding and fallback to system default encoding but I'm not in favour of that. I support defaulting to UTF-8, as it's the de facto standard for editors. Even the classic notepad.exe switched from ANSI to UTF-8 default in Windows 10.

Related issues: #351 and #276

codecov[bot] commented 2 years ago

Codecov Report

Merging #356 (826a7b1) into master (4b461fe) will increase coverage by 0.06%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #356      +/-   ##
==========================================
+ Coverage   88.59%   88.65%   +0.06%     
==========================================
  Files          19       19              
  Lines        1490     1499       +9     
  Branches      204      205       +1     
==========================================
+ Hits         1320     1329       +9     
  Misses        137      137              
  Partials       33       33              
Impacted Files Coverage Δ
cq_editor/widgets/editor.py 96.27% <100.00%> (+0.22%) :arrow_up:

:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

adam-urbanczyk commented 2 years ago

Thanks @voneiden , should I merge?

voneiden commented 2 years ago

@adam-urbanczyk OK to merge on my behalf. I made a minor modification just now: I moved the encode outside of open block just in case to avoid the originally described issue where the file is emptied if encoding fails. Now such unexpected failure will happen before opening the file, preserving the contents.

adam-urbanczyk commented 2 years ago

Great, thanks @voneiden !