Skip to content

Commit

Permalink
Synchronize with NotepadPlusPlusPluginPack.Net
Browse files Browse the repository at this point in the history
Synchronize with NotepadPlusPlusPluginPack.Net to eliminate the possibility that code difference was causing the crashing issue #67 (it was not)
  • Loading branch information
BdR76 committed May 16, 2023
1 parent 22ce562 commit 2b4d239
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
56 changes: 30 additions & 26 deletions CSVLintNppPlugin/PluginInfrastructure/GatewayDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,14 @@ public Colour(int rgb)
Blue = (rgb >> 16) & 0xFF;
}

/// <summary>
///
/// </summary>
/// <param name="red">a number 0-255</param>
/// <param name="green">a number 0-255</param>
/// <param name="blue">a number 0-255</param>
public Colour(int red, int green, int blue)
{
if(red > 255 || red < 0)
throw new ArgumentOutOfRangeException("red", "must be 0-255");
if(green > 255 || green < 0)
throw new ArgumentOutOfRangeException("green", "must be 0-255");
if(blue > 255 || blue < 0)
throw new ArgumentOutOfRangeException("blue", "must be 0-255");
public Colour(byte red, byte green, byte blue)
{
Red = red;
Green = green;
Blue = blue;
}

public int Value
{
get { return Red + (Green << 8) + (Blue << 16); }
}
public int Value => Red + (Green << 8) + (Blue << 16);
}

/// <summary>
Expand Down Expand Up @@ -145,6 +130,9 @@ public override bool Equals(object obj)
return Equals((Position)obj);
}

public static implicit operator Position(int i) => new Position(i);
public static implicit operator int(Position i) => i.pos;

public override int GetHashCode()
{
return pos;
Expand Down Expand Up @@ -189,7 +177,17 @@ public int Value
[StructLayout(LayoutKind.Sequential)]
public struct CharacterRange
{
public CharacterRange(int cpmin, int cpmax) { cpMin = cpmin; cpMax = cpmax; }
public CharacterRange(IntPtr cpmin, IntPtr cpmax) { cpMin = cpmin; cpMax = cpmax; }
public IntPtr cpMin;
public IntPtr cpMax;
}

/// <summary>
/// This is used before N++ 8.3
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct CharacterRangeLegacy
{
public int cpMin;
public int cpMax;
}
Expand All @@ -211,16 +209,18 @@ public class TextRange : IDisposable
IntPtr _ptrSciTextRange;
bool _disposed = false;

public TextRange(CharacterRange chrRange, int stringCapacity)
{
_sciTextRange.chrg = chrRange;
_sciTextRange.lpstrText = Marshal.AllocHGlobal(stringCapacity);
}
public TextRange(int cpmin, int cpmax, int stringCapacity)
public TextRange(CharacterRange chrRange, long stringCapacity)
: this(chrRange.cpMin, chrRange.cpMax, stringCapacity)
{ }

public TextRange(IntPtr cpmin, IntPtr cpmax, long stringCapacity = 0)
{
// The capacity must be _at least_ the given range plus one
stringCapacity = Math.Max(stringCapacity, Math.Abs(cpmax.ToInt64() - cpmin.ToInt64()) + 1);

_sciTextRange.chrg.cpMin = cpmin;
_sciTextRange.chrg.cpMax = cpmax;
_sciTextRange.lpstrText = Marshal.AllocHGlobal(stringCapacity);
_sciTextRange.lpstrText = Marshal.AllocHGlobal(new IntPtr(stringCapacity));
}

[StructLayout(LayoutKind.Sequential)]
Expand All @@ -229,10 +229,14 @@ struct Sci_TextRange
public CharacterRange chrg;
public IntPtr lpstrText;
}

public IntPtr NativePointer { get { _initNativeStruct(); return _ptrSciTextRange; } }

public string lpstrText { get { _readNativeStruct(); return Marshal.PtrToStringAnsi(_sciTextRange.lpstrText); } }

public CharacterRange chrg { get { _readNativeStruct(); return _sciTextRange.chrg; } set { _sciTextRange.chrg = value; _initNativeStruct(); } }


void _initNativeStruct()
{
if (_ptrSciTextRange == IntPtr.Zero)
Expand Down
2 changes: 1 addition & 1 deletion CSVLintNppPlugin/PluginInfrastructure/IScintillaGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ public interface IScintillaGateway
/// line is a header and whether it is effectively white space.
/// (Scintilla feature 2222)
/// </summary>
void SetFoldLevel(int line, int level);
void SetFoldLevel(int line, FoldLevel level);

/// <summary>Retrieve the fold level of a line. (Scintilla feature 2223)</summary>
FoldLevel GetFoldLevel(int line);
Expand Down
4 changes: 2 additions & 2 deletions CSVLintNppPlugin/PluginInfrastructure/ScintillaGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ public unsafe void SetText(string text)
/// </summary>
public unsafe string GetText(int length)
{
byte[] textBuffer = new byte[10000];
byte[] textBuffer = new byte[length];
fixed (byte* textPtr = textBuffer)
{
Win32.SendMessage(scintilla, SciMsg.SCI_GETTEXT, (IntPtr) length, (IntPtr) textPtr);
Expand Down Expand Up @@ -2036,7 +2036,7 @@ public int WrapCount(int docLine)
/// line is a header and whether it is effectively white space.
/// (Scintilla feature 2222)
/// </summary>
public void SetFoldLevel(int line, int level)
public void SetFoldLevel(int line, FoldLevel level)
{
Win32.SendMessage(scintilla, SciMsg.SCI_SETFOLDLEVEL, (IntPtr) line, (IntPtr) level);
}
Expand Down
2 changes: 1 addition & 1 deletion CSVLintNppPlugin/PluginInfrastructure/Scintilla_iface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3230,7 +3230,7 @@ public TextToFind(CharacterRange chrRange, string searchText)
/// <param name="cpmin">range to search</param>
/// <param name="cpmax">range to search</param>
/// <param name="searchText">the search pattern</param>
public TextToFind(int cpmin, int cpmax, string searchText)
public TextToFind(IntPtr cpmin, IntPtr cpmax, string searchText)
{
_sciTextToFind.chrg.cpMin = cpmin;
_sciTextToFind.chrg.cpMax = cpmax;
Expand Down

0 comments on commit 2b4d239

Please sign in to comment.