mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-06 03:38:26 +02:00
SynEdit, IDE: Fixes and Refactor for SynBeautifier (includes updates for codetools auto-indent)
git-svn-id: trunk@22377 -
This commit is contained in:
parent
85a6d9eae3
commit
65aa0e0875
@ -50,24 +50,37 @@ type
|
|||||||
// Callback for indent
|
// Callback for indent
|
||||||
TSynBeautifierSetIndentProc =
|
TSynBeautifierSetIndentProc =
|
||||||
procedure(
|
procedure(
|
||||||
LinePos: Integer;
|
(* LinePos:
|
||||||
Indent: Integer; // Indent in spaces (Logical = Physical)
|
1-based, the line that should be changed *)
|
||||||
RelativeToLinePos: Integer = 0; // Intend specifies +/- offset from intend on RTLine
|
LinePos: Integer;
|
||||||
// 0: for absolute indent
|
(* Indent:
|
||||||
IndentChars: String = ''; // use the following string to indent; maybe empty, single char, or string
|
New indent in spaces (Logical = Physical *)
|
||||||
IndentCharsFromLinePos: Integer = -1; // Line for tab/space mix; set to -1 if unknown
|
Indent: Integer;
|
||||||
KeepOldIndent: Boolean = False // True: Keep existing indent, and add (or subtract) new indent
|
(* RelativeToLinePos:
|
||||||
// False: old indent is stripped/replaced
|
Indent specifies +/- offset from indent on RTLine (0: for absolute indent) *)
|
||||||
|
RelativeToLinePos: Integer = 0;
|
||||||
|
(* IndentChars:
|
||||||
|
String used to build indent; maybe empty, single char, or string (usually 1 tab or 1 space)
|
||||||
|
The String will be repeated and cut as needed, then filled with spaces at the end
|
||||||
|
* NOTE: If this is specified the TSynBeautifierIndentType is ignored
|
||||||
|
*)
|
||||||
|
IndentChars: String = '';
|
||||||
|
(* IndentCharsFromLinePos:
|
||||||
|
Use tab/space mix from this Line for indent (if specified > 0)
|
||||||
|
"IndentChars" will only be used, if the found tab/space mix is to short
|
||||||
|
* NOTE: If this is specified the TSynBeautifierIndentType is ignored
|
||||||
|
*)
|
||||||
|
IndentCharsFromLinePos: Integer = 0
|
||||||
) of object;
|
) of object;
|
||||||
|
|
||||||
// Event triggered if Lines may needs Indend
|
// Event triggered if Lines may needs Indend
|
||||||
TSynBeautifierGetIndentEvent =
|
TSynBeautifierGetIndentEvent =
|
||||||
function(
|
function(
|
||||||
Sender: TSynCustomBeautifier; // the beautifier
|
Sender: TObject; // the beautifier
|
||||||
Editor: TObject; // the synedit
|
Editor: TObject; // the synedit
|
||||||
LogCaret: TPoint;
|
LogCaret, OldLogCaret: TPoint; // Caret after and before the edit action
|
||||||
var FirstLinePos, LastLinePos: Integer;// IF the function returns false, the beautifier shall calculate the indent
|
FirstLinePos, LastLinePos: Integer; // Changed lines. this can include lines outside the range of OldLogCaret to LogCaret
|
||||||
Reason: TSynEditorCommand; // what caused the evnt
|
Reason: TSynEditorCommand; // what caused the event
|
||||||
SetIndentProc: TSynBeautifierSetIndentProc
|
SetIndentProc: TSynBeautifierSetIndentProc
|
||||||
): boolean of object;
|
): boolean of object;
|
||||||
|
|
||||||
@ -121,18 +134,17 @@ type
|
|||||||
procedure DoAfterCommand(const ACaret: TSynEditCaret;
|
procedure DoAfterCommand(const ACaret: TSynEditCaret;
|
||||||
var Command: TSynEditorCommand;
|
var Command: TSynEditorCommand;
|
||||||
StartLinePos, EndLinePos: Integer); override;
|
StartLinePos, EndLinePos: Integer); override;
|
||||||
function GetIntend(const LinePos: Integer; out BasedOnLine: Integer): Integer;
|
function GetIndent(const LinePos: Integer; out BasedOnLine: Integer): Integer;
|
||||||
function AdjustCharMix(Indent: Integer; CharMix, OldCharMix: String): String;
|
function AdjustCharMix(DesiredIndent: Integer; CharMix, AppendMix: String): String;
|
||||||
function GetCharMix(const LinePos, Indent: Integer; const OldIndent: string;
|
function GetCharMix(const LinePos, Indent: Integer;
|
||||||
var IndentCharsFromLinePos: Integer = 0): String;
|
var IndentCharsFromLinePos: Integer = 0): String;
|
||||||
procedure ApplyIndent(LinePos: Integer; Indent: Integer;
|
procedure ApplyIndent(LinePos: Integer; Indent: Integer;
|
||||||
RelativeToLinePos: Integer = 0; IndentChars: String = '';
|
RelativeToLinePos: Integer = 0; IndentChars: String = '';
|
||||||
IndentCharsFromLinePos: Integer = -1;
|
IndentCharsFromLinePos: Integer = 0);
|
||||||
KeepOldIndent: Boolean = False);
|
|
||||||
function UnIndentLine(const ACaret: TSynEditCaret; out CaretNewX: Integer): Boolean;
|
function UnIndentLine(const ACaret: TSynEditCaret; out CaretNewX: Integer): Boolean;
|
||||||
public
|
public
|
||||||
procedure Assign(Src: TPersistent); override;
|
procedure Assign(Src: TPersistent); override;
|
||||||
function GetCurrentIndent(Editor: TSynEditBase; const Line: string;
|
function GetIndentForLine(Editor: TSynEditBase; const Line: string;
|
||||||
Physical: boolean): Integer;
|
Physical: boolean): Integer;
|
||||||
function GetDesiredIndentForLine
|
function GetDesiredIndentForLine
|
||||||
(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||||
@ -223,7 +235,7 @@ begin
|
|||||||
(ACaret.CharPos > 1) and
|
(ACaret.CharPos > 1) and
|
||||||
( (not TSynEdit(FCurrentEditor).SelAvail) or
|
( (not TSynEdit(FCurrentEditor).SelAvail) or
|
||||||
(eoPersistentBlock in TSynEdit(FCurrentEditor).Options2) ) and
|
(eoPersistentBlock in TSynEdit(FCurrentEditor).Options2) ) and
|
||||||
(GetCurrentIndent(FCurrentEditor, ACaret.LineText, True) = ACaret.CharPos - 1)
|
(GetIndentForLine(FCurrentEditor, ACaret.LineText, True) = ACaret.CharPos - 1)
|
||||||
then begin
|
then begin
|
||||||
UnIndentLine(ACaret, x);
|
UnIndentLine(ACaret, x);
|
||||||
ACaret.CharPos := x;
|
ACaret.CharPos := x;
|
||||||
@ -240,8 +252,9 @@ begin
|
|||||||
if EndLinePos < 1 then
|
if EndLinePos < 1 then
|
||||||
exit;
|
exit;
|
||||||
if assigned(FOnGetDesiredIndent) and
|
if assigned(FOnGetDesiredIndent) and
|
||||||
FOnGetDesiredIndent(self, FCurrentEditor, ACaret.LineBytePos, StartLinePos,
|
FOnGetDesiredIndent(self, FCurrentEditor, ACaret.LineBytePos,
|
||||||
EndLinePos, Command, @ApplyIndent)
|
ACaret.OldLineBytePos, StartLinePos, EndLinePos, Command,
|
||||||
|
@ApplyIndent)
|
||||||
then
|
then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
@ -251,14 +264,13 @@ begin
|
|||||||
else
|
else
|
||||||
y := ACaret.LinePos + 1;
|
y := ACaret.LinePos + 1;
|
||||||
|
|
||||||
if (Command = ecLineBreak) and
|
if (FCurrentLines[y-2] = '') and (FCurrentLines[y-1] <> '') then
|
||||||
(FCurrentLines[y-2] = '') and (FCurrentLines[y-1] <> '')
|
|
||||||
then
|
|
||||||
Indent := 0
|
Indent := 0
|
||||||
else
|
else
|
||||||
Indent := GetIntend(y, b);
|
Indent := GetIndent(y, b);
|
||||||
|
|
||||||
if Indent > 0 then begin
|
if Indent > 0 then begin
|
||||||
s := GetCharMix(y, Indent, '', b);
|
s := GetCharMix(y, Indent, b);
|
||||||
if (FIndentType = sbitPositionCaret) and (FCurrentLines[y-1] = '') then
|
if (FIndentType = sbitPositionCaret) and (FCurrentLines[y-1] = '') then
|
||||||
s := '';
|
s := '';
|
||||||
FCurrentLines.EditInsert(1, y, s);
|
FCurrentLines.EditInsert(1, y, s);
|
||||||
@ -281,13 +293,13 @@ var
|
|||||||
Line, Temp: String;
|
Line, Temp: String;
|
||||||
begin
|
begin
|
||||||
Line := ACaret.LineText;
|
Line := ACaret.LineText;
|
||||||
SpaceCount1 := GetCurrentIndent(FCurrentEditor, Line, true);
|
SpaceCount1 := GetIndentForLine(FCurrentEditor, Line, true);
|
||||||
SpaceCount2 := 0;
|
SpaceCount2 := 0;
|
||||||
if (SpaceCount1 > 0) then begin
|
if (SpaceCount1 > 0) then begin
|
||||||
BackCounter := ACaret.LinePos - 2;
|
BackCounter := ACaret.LinePos - 2;
|
||||||
while BackCounter >= 0 do begin
|
while BackCounter >= 0 do begin
|
||||||
Temp := FCurrentLines[BackCounter];
|
Temp := FCurrentLines[BackCounter];
|
||||||
SpaceCount2 := GetCurrentIndent(FCurrentEditor, Temp, true);
|
SpaceCount2 := GetIndentForLine(FCurrentEditor, Temp, true);
|
||||||
if (SpaceCount2 < SpaceCount1) and (temp <> '') then
|
if (SpaceCount2 < SpaceCount1) and (temp <> '') then
|
||||||
break;
|
break;
|
||||||
Dec(BackCounter);
|
Dec(BackCounter);
|
||||||
@ -303,7 +315,7 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSynBeautifier.GetIntend(const LinePos: Integer; out BasedOnLine: Integer): Integer;
|
function TSynBeautifier.GetIndent(const LinePos: Integer; out BasedOnLine: Integer): Integer;
|
||||||
var
|
var
|
||||||
Temp: string;
|
Temp: string;
|
||||||
begin
|
begin
|
||||||
@ -312,36 +324,39 @@ begin
|
|||||||
dec(BasedOnLine);
|
dec(BasedOnLine);
|
||||||
Temp := FCurrentLines[BasedOnLine];
|
Temp := FCurrentLines[BasedOnLine];
|
||||||
if Temp <> '' then begin
|
if Temp <> '' then begin
|
||||||
Result := GetCurrentIndent(FCurrentEditor, Temp, True);
|
Result := GetIndentForLine(FCurrentEditor, Temp, True);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
BasedOnLine := LinePos;
|
BasedOnLine := LinePos;
|
||||||
Result := GetCurrentIndent(FCurrentEditor, FCurrentLines[BasedOnLine], True);
|
Result := GetIndentForLine(FCurrentEditor, FCurrentLines[BasedOnLine], True);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSynBeautifier.AdjustCharMix(Indent: Integer; CharMix, OldCharMix: String): String;
|
function TSynBeautifier.AdjustCharMix(DesiredIndent: Integer; CharMix, AppendMix: String): String;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
CurLen: Integer;
|
||||||
begin
|
begin
|
||||||
while (GetCurrentIndent(FCurrentEditor, CharMix + OldCharMix, True) < Indent) do
|
CurLen := FCurrentLines.LogicalToPhysicalCol(CharMix, -1, length(CharMix)+1) - 1; // TODO: Need the real index of the line
|
||||||
if (CharMix <> '') then
|
if AppendMix <> '' then begin
|
||||||
CharMix := CharMix + CharMix[length(CharMix)]
|
while CurLen < DesiredIndent do begin
|
||||||
else
|
CharMix := CharMix + AppendMix;
|
||||||
CharMix := CharMix + ' ';
|
CurLen := FCurrentLines.LogicalToPhysicalCol(CharMix, -1, length(CharMix)+1) - 1; // TODO: Need the real index of the line
|
||||||
// too long, maybe too many tabs
|
end
|
||||||
while (CharMix <> '') and
|
end;
|
||||||
(GetCurrentIndent(FCurrentEditor, CharMix + OldCharMix, True) > Indent)
|
|
||||||
do
|
i := length(CharMix);
|
||||||
SetLength(CharMix, Length(CharMix) - 1);
|
while CurLen > DesiredIndent do begin
|
||||||
i := GetCurrentIndent(FCurrentEditor, CharMix + OldCharMix, True) - Indent;
|
Dec(i);
|
||||||
if i > 0 then
|
CurLen := FCurrentLines.LogicalToPhysicalCol(CharMix, -1, i+1) - 1; // TODO: Need the real index of the line
|
||||||
CharMix := CharMix + StringOfChar(' ', i);
|
end;
|
||||||
|
|
||||||
|
CharMix := copy(CharMix, 1, i) + StringOfChar(' ', DesiredIndent - CurLen);
|
||||||
Result := CharMix;
|
Result := CharMix;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSynBeautifier.GetCharMix(const LinePos, Indent: Integer;
|
function TSynBeautifier.GetCharMix(const LinePos, Indent: Integer;
|
||||||
const OldIndent: string; var IndentCharsFromLinePos: Integer = 0): String;
|
var IndentCharsFromLinePos: Integer = 0): String;
|
||||||
var
|
var
|
||||||
Temp, KnownMix, BasedMix: string;
|
Temp, KnownMix, BasedMix: string;
|
||||||
KnownPhysLen, PhysLen: Integer;
|
KnownPhysLen, PhysLen: Integer;
|
||||||
@ -349,28 +364,27 @@ var
|
|||||||
begin
|
begin
|
||||||
if FIndentType <> sbitCopySpaceTab then begin
|
if FIndentType <> sbitCopySpaceTab then begin
|
||||||
IndentCharsFromLinePos := 0;
|
IndentCharsFromLinePos := 0;
|
||||||
KnownMix := StringOfChar(' ', Indent - Length(OldIndent)); // OldIndent is expected Space, tab only; no multibyte UTF8
|
Result := StringOfChar(' ', Indent);
|
||||||
Result := AdjustCharMix(Indent, KnownMix, OldIndent);
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (IndentCharsFromLinePos > 0) and (IndentCharsFromLinePos <= FCurrentLines.Count) then
|
if (IndentCharsFromLinePos > 0) and (IndentCharsFromLinePos <= FCurrentLines.Count) then
|
||||||
begin
|
begin
|
||||||
Temp := FCurrentLines[IndentCharsFromLinePos];
|
Temp := FCurrentLines[IndentCharsFromLinePos];
|
||||||
KnownMix := copy(Temp, 1, GetCurrentIndent(FCurrentEditor, Temp, False));
|
KnownMix := copy(Temp, 1, GetIndentForLine(FCurrentEditor, Temp, False));
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
KnownMix := '';
|
KnownMix := '';
|
||||||
BasedMix := KnownMix;
|
BasedMix := KnownMix;
|
||||||
KnownPhysLen := GetCurrentIndent(FCurrentEditor, KnownMix + OldIndent, True);
|
KnownPhysLen := GetIndentForLine(FCurrentEditor, KnownMix, True);
|
||||||
|
|
||||||
BackCounter := LinePos;
|
BackCounter := LinePos;
|
||||||
while (BackCounter > 0) and (KnownPhysLen < Indent) do begin
|
while (BackCounter > 0) and (KnownPhysLen < Indent) do begin
|
||||||
dec(BackCounter);
|
dec(BackCounter);
|
||||||
Temp := FCurrentLines[BackCounter];
|
Temp := FCurrentLines[BackCounter];
|
||||||
if Temp <> '' then begin
|
if Temp <> '' then begin
|
||||||
Temp := copy(Temp, 1, GetCurrentIndent(FCurrentEditor, Temp, False));
|
Temp := copy(Temp, 1, GetIndentForLine(FCurrentEditor, Temp, False));
|
||||||
PhysLen := GetCurrentIndent(FCurrentEditor, Temp + OldIndent, True);
|
PhysLen := GetIndentForLine(FCurrentEditor, Temp, True);
|
||||||
if (PhysLen > KnownPhysLen) and (copy(temp, 1, length(BasedMix)) = BasedMix) then
|
if (PhysLen > KnownPhysLen) and (copy(temp, 1, length(BasedMix)) = BasedMix) then
|
||||||
begin
|
begin
|
||||||
KnownMix := Temp;
|
KnownMix := Temp;
|
||||||
@ -380,55 +394,61 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := AdjustCharMix(Indent, KnownMix, OldIndent);
|
Result := AdjustCharMix(Indent, KnownMix, '');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynBeautifier.ApplyIndent(LinePos: Integer;
|
procedure TSynBeautifier.ApplyIndent(LinePos: Integer;
|
||||||
Indent: Integer; RelativeToLinePos: Integer; IndentChars: String = '';
|
Indent: Integer; RelativeToLinePos: Integer; IndentChars: String = '';
|
||||||
IndentCharsFromLinePos: Integer = -1; KeepOldIndent: Boolean = False);
|
IndentCharsFromLinePos: Integer = 0);
|
||||||
var
|
var
|
||||||
Temp: String;
|
CharMix: String;
|
||||||
OldLen: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
if (LinePos < 1) or (LinePos > FCurrentEditor.Lines.Count) then
|
if (LinePos < 1) or (LinePos > FCurrentEditor.Lines.Count) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
if KeepOldIndent then
|
// calculate the final indent needed
|
||||||
Temp := ''
|
|
||||||
else begin
|
|
||||||
Temp := FCurrentLines[LinePos - 1];
|
|
||||||
Temp := copy(Temp, 1, GetCurrentIndent(FCurrentEditor, Temp, False));
|
|
||||||
end;
|
|
||||||
OldLen := length(Temp);
|
|
||||||
|
|
||||||
if (RelativeToLinePos > 0) and (RelativeToLinePos <= FCurrentEditor.Lines.Count) then
|
if (RelativeToLinePos > 0) and (RelativeToLinePos <= FCurrentEditor.Lines.Count) then
|
||||||
Indent := Indent + GetCurrentIndent(FCurrentEditor, FCurrentLines[RelativeToLinePos], True);
|
Indent := Indent + GetIndentForLine(FCurrentEditor, FCurrentLines[RelativeToLinePos-1], True);
|
||||||
if Indent< 0 then
|
if Indent< 0 then
|
||||||
Indent := 0;
|
Indent := 0;
|
||||||
|
|
||||||
if IndentChars <> '' then
|
// Calculate the charmix
|
||||||
IndentChars := AdjustCharMix(Indent, IndentChars, {$IFDEF EnableIndenter}''{$ELSE}Temp{$ENDIF})
|
CharMix := '';
|
||||||
else
|
if Indent > 0 then begin
|
||||||
IndentChars := GetCharMix(LinePos, Indent, Temp, IndentCharsFromLinePos);
|
if (IndentCharsFromLinePos > 0) and (IndentCharsFromLinePos <= FCurrentEditor.Lines.Count) then begin
|
||||||
|
CharMix := FCurrentLines[IndentCharsFromLinePos-1];
|
||||||
|
i := GetIndentForLine(FCurrentEditor, CharMix, False);
|
||||||
|
CharMix := AdjustCharMix(Indent, copy(CharMix, 1, i), IndentChars);
|
||||||
|
end
|
||||||
|
else if IndentChars <> '' then begin
|
||||||
|
CharMix := AdjustCharMix(Indent, '', IndentChars);
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
i := LinePos;
|
||||||
|
CharMix := GetCharMix(LinePos, Indent, i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{$IFDEF EnableIndenter}
|
{$IFDEF EnableIndenter}
|
||||||
DebugLn(['TSynBeautifier.ApplyIndent IndentChars="',dbgstr(IndentChars),'" KeepOldIndent=',KeepOldIndent,' Indent=',Indent]);
|
DebugLn(['TSynBeautifier.ApplyIndent IndentChars="',dbgstr(IndentChars),' Indent=',Indent]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
if not KeepOldIndent then
|
i := GetIndentForLine(FCurrentEditor, FCurrentLines[LinePos-1], False);
|
||||||
FCurrentLines.EditDelete(1, LinePos, OldLen);
|
FCurrentLines.EditDelete(1, LinePos, i);
|
||||||
//if not((FIndentType = sbitPositionCaret) and (FCurrentLines[LinePos] = '')) then
|
if (CharMix <> '') and not((FIndentType = sbitPositionCaret) and (FCurrentLines[LinePos-1] = '')) then
|
||||||
if IndentChars <> '' then
|
FCurrentLines.EditInsert(1, LinePos, CharMix);
|
||||||
FCurrentLines.EditInsert(1, LinePos, IndentChars);
|
|
||||||
{$IFDEF EnableIndenter}
|
{$IFDEF EnableIndenter}
|
||||||
DebugLn(['TSynBeautifier.ApplyIndent Line="',dbgstr(FCurrentLines.ExpandedStrings[LinePos-1]),'"']);
|
DebugLn(['TSynBeautifier.ApplyIndent Line="',dbgstr(FCurrentLines.ExpandedStrings[LinePos-1]),'"']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSynBeautifier.GetCurrentIndent(Editor: TSynEditBase; const Line: string; Physical: boolean): Integer;
|
function TSynBeautifier.GetIndentForLine(Editor: TSynEditBase; const Line: string; Physical: boolean): Integer;
|
||||||
var
|
var
|
||||||
p: PChar;
|
p: PChar;
|
||||||
begin
|
begin
|
||||||
p := pointer(Line);
|
p := PChar(Line);
|
||||||
if Assigned(p) then begin
|
if Assigned(p) then begin
|
||||||
Result := 0;
|
Result := 0;
|
||||||
while p^ in [#1..#32] do begin
|
while p^ in [#1..#32] do begin
|
||||||
@ -456,7 +476,7 @@ begin
|
|||||||
repeat
|
repeat
|
||||||
Dec(BackCounter);
|
Dec(BackCounter);
|
||||||
Temp := Lines[BackCounter];
|
Temp := Lines[BackCounter];
|
||||||
Result := GetCurrentIndent(Editor, Temp, True) + 1;
|
Result := GetIndentForLine(Editor, Temp, True) + 1;
|
||||||
until (BackCounter = 0) or (Temp <> '');
|
until (BackCounter = 0) or (Temp <> '');
|
||||||
|
|
||||||
FoundLine := BackCounter + 1;
|
FoundLine := BackCounter + 1;
|
||||||
@ -471,7 +491,7 @@ begin
|
|||||||
Temp := Lines[FoundLine-1]
|
Temp := Lines[FoundLine-1]
|
||||||
else
|
else
|
||||||
FoundLine := BackCounter + 1;
|
FoundLine := BackCounter + 1;
|
||||||
Temp := copy(Temp, 1, GetCurrentIndent(Editor, Temp, False));
|
Temp := copy(Temp, 1, GetIndentForLine(Editor, Temp, False));
|
||||||
|
|
||||||
case FIndentType of
|
case FIndentType of
|
||||||
sbitCopySpaceTab:
|
sbitCopySpaceTab:
|
||||||
|
@ -185,6 +185,8 @@ type
|
|||||||
FTouched: Boolean;
|
FTouched: Boolean;
|
||||||
|
|
||||||
procedure AdjustToChar;
|
procedure AdjustToChar;
|
||||||
|
function GetOldLineBytePos: TPoint;
|
||||||
|
function GetOldLineCharPos: TPoint;
|
||||||
procedure InternalSetLineCharPos(NewLine, NewCharPos: Integer;
|
procedure InternalSetLineCharPos(NewLine, NewCharPos: Integer;
|
||||||
KeepLastCharPos: Boolean = False;
|
KeepLastCharPos: Boolean = False;
|
||||||
ForceSet: Boolean = False);
|
ForceSet: Boolean = False);
|
||||||
@ -221,14 +223,19 @@ type
|
|||||||
function WasAtLineChar(aPoint: TPoint): Boolean;
|
function WasAtLineChar(aPoint: TPoint): Boolean;
|
||||||
function WasAtLineByte(aPoint: TPoint): Boolean;
|
function WasAtLineByte(aPoint: TPoint): Boolean;
|
||||||
function IsAtPos(aCaret: TSynEditCaret): Boolean;
|
function IsAtPos(aCaret: TSynEditCaret): Boolean;
|
||||||
|
|
||||||
property OldLinePos: Integer read FOldLinePos;
|
property OldLinePos: Integer read FOldLinePos;
|
||||||
property OldCharPos: Integer read FOldCharPos;
|
property OldCharPos: Integer read FOldCharPos;
|
||||||
|
property OldLineCharPos: TPoint read GetOldLineCharPos;
|
||||||
|
property OldLineBytePos: TPoint read GetOldLineBytePos;
|
||||||
|
|
||||||
property LinePos: Integer read fLinePos write setLinePos;
|
property LinePos: Integer read fLinePos write setLinePos;
|
||||||
property CharPos: Integer read fCharPos write setCharPos;
|
property CharPos: Integer read fCharPos write setCharPos;
|
||||||
property LineCharPos: TPoint read GetLineCharPos write SetLineCharPos;
|
property LineCharPos: TPoint read GetLineCharPos write SetLineCharPos;
|
||||||
property BytePos: Integer read GetBytePos write SetBytePos;
|
property BytePos: Integer read GetBytePos write SetBytePos;
|
||||||
property LineBytePos: TPoint read GetLineBytePos write SetLineBytePos;
|
property LineBytePos: TPoint read GetLineBytePos write SetLineBytePos;
|
||||||
property LineText: string read GetLineText write SetLineText;
|
property LineText: string read GetLineText write SetLineText;
|
||||||
|
|
||||||
property AdjustToNextChar: Boolean read FAdjustToNextChar write FAdjustToNextChar;
|
property AdjustToNextChar: Boolean read FAdjustToNextChar write FAdjustToNextChar;
|
||||||
property SkipTabs: Boolean read FSkipTabs write SetSkipTabs;
|
property SkipTabs: Boolean read FSkipTabs write SetSkipTabs;
|
||||||
property AllowPastEOL: Boolean read FAllowPastEOL write SetAllowPastEOL;
|
property AllowPastEOL: Boolean read FAllowPastEOL write SetAllowPastEOL;
|
||||||
@ -422,6 +429,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSynEditCaret.GetOldLineBytePos: TPoint;
|
||||||
|
begin
|
||||||
|
Result := FLines.PhysicalToLogicalPos(OldLineCharPos);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TSynEditCaret.GetOldLineCharPos: TPoint;
|
||||||
|
begin
|
||||||
|
Result := Point(FOldCharPos, FOldLinePos);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSynEditCaret.setCharPos(const AValue : Integer);
|
procedure TSynEditCaret.setCharPos(const AValue : Integer);
|
||||||
begin
|
begin
|
||||||
InternalSetLineCharPos(FLinePos, AValue);
|
InternalSetLineCharPos(FLinePos, AValue);
|
||||||
|
16
ide/main.pp
16
ide/main.pp
@ -357,8 +357,8 @@ type
|
|||||||
Button: TMouseButton; Shift: TShiftstate; X, Y: Integer);
|
Button: TMouseButton; Shift: TShiftstate; X, Y: Integer);
|
||||||
procedure OnSrcNoteBookMouseLink(
|
procedure OnSrcNoteBookMouseLink(
|
||||||
Sender: TObject; X, Y: Integer; var AllowMouseLink: Boolean);
|
Sender: TObject; X, Y: Integer; var AllowMouseLink: Boolean);
|
||||||
function OnSrcNoteBookGetIndent(Sender: TSynCustomBeautifier; SrcEditor: TSourceEditor;
|
function OnSrcNoteBookGetIndent(Sender: TObject; SrcEditor: TSourceEditor;
|
||||||
LogCaret: TPoint; var FirstLinePos, LastLine: Integer;
|
LogCaret, OldLogCaret: TPoint; FirstLinePos, LastLinePos: Integer;
|
||||||
Reason: TSynEditorCommand; SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
Reason: TSynEditorCommand; SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
||||||
procedure OnSrcNotebookDeleteLastJumPoint(Sender: TObject);
|
procedure OnSrcNotebookDeleteLastJumPoint(Sender: TObject);
|
||||||
procedure OnSrcNotebookEditorVisibleChanged(Sender: TObject);
|
procedure OnSrcNotebookEditorVisibleChanged(Sender: TObject);
|
||||||
@ -14459,9 +14459,9 @@ begin
|
|||||||
ActiveUnitInfo.Source,X,Y,NewSource,NewX,NewY,NewTopLine);
|
ActiveUnitInfo.Source,X,Y,NewSource,NewX,NewY,NewTopLine);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMainIDE.OnSrcNoteBookGetIndent(Sender: TSynCustomBeautifier;
|
function TMainIDE.OnSrcNoteBookGetIndent(Sender: TObject;
|
||||||
SrcEditor: TSourceEditor; LogCaret: TPoint;
|
SrcEditor: TSourceEditor; LogCaret, OldLogCaret: TPoint;
|
||||||
var FirstLinePos, LastLine: Integer; Reason: TSynEditorCommand;
|
FirstLinePos, LastLinePos: Integer; Reason: TSynEditorCommand;
|
||||||
SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
||||||
var
|
var
|
||||||
CodeBuf: TCodeBuffer;
|
CodeBuf: TCodeBuffer;
|
||||||
@ -14479,11 +14479,11 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
case Reason of
|
case Reason of
|
||||||
ecLineBreak,ecInsertLine: ;
|
ecLineBreak,ecInsertLine: ;
|
||||||
ecPaste: if LastLine<=FirstLinePos then exit; // not a whole line
|
ecPaste: if LastLinePos<=FirstLinePos then exit; // not a whole line
|
||||||
else
|
else
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
debugln(['TMainIDE.OnSrcNoteBookGetIndent LogCaret=',dbgs(LogCaret),' FirstLinePos=',FirstLinePos,' LastLine=',LastLine]);
|
debugln(['TMainIDE.OnSrcNoteBookGetIndent LogCaret=',dbgs(LogCaret),' FirstLinePos=',FirstLinePos,' LastLinePos=',LastLinePos]);
|
||||||
Result := True;
|
Result := True;
|
||||||
EditorIndex:=SrcEditor.PageIndex;
|
EditorIndex:=SrcEditor.PageIndex;
|
||||||
SaveSourceEditorChangesToCodeCache(EditorIndex);
|
SaveSourceEditorChangesToCodeCache(EditorIndex);
|
||||||
@ -14516,7 +14516,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
ecPaste:
|
ecPaste:
|
||||||
begin
|
begin
|
||||||
//DebugLn(['TMainIDE.OnSrcNoteBookGetIndent Apply to FirstLinePos-1 .. LastLine']);
|
//DebugLn(['TMainIDE.OnSrcNoteBookGetIndent Apply to FirstLinePos-1 .. LastLinePos']);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -421,8 +421,8 @@ type
|
|||||||
) of object;
|
) of object;
|
||||||
TOnShowCodeContext = procedure(JumpToError: boolean;
|
TOnShowCodeContext = procedure(JumpToError: boolean;
|
||||||
out Abort: boolean) of object;
|
out Abort: boolean) of object;
|
||||||
TOnGetIndentEvent = function(Sender: TSynCustomBeautifier; Editor: TSourceEditor;
|
TOnGetIndentEvent = function(Sender: TObject; Editor: TSourceEditor;
|
||||||
LogCaret: TPoint; var FirstLinePos, LinesCount: Integer;
|
LogCaret, OldLogCaret: TPoint; FirstLinePos, LinesCount: Integer;
|
||||||
Reason: TSynEditorCommand; SetIndentProc: TSynBeautifierSetIndentProc
|
Reason: TSynEditorCommand; SetIndentProc: TSynBeautifierSetIndentProc
|
||||||
): boolean of object;
|
): boolean of object;
|
||||||
|
|
||||||
@ -611,8 +611,8 @@ type
|
|||||||
Shift: TShiftstate; X,Y: Integer);
|
Shift: TShiftstate; X,Y: Integer);
|
||||||
procedure EditorMouseLink(
|
procedure EditorMouseLink(
|
||||||
Sender: TObject; X,Y: Integer; var AllowMouseLink: Boolean);
|
Sender: TObject; X,Y: Integer; var AllowMouseLink: Boolean);
|
||||||
function EditorGetIndent(Sender: TSynCustomBeautifier; Editor: TObject;
|
function EditorGetIndent(Sender: TObject; Editor: TObject;
|
||||||
LogCaret: TPoint; var FirstLinePos, LinesCount: Integer;
|
LogCaret, OldLogCaret: TPoint; FirstLinePos, LastLinePos: Integer;
|
||||||
Reason: TSynEditorCommand;
|
Reason: TSynEditorCommand;
|
||||||
SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
||||||
procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||||
@ -6739,13 +6739,13 @@ begin
|
|||||||
OnMouseLink(Sender, X, Y, AllowMouseLink);
|
OnMouseLink(Sender, X, Y, AllowMouseLink);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSourceNotebook.EditorGetIndent(Sender: TSynCustomBeautifier; Editor: TObject;
|
function TSourceNotebook.EditorGetIndent(Sender: TObject; Editor: TObject;
|
||||||
LogCaret: TPoint; var FirstLinePos, LinesCount: Integer; Reason: TSynEditorCommand;
|
LogCaret, OldLogCaret: TPoint; FirstLinePos, LastLinePos: Integer;
|
||||||
SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
Reason: TSynEditorCommand; SetIndentProc: TSynBeautifierSetIndentProc): Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if Assigned(OnGetIndent) then
|
if Assigned(OnGetIndent) then
|
||||||
Result := OnGetIndent(Sender, GetActiveSE, LogCaret, FirstLinePos, LinesCount,
|
Result := OnGetIndent(Sender, GetActiveSE, LogCaret, OldLogCaret, FirstLinePos, LastLinePos,
|
||||||
Reason, SetIndentProc);
|
Reason, SetIndentProc);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user