Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error displaying text when files are automatically updated #686

Closed
DeepTulip opened this issue Jul 17, 2023 · 12 comments
Closed

Error displaying text when files are automatically updated #686

DeepTulip opened this issue Jul 17, 2023 · 12 comments

Comments

@DeepTulip
Copy link

DeepTulip commented Jul 17, 2023

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.

20230718013900
↓↓↓
20230718013915


WIN 10 64
FILE UTF-8

Notepad2 (64-bit) 4.23.06 r4862 (d53367e)
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

@zufuliu
Copy link
Owner

zufuliu commented Jul 17, 2023

It just load the file content, if the file is saved in another process, Notepad2 should reload it again with the updated content.

@DeepTulip
Copy link
Author

DeepTulip commented Jul 17, 2023

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.

1

@zufuliu
Copy link
Owner

zufuliu commented Jul 17, 2023

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).

@DeepTulip
Copy link
Author

This is what happens when the "Detect file change by polling instead of notification" option is enabled.

@zufuliu
Copy link
Owner

zufuliu commented Jul 18, 2023

This is what happens when the "Detect file change by polling instead of notification" option is enabled.

Oh, what happens after turn off it?

@DeepTulip
Copy link
Author

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.

@DeepTulip
Copy link
Author

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.

@zufuliu
Copy link
Owner

zufuliu commented Jul 21, 2023

Hi @DeepTulip, can you share how to setup your background formatting tool? I can try to reproduce the problem.

@DeepTulip
Copy link
Author

DeepTulip commented Jul 21, 2023

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"

https://github.com/AutoHotkey/AutoHotkey/releases

@zufuliu
Copy link
Owner

zufuliu commented Jul 22, 2023

It works on second run without FileDelete.

@zufuliu
Copy link
Owner

zufuliu commented Jul 22, 2023

Fixed by e632ff2 (tes is incorrectly treated as BOM on reloading), please download and test latest builds from https://github.com/zufuliu/notepad2/actions.

@DeepTulip
Copy link
Author

This is just as I suspected. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants