mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-04 16:37:19 +01:00
SynEdit, Beautifier: added Replace current indent
git-svn-id: trunk@20495 -
This commit is contained in:
parent
ed0983b26a
commit
2f710fb9b6
@ -45,7 +45,8 @@ uses
|
||||
type
|
||||
|
||||
TSynBeautifierGetIndentEvent =
|
||||
procedure(Sender: TObject; LogCaret: TPoint; Line: Integer; var Indent, BasedLine: Integer) of object;
|
||||
procedure(Sender: TObject; LogCaret: TPoint; Line: Integer;
|
||||
var Indent, BasedLine: Integer; var ReplaceIndent: Boolean) of object;
|
||||
|
||||
{ TSynCustomBeautifier }
|
||||
|
||||
@ -61,10 +62,12 @@ type
|
||||
function IndentLine(const Editor: TSynEditBase;
|
||||
const Lines: TSynEditStrings; const ACaret: TSynEditCaret;
|
||||
out CaretNewX: Integer): Boolean; virtual; abstract; // Todo DelChar are not supprted for undo
|
||||
function GetDesiredIndentForLine(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
function GetDesiredIndentForLine
|
||||
(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret): Integer; virtual; abstract;
|
||||
function GetDesiredIndentForLine(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret;
|
||||
function GetDesiredIndentForLine
|
||||
(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret; out ReplaceIndent: Boolean;
|
||||
out DesiredIndent: String): Integer; virtual; abstract;
|
||||
property OnGetDesiredIndent: TSynBeautifierGetIndentEvent
|
||||
read FOnGetDesiredIndent write FOnGetDesiredIndent;
|
||||
@ -82,15 +85,18 @@ type
|
||||
Physical: boolean): Integer;
|
||||
function CanUnindent(const Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret): Boolean; override;
|
||||
function UnIndentLine(const Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret; out CaretNewX: Integer
|
||||
): Boolean; override; // Todo InsChar are not supprted for undo
|
||||
function IndentLine(const Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret; out CaretNewX: Integer): Boolean; override; // Todo DelChar are not supprted for undo
|
||||
function GetDesiredIndentForLine(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
function UnIndentLine
|
||||
(const Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret; out CaretNewX: Integer): Boolean; override;
|
||||
function IndentLine
|
||||
(const Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret; out CaretNewX: Integer): Boolean; override;
|
||||
function GetDesiredIndentForLine
|
||||
(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret): Integer; override;
|
||||
function GetDesiredIndentForLine(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret;
|
||||
function GetDesiredIndentForLine
|
||||
(Editor: TSynEditBase; const Lines: TSynEditStrings;
|
||||
const ACaret: TSynEditCaret; out ReplaceIndent: Boolean;
|
||||
out DesiredIndent: String): Integer; override;
|
||||
published
|
||||
property IndentType: TSynBeautifierIndentType read FIndentType write FIndentType;
|
||||
@ -161,11 +167,16 @@ function TSynBeautifier.IndentLine(const Editor: TSynEditBase;
|
||||
var
|
||||
IndentPos: Integer;
|
||||
InsChars: String;
|
||||
ReplaceIndent: Boolean;
|
||||
begin
|
||||
IndentPos := GetDesiredIndentForLine(Editor, Lines, ACaret, InsChars);
|
||||
IndentPos := GetDesiredIndentForLine(Editor, Lines, ACaret, ReplaceIndent, InsChars);
|
||||
if IndentPos < 0 then
|
||||
exit(False);
|
||||
|
||||
if ReplaceIndent then
|
||||
Lines.EditDelete(1, ACaret.LinePos,
|
||||
GetCurrentIndent(Editor, ACaret.LineText, False));
|
||||
|
||||
if (FIndentType = sbitPositionCaret) and (ACaret.LineText = '') then
|
||||
InsChars := '';
|
||||
|
||||
@ -175,8 +186,8 @@ begin
|
||||
end;
|
||||
|
||||
function TSynBeautifier.GetDesiredIndentForLine(Editor: TSynEditBase;
|
||||
const Lines: TSynEditStrings; const ACaret: TSynEditCaret; out
|
||||
DesiredIndent: String): Integer;
|
||||
const Lines: TSynEditStrings; const ACaret: TSynEditCaret;
|
||||
out ReplaceIndent: Boolean; out DesiredIndent: String): Integer;
|
||||
var
|
||||
BackCounter, PhysLen: Integer;
|
||||
Temp: string;
|
||||
@ -192,8 +203,10 @@ begin
|
||||
until (BackCounter = 0) or (Temp <> '');
|
||||
|
||||
FoundLine := BackCounter + 1;
|
||||
ReplaceIndent := False;
|
||||
if assigned(FOnGetDesiredIndent) then
|
||||
FOnGetDesiredIndent(Editor, ACaret.LineBytePos, ACaret.LinePos, Result, FoundLine);
|
||||
FOnGetDesiredIndent(Editor, ACaret.LineBytePos, ACaret.LinePos, Result,
|
||||
FoundLine, ReplaceIndent);
|
||||
|
||||
if Result < 0 then exit;
|
||||
|
||||
@ -221,8 +234,9 @@ function TSynBeautifier.GetDesiredIndentForLine(Editor: TSynEditBase;
|
||||
const Lines: TSynEditStrings; const ACaret: TSynEditCaret): Integer;
|
||||
var
|
||||
Dummy: String;
|
||||
Replace: Boolean;
|
||||
begin
|
||||
Result := GetDesiredIndentForLine(Editor, Lines, ACaret, Dummy);
|
||||
Result := GetDesiredIndentForLine(Editor, Lines, ACaret, Replace, Dummy);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
@ -161,7 +161,7 @@ type
|
||||
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
||||
procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
procedure EditorGetIndent(Sender: TObject; LogCaret: TPoint; Line: Integer;
|
||||
var Indent, BasedLine: Integer);
|
||||
var Indent, BasedLine: Integer; var ReplaceIndent: Boolean);
|
||||
procedure EditorStatusChanged(Sender: TObject; Changes: TSynStatusChanges);
|
||||
procedure SetCodeBuffer(NewCodeBuffer: TCodeBuffer);
|
||||
function GetSource: TStrings;
|
||||
@ -603,7 +603,7 @@ type
|
||||
procedure EditorMouseLink(
|
||||
Sender: TObject; X,Y: Integer; var AllowMouseLink: Boolean);
|
||||
procedure EditorGetIndent(Sender: TObject; LogCaret: TPoint; Line: Integer;
|
||||
var Indent, BasedLine: Integer);
|
||||
var Indent, BasedLine: Integer; var ReplaceIndent: Boolean);
|
||||
procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
procedure EditorMouseWheel(Sender: TObject; Shift: TShiftState;
|
||||
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
||||
@ -3005,10 +3005,10 @@ begin
|
||||
end;
|
||||
|
||||
procedure TSourceEditor.EditorGetIndent(Sender: TObject; LogCaret: TPoint;
|
||||
Line: Integer; var Indent, BasedLine: Integer);
|
||||
Line: Integer; var Indent, BasedLine: Integer; var ReplaceIndent: Boolean);
|
||||
begin
|
||||
if Assigned(OnGetDesiredIndent) then
|
||||
OnGetDesiredIndent(Sender, LogCaret, Line, Indent, BasedLine);
|
||||
OnGetDesiredIndent(Sender, LogCaret, Line, Indent, BasedLine, ReplaceIndent);
|
||||
end;
|
||||
|
||||
Function TSourceEditor.GetCaretPosFromCursorPos(const CursorPos: TPoint): TPoint;
|
||||
@ -6693,10 +6693,10 @@ begin
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.EditorGetIndent(Sender: TObject; LogCaret: TPoint; Line: Integer;
|
||||
var Indent, BasedLine: Integer);
|
||||
var Indent, BasedLine: Integer; var ReplaceIndent: Boolean);
|
||||
begin
|
||||
if Assigned(OnGetDesiredIndent) then
|
||||
OnGetDesiredIndent(Sender, LogCaret, Line, Indent, BasedLine);
|
||||
OnGetDesiredIndent(Sender, LogCaret, Line, Indent, BasedLine, ReplaceIndent);
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.HintTimer(sender: TObject);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user