Closed DeepTulip closed 1 year ago
It just load the file content, if the file is saved in another process, Notepad2 should reload it again with the updated content.
Yes, Notepad2 just loads the file, and the real content of the file is:
test(t) {
MsgBox "test"
}
But reloading it will not show the few characters on the front end, which becomes this:
t(t) {
MsgBox "test"
}
If the text is modified at this point, the currently displayed characters will overwrite the real file, and thus the file becomes:
t(t) {
MsgBox "test"
}
This is a long-standing bug. But since Notepad2 is not my main editor, I just use it for a quick look at the text. But when I started using it more often and configured the formatting tool (which formats files from the background), the problem became serious and many files were corrupted.
Looks like subsequent changes not detected (file not reloaded), please check "Detect file change by polling instead of notification" on "File Change Notification" dialog (we may need a better description for the option).
This is what happens when the "Detect file change by polling instead of notification" option is enabled.
This is what happens when the "Detect file change by polling instead of notification" option is enabled.
Oh, what happens after turn off it?
It's the same when it's closed. My understanding of this option is that it is used to discover file changes. In the GIF, Notepad2 has apparently found the changes and re-read the file (it already shows the formatted text), so it shouldn't be a problem with this option.
By the way, the same formatting tool (modifying the file in the background), the same file (test.ahk), both EmEditor and vs code were able to display the changed file immediately and correctly.
Hi @DeepTulip, can you share how to setup your background formatting tool? I can try to reproduce the problem.
Use AutoHotkey.exe to load this code:
try
FileDelete path := A_Temp "/test.ahk"
n2 := "D:\Notepad2\Notepad2.exe"
FileAppend 'test(t){`nMsgBox "test"`n}`n', path, "utf-8"
Sleep 200
Run(n2 " " path)
Sleep 700
fo := FileOpen(path, "rw"), fo.Encoding := "UTF-8"
fo.Length := 0, fo.Pos := 0, fo.Write('test(t){`n`tMsgBox "test"`n}`n')
fo.Close()
MsgBox "end"
It works on second run without FileDelete
.
Fixed by e632ff20096b54f0e6b8bec73cd83d14bb3d639d (tes
is incorrectly treated as BOM on reloading), please download and test latest builds from https://github.com/zufuliu/notepad2/actions.
This is just as I suspected. Thank you very much.
When a file is modified by another process, notepad2 automatically updates the contents, which can lose the first few characters. If you edit the text at this point, these characters will be completely lost.
↓↓↓
WIN 10 64 FILE UTF-8
Notepad2 (64-bit) 4.23.06 r4862 (d53367e0) Compiled on Jun 18 2023 with Visual C++ 19.36.32534.0, Scintilla 5.3.5. Encoding: UTF-8 BOM, GBK Scheme: .ahk, AutoHotkey Script System: 10.0.19045 x64