Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 5bbf16f

Browse files
committed
rewrite AppendTextAndMoveCursor
1 parent 0c48619 commit 5bbf16f

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

Visual Studio Project Template C#/PluginInfrastructure/IScintillaGateway.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ public interface INotepadPPGateway
99
void FileNew();
1010
}
1111

12-
/// <summary>
13-
/// This it the plugin-writers primary interface to Notepad++/Scintilla.
14-
/// It takes away all the complexity with command numbers and Int-pointer casting.
15-
///
16-
/// See http://www.scintilla.org/ScintillaDoc.html for further details.
17-
/// </summary>
18-
public interface IScintillaGateway
12+
/// <summary>
13+
/// This it the plugin-writers primary interface to Notepad++/Scintilla.
14+
/// It takes away all the complexity with command numbers and Int-pointer casting.
15+
///
16+
/// See http://www.scintilla.org/ScintillaDoc.html for further details.
17+
/// </summary>
18+
public interface IScintillaGateway
1919
{
2020
int GetSelectionLength();
21-
unsafe void AppendTextAndMoveCursor(string text);
21+
void AppendTextAndMoveCursor(string text);
2222

2323

2424

Visual Studio Project Template C#/PluginInfrastructure/ScintillaGateway.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public void FileNew()
1313
}
1414
}
1515

16-
/// <summary>
17-
/// This it the plugin-writers primary interface to Notepad++/Scintilla.
18-
/// It takes away all the complexity with command numbers and Int-pointer casting.
19-
///
20-
/// See http://www.scintilla.org/ScintillaDoc.html for further details.
21-
/// </summary>
16+
/// <summary>
17+
/// This it the plugin-writers primary interface to Notepad++/Scintilla.
18+
/// It takes away all the complexity with command numbers and Int-pointer casting.
19+
///
20+
/// See http://www.scintilla.org/ScintillaDoc.html for further details.
21+
/// </summary>
2222
public class ScintillaGateway : IScintillaGateway
2323
{
2424
private const int Unused = 0;
@@ -31,19 +31,15 @@ public ScintillaGateway(IntPtr scintilla)
3131
}
3232

3333
public int GetSelectionLength()
34+
public void AppendTextAndMoveCursor(string text)
3435
{
3536
var selectionLength = (int)Win32.SendMessage(scintilla, SciMsg.SCI_GETSELTEXT, Unused, Unused);
3637
return selectionLength;
38+
AppendText(text.Length, text);
39+
GotoPos(new Position(GetCurrentPos().Value + text.Length));
3740
}
3841

39-
public unsafe void AppendTextAndMoveCursor(string text)
4042
{
41-
byte[] buffer = Encoding.UTF8.GetBytes(text);
42-
fixed (byte* ptr = buffer)
43-
{
44-
Win32.SendMessage(scintilla, SciMsg.SCI_APPENDTEXT, buffer.Length, (IntPtr)ptr);
45-
GotoPos(new Position(GetCurrentPos().Value + buffer.Length));
46-
}
4743
}
4844

4945

0 commit comments

Comments
 (0)