Skip to content

Commit

Permalink
Поддержка предыдущей версии Scintilla
Browse files Browse the repository at this point in the history
Поддержка предыдущей версии Scintilla в GEttextRange
  • Loading branch information
vladk1973 authored Nov 17, 2022
1 parent 2c72f4c commit 746cfa3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
15 changes: 13 additions & 2 deletions lib/SciSupport.pas
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,25 @@ TSCNotification = record
end;

TCharacterRange = Record
cpMin : NativeInt;
cpMax : NativeInt;
cpMin : Integer;
cpMax : Integer;
end;
PTextRange = ^TTextRange;
TTextRange = Record
chrg : TCharacterRange;
lpstrText : LPSTR;
end;

TCharacterRangeV5 = Record
cpMin : NativeInt;
cpMax : NativeInt;
end;
PTextRangeV5 = ^TTextRangeV5;
TTextRangeV5 = Record
chrg : TCharacterRangeV5;
lpstrText : LPSTR;
end;

PTextToFind = ^TTextToFind;
TTextToFind = Record
chrg : TCharacterRange;
Expand Down
51 changes: 39 additions & 12 deletions lib/nppplugin.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1037,23 +1037,50 @@ function TNppPlugin.GetLine(const Line: Integer): AnsiString;

function TNppPlugin.GetTextRange(Range: TCharacterRange): AnsiString;
var pt: PTextRange; //Âîçâðàùàåò òåêñò âíóòðè ïåðåäàííîãî äèàïàçîíà
pt5: PTextRangeV5;
Size,StartSize: NativeInt;
S: AnsiString;
begin
StartSize := (Range.cpMax - Range.cpMin)+1;
GetMem(pt,SizeOf(TTextRange));
GetMem(pt^.lpstrText,StartSize);
try
pt^.chrg := Range;
Size :=Sci_Send(SCI_GETTEXTRANGEFULL,0,LPARAM(pt));
if HasV5Apis then Inc(Size);
SetLength(S,Size);
StrLCopy(PAnsiChar(S),pt^.lpstrText,Size);
finally
FreeMem(pt^.lpstrText,StartSize);
FreeMem(pt,SizeOf(TTextRange));
Result := S;

if HasV5Apis then
begin
GetMem(pt5,SizeOf(TTextRangeV5));
GetMem(pt5^.lpstrText,StartSize);
try
pt5^.chrg.cpMin := Range.cpMin;
pt5^.chrg.cpMax := Range.cpMax;
Size :=Sci_Send(SCI_GETTEXTRANGEFULL,0,LPARAM(pt5));
Inc(Size);
if Size>0 then
begin
SetLength(S,Size);
StrLCopy(PAnsiChar(S),pt5^.lpstrText,Size);
end;
finally
FreeMem(pt5^.lpstrText,StartSize);
FreeMem(pt5,SizeOf(TTextRangeV5));
end;
end
else
begin
GetMem(pt,SizeOf(TTextRange));
GetMem(pt^.lpstrText,StartSize);
try
pt^.chrg := Range;
Size :=Sci_Send(SCI_GETTEXTRANGE,0,LPARAM(pt));
if Size>0 then
begin
SetLength(S,Size);
StrLCopy(PAnsiChar(S),pt^.lpstrText,Size);
end;
finally
FreeMem(pt^.lpstrText,StartSize);
FreeMem(pt,SizeOf(TTextRange));
end;
end;

Result := S;
end;

procedure TNppPlugin.FuncInsertText(const S: AnsiString);
Expand Down

0 comments on commit 746cfa3

Please sign in to comment.