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

Fixed bug in CreateLoader, added encoding param. #84

Closed
wants to merge 3 commits into from
Closed

Fixed bug in CreateLoader, added encoding param. #84

wants to merge 3 commits into from

Conversation

HTD
Copy link

@HTD HTD commented Jul 20, 2015

There was no possibility of reading files with various encodings, I've added additional parameter to CreateLoader method which allows to do so. Tested, works.

@jacobslusser
Copy link
Owner

Your understanding of the encoding argument used in the ILoader ctor is incorrect. This value specifies what encoding to use when writing data to ScintillaNET, not reading data from a file.

When loading a file the general sequence you would follow is:
1). Read bytes/stream from disk (your application)
2). Convert bytes to characters using desired encoding (your application)
3). Add characters to Scintilla via AddData (your application)
4). Convert characters to Scintilla's internal encoding (ScintillaNET)

Your assumption is that the encoding used here is related to step 2, however, it is actually related to step 4. This encoding argument is used when converting characters to Scintilla's internal byte format--which should be of no concern for you (and is always UTF-8, BTW).

If that doesn't make sense, let me know and I'll try and explain it differently. But the short answer is that if you want to use a different encoding when loading a file, there is nothing we need to change in ScintillaNET to make that work. That is all a function of your application.

@HTD
Copy link
Author

HTD commented Jul 20, 2015

OK, my fault. There is however a weird behavior: when I try to use loader directly after the control was created - text is always corrupt. But when I load it again - it's correct. Then I noticed when I add "Document = Document.Empty" at the beginning of the code - it works. Document is loaded correctly from the first time. I'm not sure if it's a feature or a bug.

@jacobslusser
Copy link
Owner

No worries about the encoding stuff. :)

Regarding the text being corrupt when you first create the control... I'm unable to reproduce the issue. When I use the snippet from the Wiki article on a new control I don't have any problems with the text.

Can you provide a code sample that demonstrates the issue you're seeing?

@HTD
Copy link
Author

HTD commented Jul 21, 2015

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.

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

@jacobslusser
Copy link
Owner

I can confirm the issue using your test. I'm not sure yet what the cause is but I'll continue to investigate.

@jacobslusser jacobslusser reopened this Jul 21, 2015
@jacobslusser
Copy link
Owner

I created Issue #87 to track the resolution of this.

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

Successfully merging this pull request may close these issues.

2 participants