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

Loading a file as Document makes StartStyling() and SetStyling() break after text is inserted or deleted by user #94

Closed
HTD opened this issue Jul 26, 2015 · 2 comments
Labels

Comments

@HTD
Copy link

HTD commented Jul 26, 2015

https://github.com/HTD/TraxCodeEditor/tree/master/Test1

The test (Test1 project) uses signed ScintillaNET 3.5.0 from Nuget package.
It sets up 2 identical Scintilla instances, configures exactly one highlighting style, loads a short text into both instances but using different methods. The text using ASCII encoding to reject any encoding issues.

Left instance's text is loaded by assigning its Text property. Right instance's text is loaded using Scintilla.ILoader instance.

Both editors are set up to highlight the word "FOX" on each UI update.

Then I simulate of adding and deleting some characters from both editors. I delete all I insert, so the text in both editors should not be changed, and so their highlighting shouldn't change.

Expected behavior: identical text and highlighting on both sides.
Observed behavior: highlighting of the last line in the right editor is moved incorrectly.

issue94

@jacobslusser
Copy link
Owner

I believe this is an issue with the native Scintilla component. I've opened a ticket for that team to take a look:

https://sourceforge.net/p/scintilla/bugs/1745/

To summarize, the delete notification doesn't appear to be working correctly when the text being deleted was added via the Scintilla.ILoader. You can verify this by watching the Scintilla.Delete event. The result is that the byte-to-char translation layer in ScintillaNET is getting out of sync.

@HTD
Copy link
Author

HTD commented Jul 29, 2015

So I've read the guy's answer. I added UndoCollection = true after loading document and now it works. I'm not sure, but it's probably not a bug, OR... Maybe ScinntillaNET should ensure UndoCollection is true in Document setter?

This seems like the right thing to do (in Document setter):

var ptr = value.Value;
DirectMessage(NativeMethods.SCI_SETDOCPOINTER, IntPtr.Zero, ptr);
DirectMessage(NativeMethods.SCI_SETCODEPAGE, new IntPtr(NativeMethods.SC_CP_UTF8)); // see issue #87
DirectMessage(NativeMethods.SCI_SETUNDOCOLLECTION, new IntPtr(1));

I'm not sure if this should not lead to another issue:
I've noticed when assignment to Document is made - many Scintilla properties are reset and thus out of sync with ScintillaNET properties. Therefore we should reset them on each assignment. For now I see the following 4 of them: internal encoding, UndoCollection, TabWidth and UseTabs.

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