Skip to content

Commit fda35ee

Browse files
author
Sébastien Geiser
committed
Better management of the length of text
1 parent a83c914 commit fda35ee

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

CSharpRegexTools4Npp/BNpp.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,16 @@ public static string Text
163163
get
164164
{
165165
IScintillaGateway scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla());
166-
return BEncoding.GetUtf8TextFromScintillaText(scintilla.GetText(scintilla.GetTextLength()));
166+
// Multiply by 2 to managed 2 bytes encoded chars
167+
return BEncoding.GetUtf8TextFromScintillaText(scintilla.GetText(scintilla.GetTextLength() * 2));
167168
}
168169

169170
set
170171
{
171172
IScintillaGateway scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla());
172173
scintilla.ClearAll();
173174
string text = BEncoding.GetScintillaTextFromUtf8Text(value, out int length);
174-
scintilla.AppendText(length, text);
175+
scintilla.SetText(text);
175176
}
176177
}
177178

CSharpRegexTools4Npp/PluginInfrastructure/ScintillaGateway.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ public unsafe void SetText(string text)
18021802
/// </summary>
18031803
public unsafe string GetText(int length)
18041804
{
1805-
byte[] textBuffer = new byte[10000];
1805+
byte[] textBuffer = new byte[length];
18061806
fixed (byte* textPtr = textBuffer)
18071807
{
18081808
IntPtr res = Win32.SendMessage(scintilla, SciMsg.SCI_GETTEXT, length, (IntPtr) textPtr);

0 commit comments

Comments
 (0)