Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Encoding error when first loading file #87

Closed
jacobslusser opened this issue Jul 21, 2015 · 2 comments
Closed

Encoding error when first loading file #87

jacobslusser opened this issue Jul 21, 2015 · 2 comments
Labels

Comments

@jacobslusser
Copy link
Owner

https://github.com/HTD/ScintillaNET/tree/master/Test

Here's the sample. It has to be cloned as whole project because of encoded test files.

After starting program - select any menu option - this would load one of the test files.
The correct text is "Zażółć gęślą jaźń.". But you will get something else - corrupt text.
Select any menu option again - you should see correct text. With any encoding option.
Uncomment line 20 in Test.cs ("scintilla1.Document = Document.Empty;")
Run program and select any option
Now text should be displayed correctly for each test from the first time.

@jacobslusser
Copy link
Owner Author

Upon closer examination, calling scintilla.Document = Document.Empty isn't really a fix. A side product of that call (and another bug) is that it is resetting the encoding used internally by Scintilla from UTF8 to the default. That gives the appearance that it is working but it actually isn't.

So in addition to determining what the underlying issue is, I believe I also have a fix to do when changing the document to make sure the encoding does not change.

@HTD
Copy link

HTD commented Jul 25, 2015

Looks like I found a real workaround for this: Scintilla.cs, added line 3503 (current version):

DirectMessage(NativeMethods.SCI_SETCODEPAGE, new IntPtr(NativeMethods.SC_CP_UTF8));

in Document setter. Now it works, I tested it with UTF-8 file which can't be encoded in default Windows encoding.

jacobslusser added a commit that referenced this issue Jul 30, 2015
The issue was that Scintilla stores some properties (e.g. Encoding) with
the document. Changing to a new document caused those properties to be
reset. This fix is to carry those properties over to the new document. A
related issue was that the UndoCollection property would get reset and
cause the SCN_MODIFIED notification to return null for the modified
text. This would cause the byte-to-char layer to get out of sync. Since
the UndoCollection property is so dangerous I removed it altogether.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants