Skip to content

Commit c345132

Browse files
author
Sébastien Geiser
committed
Correction of SelectionStart
1 parent 3f7bd54 commit c345132

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

CSharpRegexTools4Npp/BNpp.cs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,12 @@ public static int SelectionStart
6464
{
6565
get
6666
{
67-
int curPos = (int)Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GETSELECTIONSTART, 0, 0);
68-
IScintillaGateway scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla());
69-
string beginingText = scintilla.GetText(curPos);
70-
string text = BEncoding.GetScintillaTextFromUtf8Text(beginingText, out int length);
71-
return length;
67+
return new ScintillaGateway(PluginBase.GetCurrentScintilla()).GetSelectionStart();
7268
}
7369

7470
set
7571
{
76-
string allText = Text;
77-
int startToUse = value;
78-
79-
if (value < 0)
80-
{
81-
startToUse = 0;
82-
}
83-
else if (value > allText.Length)
84-
{
85-
startToUse = allText.Length;
86-
}
87-
88-
string beforeText = allText.Substring(0, startToUse);
89-
string beforeTextInDefaultEncoding = BEncoding.GetScintillaTextFromUtf8Text(beforeText, out int defaultStart);
90-
91-
Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_SETSELECTIONSTART, defaultStart, 0);
72+
new ScintillaGateway(PluginBase.GetCurrentScintilla()).SetSelectionStart(new Position(value));
9273
}
9374
}
9475

@@ -155,8 +136,9 @@ public static string SelectedText
155136
{
156137
get
157138
{
158-
int start = SelectionStart;
159-
int end = SelectionEnd;
139+
IScintillaGateway scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla());
140+
int start = scintillaGateway.GetSelectionStart().Value;
141+
int end = scintillaGateway.GetSelectionEnd().Value;
160142

161143
return end - start == 0 ? "" : Text.Substring(start, end - start);
162144
}

0 commit comments

Comments
 (0)