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

Commit d02a417

Browse files
authored
Change int type for SCNotification Scintilla (#268)
Change int type for SCNotification Scintilla, linked to #261, #262 and #263
2 parents a778deb + fd0d15f commit d02a417

4 files changed

Lines changed: 27 additions & 27 deletions

File tree

3PA/NppCore/DocumentLines.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ private static SciApi Api {
107107
public void Reset() {
108108
Init();
109109
var scn = new SCNotification {
110-
linesAdded = SciGetLineCount() - 1,
111-
position = 0,
112-
length = SciGetLength()
110+
linesAdded = new IntPtr(SciGetLineCount() - 1),
111+
position = IntPtr.Zero,
112+
length = new IntPtr(SciGetLength())
113113
};
114-
scn.text = Api.Send(SciMsg.SCI_GETRANGEPOINTER, new IntPtr(scn.position), new IntPtr(scn.length));
114+
scn.text = Api.Send(SciMsg.SCI_GETRANGEPOINTER, scn.position, scn.length);
115115
OnScnModified(scn, true, Sci.Encoding);
116116
}
117117

@@ -153,16 +153,16 @@ public void OnScnModified(SCNotification scn, bool isInsertion, Encoding encodin
153153
/// </summary>
154154
/// <param name="scn"></param>
155155
private void OnDeletedText(SCNotification scn) {
156-
var startLine = SciLineFromPosition(scn.position);
157-
if (scn.linesAdded == 0) {
158-
var delCharLenght = GetCharCount(scn.text, scn.length);
156+
var startLine = SciLineFromPosition(scn.position.ToInt32());
157+
if (scn.linesAdded == IntPtr.Zero) {
158+
var delCharLenght = GetCharCount(scn.text, scn.length.ToInt32());
159159
SetHoleInLine(startLine, -delCharLenght);
160160
} else {
161161
var lineByteStart = SciPositionFromLine(startLine);
162162
var lineByteLength = SciLineLength(startLine);
163163
var delCharLenght = -(GetCharCount(lineByteStart, lineByteLength) - LineCharLength(startLine));
164164
FillTheHole();
165-
for (int i = 0; i < -scn.linesAdded; i++) {
165+
for (int i = 0; i < -scn.linesAdded.ToInt32(); i++) {
166166
delCharLenght += LineCharLength(startLine + 1);
167167
_linesList.RemoveAt(startLine + 1);
168168
}
@@ -176,9 +176,9 @@ private void OnDeletedText(SCNotification scn) {
176176
/// </summary>
177177
/// <param name="scn"></param>
178178
private void OnInsertedText(SCNotification scn) {
179-
var startLine = SciLineFromPosition(scn.position);
180-
if (scn.linesAdded == 0) {
181-
var insCharLenght = GetCharCount(scn.text, scn.length);
179+
var startLine = SciLineFromPosition(scn.position.ToInt32());
180+
if (scn.linesAdded == IntPtr.Zero) {
181+
var insCharLenght = GetCharCount(scn.text, scn.length.ToInt32());
182182
SetHoleInLine(startLine, insCharLenght);
183183
} else {
184184
var startCharPos = CharPositionFromLine(startLine);
@@ -187,7 +187,7 @@ private void OnInsertedText(SCNotification scn) {
187187
var lineCharLenght = GetCharCount(lineByteStart, lineByteLength);
188188
var insCharLenght = lineCharLenght - LineCharLength(startLine);
189189
FillTheHole();
190-
for (int i = 0; i < scn.linesAdded; i++) {
190+
for (int i = 0; i < scn.linesAdded.ToInt32(); i++) {
191191
startCharPos += lineCharLenght;
192192
var line = startLine + i + 1;
193193
lineByteStart += lineByteLength;
@@ -196,7 +196,7 @@ private void OnInsertedText(SCNotification scn) {
196196
insCharLenght += lineCharLenght;
197197
_linesList.Insert(line, startCharPos);
198198
}
199-
SetHoleInLine(startLine + scn.linesAdded, insCharLenght);
199+
SetHoleInLine(startLine + scn.linesAdded.ToInt32(), insCharLenght);
200200
FillTheHole();
201201

202202
// We should not have a null length, but we actually can :
@@ -205,7 +205,7 @@ private void OnInsertedText(SCNotification scn) {
205205
// so in that case, we need to refresh the info when the text is actually inserted, that is after updateui
206206
// Clarification : the notification sent is correct (nb lines > 0, length, text are ok), but calling SciLineLength
207207
// will always return 0 at this moment!
208-
if (scn.length > 0 && TextLength == 0)
208+
if (scn.length.ToInt32() > 0 && TextLength == 0)
209209
NotificationsPublisher.ActionsAfterUpdateUi.Enqueue(Reset);
210210
}
211211
}

3PA/NppCore/NotificationsPublisher.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,21 @@ public static void OnNppNotification(SCNotification nc) {
150150
}
151151

152152
// only 1 char appears to be modified
153-
if (nc.length <= 2) {
153+
if (nc.length.ToInt32() <= 2) {
154154
// get the char
155155
var bytes = (byte*) nc.text;
156-
var arrbyte = new byte[nc.length];
156+
var arrbyte = new byte[nc.length.ToInt32()];
157157
int index;
158-
for (index = 0; index < nc.length; index++)
158+
for (index = 0; index < nc.length.ToInt32(); index++)
159159
arrbyte[index] = bytes[index];
160160
var c = encoding.GetChars(arrbyte);
161161
var cLength = c.Length;
162162
// do we really have a 1 char input?
163163
if (cLength == 1 || (cLength == 2 && c[0] == '\r')) {
164164
if (insertedText) {
165-
ActionsAfterUpdateUi.Enqueue(() => Plug.OnCharAdded(c[0], nc.position));
165+
ActionsAfterUpdateUi.Enqueue(() => Plug.OnCharAdded(c[0], nc.position.ToInt32()));
166166
} else {
167-
ActionsAfterUpdateUi.Enqueue(() => Plug.OnCharDeleted(c[0], nc.position));
167+
ActionsAfterUpdateUi.Enqueue(() => Plug.OnCharDeleted(c[0], nc.position.ToInt32()));
168168
}
169169
singleCharModification = true;
170170
}
@@ -178,7 +178,7 @@ public static void OnNppNotification(SCNotification nc) {
178178

179179
case (uint) SciNotif.SCN_STYLENEEDED:
180180
// if we use the contained lexer, we will receive this notification and we will have to style the text
181-
Plug.OnStyleNeeded(Sci.GetEndStyled(), nc.position);
181+
Plug.OnStyleNeeded(Sci.GetEndStyled(), nc.position.ToInt32());
182182
return;
183183

184184
case (uint) SciNotif.SCN_MARGINCLICK:

3PA/NppCore/SciHeader.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ namespace _3PA.NppCore {
3737
[StructLayout(LayoutKind.Sequential)]
3838
public struct SCNotification {
3939
public Sci_NotifyHeader nmhdr;
40-
public int position; /* SCN_STYLENEEDED, SCN_MODIFIED, SCN_DWELLSTART, SCN_DWELLEND */
40+
public IntPtr position; /* SCN_STYLENEEDED, SCN_MODIFIED, SCN_DWELLSTART, SCN_DWELLEND */
4141
public int ch; /* SCN_CHARADDED, SCN_KEY */
4242
public int modifiers; /* SCN_KEY */
4343
public int modificationType; /* SCN_MODIFIED */
4444
public IntPtr text; /* SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION */
45-
public int length; /* SCN_MODIFIED */
46-
public int linesAdded; /* SCN_MODIFIED */
45+
public IntPtr length; /* SCN_MODIFIED */
46+
public IntPtr linesAdded; /* SCN_MODIFIED */
4747
public int message; /* SCN_MACRORECORD */
4848
public IntPtr wParam; /* SCN_MACRORECORD */
4949
public IntPtr lParam; /* SCN_MACRORECORD */
50-
public int line; /* SCN_MODIFIED */
50+
public IntPtr line; /* SCN_MODIFIED */
5151
public int foldLevelNow; /* SCN_MODIFIED */
5252
public int foldLevelPrev; /* SCN_MODIFIED */
5353
public int margin; /* SCN_MARGINCLICK */
5454
public int listType; /* SCN_USERLISTSELECTION */
5555
public int x; /* SCN_DWELLSTART, SCN_DWELLEND */
5656
public int y; /* SCN_DWELLSTART, SCN_DWELLEND */
5757
public int token; /* SCN_MODIFIED with SC_MOD_CONTAINER */
58-
public int annotationLinesAdded; /* SC_MOD_CHANGEANNOTATION */
58+
public IntPtr annotationLinesAdded; /* SC_MOD_CHANGEANNOTATION */
5959
public int updated; /* SCN_UPDATEUI */
6060
public int listCompletionMethod; /* SCN_AUTOCSELECTION, SCN_AUTOCCOMPLETED, SCN_USERLISTSELECTION */
6161

3PA/Plug.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,9 @@ public static void OnSciMarginClick(SCNotification nc) {
691691
// click on the error margin
692692
if (nc.margin == OpenedFilesInfo.ErrorMarginNumber) {
693693
// if it's an error symbol that has been clicked, the error on the line will be cleared
694-
if (!OpenedFilesInfo.ClearLineErrors(Sci.LineFromPosition(nc.position))) {
694+
if (!OpenedFilesInfo.ClearLineErrors(Sci.LineFromPosition(nc.position.ToInt32()))) {
695695
// if nothing has been cleared, we go to the next error position
696-
OpenedFilesInfo.GoToNextError(Sci.LineFromPosition(nc.position));
696+
OpenedFilesInfo.GoToNextError(Sci.LineFromPosition(nc.position.ToInt32()));
697697
}
698698
}
699699
}

0 commit comments

Comments
 (0)