mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 19:35:58 +02:00
IDE: Format a comment shown in code tooltip better. Issue #28430, patch from Yann Mérignac.
git-svn-id: trunk@49583 -
This commit is contained in:
parent
411ecaa94b
commit
22ea26d2cc
@ -83,7 +83,8 @@ span.keyword {
|
|||||||
/* comments in source fragments */
|
/* comments in source fragments */
|
||||||
span.comment {
|
span.comment {
|
||||||
color: darkcyan;
|
color: darkcyan;
|
||||||
font-style: italic
|
font-style: italic;
|
||||||
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* directives in source fragments */
|
/* directives in source fragments */
|
||||||
|
@ -2693,6 +2693,43 @@ var
|
|||||||
NestedComments: Boolean;
|
NestedComments: Boolean;
|
||||||
CommentStr, LastComment: String;
|
CommentStr, LastComment: String;
|
||||||
|
|
||||||
|
function ShiftLeft(const Comment: String) : String;
|
||||||
|
var
|
||||||
|
Lines : TStringList;
|
||||||
|
S : String;
|
||||||
|
I, J, LeftMost : Integer;
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
Lines := nil;
|
||||||
|
Lines := TStringList.Create;
|
||||||
|
Lines.Text := Comment;
|
||||||
|
|
||||||
|
LeftMost := Length(Comment);
|
||||||
|
|
||||||
|
for I := 0 to Lines.Count - 1 do
|
||||||
|
begin
|
||||||
|
if LeftMost <= 1 then
|
||||||
|
Break;
|
||||||
|
|
||||||
|
S := Lines[I];
|
||||||
|
J := 1;
|
||||||
|
while (J <= Length(S)) and (J < LeftMost) and (S[J] = ' ') do
|
||||||
|
Inc(J);
|
||||||
|
|
||||||
|
if J < LeftMost then
|
||||||
|
LeftMost := J;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if LeftMost > 1 then
|
||||||
|
for I := 0 to Lines.Count - 1 do
|
||||||
|
Lines[I] := Copy(Lines[I], LeftMost, Length(Lines[I]) - LeftMost + 1);
|
||||||
|
|
||||||
|
Result := Lines.Text;
|
||||||
|
finally
|
||||||
|
FreeAndNil(Lines);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure AddComment;
|
procedure AddComment;
|
||||||
begin
|
begin
|
||||||
if (CodeXYPos=nil) or (LastCodeXYPos=nil)
|
if (CodeXYPos=nil) or (LastCodeXYPos=nil)
|
||||||
@ -2700,7 +2737,7 @@ var
|
|||||||
or (CodeXYPos^.Y-LastCodeXYPos^.Y>10) then begin
|
or (CodeXYPos^.Y-LastCodeXYPos^.Y>10) then begin
|
||||||
// the last comment is at a different position => add a source link
|
// the last comment is at a different position => add a source link
|
||||||
if LastComment<>'' then
|
if LastComment<>'' then
|
||||||
Result:=Result+'<span class="comment">'+TextToHTML(LastComment)
|
Result:=Result+'<span class="comment">'+TextToHTML(ShiftLeft(LastComment))
|
||||||
+' ('+SourcePosToFPDocHint(LastCodeXYPos^,'Source')+')'
|
+' ('+SourcePosToFPDocHint(LastCodeXYPos^,'Source')+')'
|
||||||
+'</span><br>'+LineEnding;
|
+'</span><br>'+LineEnding;
|
||||||
LastComment:=CommentStr;
|
LastComment:=CommentStr;
|
||||||
@ -2713,6 +2750,40 @@ var
|
|||||||
LastCodeXYPos:=CodeXYPos;
|
LastCodeXYPos:=CodeXYPos;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function ExtractComment(const Source: String;
|
||||||
|
CommentStart: Integer) : String;
|
||||||
|
var
|
||||||
|
CommentEnd, XPos: Integer;
|
||||||
|
begin
|
||||||
|
XPos := CodeXYPos^.X;
|
||||||
|
CommentEnd := FindCommentEnd(Source, CommentStart, NestedComments);
|
||||||
|
|
||||||
|
case Source[CommentStart] of
|
||||||
|
'/':
|
||||||
|
begin
|
||||||
|
CommentStart := CommentStart + 2;
|
||||||
|
XPos := 0;
|
||||||
|
end;
|
||||||
|
'(':
|
||||||
|
begin
|
||||||
|
CommentStart := CommentStart + 2;
|
||||||
|
CommentEnd := CommentEnd - 2;
|
||||||
|
XPos := XPos + 1;
|
||||||
|
end;
|
||||||
|
'{':
|
||||||
|
begin
|
||||||
|
CommentStart := CommentStart + 1;
|
||||||
|
CommentEnd := CommentEnd - 1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Result:=Copy(Source, CommentStart, CommentEnd - CommentStart);
|
||||||
|
|
||||||
|
Result := TrimRight(Result);
|
||||||
|
|
||||||
|
if XPos > 0 then
|
||||||
|
Result := StringOfChar(' ', XPos) + Result;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:='';
|
Result:='';
|
||||||
if (Tool=nil) or (Node=nil) then exit;
|
if (Tool=nil) or (Node=nil) then exit;
|
||||||
@ -2731,14 +2802,12 @@ begin
|
|||||||
if (CommentStart<1) or (CommentStart>CommentCode.SourceLength)
|
if (CommentStart<1) or (CommentStart>CommentCode.SourceLength)
|
||||||
then
|
then
|
||||||
continue;
|
continue;
|
||||||
CommentStr:=ExtractCommentContent(CommentCode.Source,CommentStart,
|
CommentStr := ExtractComment(CommentCode.Source, CommentStart);
|
||||||
NestedComments,true,true,true);
|
|
||||||
AddComment;
|
AddComment;
|
||||||
end;
|
end;
|
||||||
CommentStr:='';
|
CommentStr:='';
|
||||||
CodeXYPos:=nil;
|
CodeXYPos:=nil;
|
||||||
AddComment;
|
AddComment;
|
||||||
|
|
||||||
finally
|
finally
|
||||||
FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
|
FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
|
||||||
end;
|
end;
|
||||||
@ -2828,6 +2897,7 @@ begin
|
|||||||
while p>0 do
|
while p>0 do
|
||||||
begin
|
begin
|
||||||
case Result[p] of
|
case Result[p] of
|
||||||
|
' ': Result:=copy(Result,1,p-1)+' '+copy(Result,p+1,length(Result));
|
||||||
'<': Result:=copy(Result,1,p-1)+'<'+copy(Result,p+1,length(Result));
|
'<': Result:=copy(Result,1,p-1)+'<'+copy(Result,p+1,length(Result));
|
||||||
'>': Result:=copy(Result,1,p-1)+'>'+copy(Result,p+1,length(Result));
|
'>': Result:=copy(Result,1,p-1)+'>'+copy(Result,p+1,length(Result));
|
||||||
'&': Result:=copy(Result,1,p-1)+'&'+copy(Result,p+1,length(Result));
|
'&': Result:=copy(Result,1,p-1)+'&'+copy(Result,p+1,length(Result));
|
||||||
|
@ -464,12 +464,12 @@ begin
|
|||||||
Result:=copy(Result,1,p-1)+NewTag+copy(Result,EndPos,length(Result));
|
Result:=copy(Result,1,p-1)+NewTag+copy(Result,EndPos,length(Result));
|
||||||
inc(p,length(NewTag));
|
inc(p,length(NewTag));
|
||||||
end;
|
end;
|
||||||
end else if Result[p] in [' ',#9,#10,#13] then begin
|
end else if Result[p] in [#9,#10,#13] then begin
|
||||||
// replace spaces and newline characters with a single space
|
// replace spaces and newline characters with a single space
|
||||||
EndPos:=p+1;
|
EndPos:=p+1;
|
||||||
while (EndPos<=length(Result)) and (Result[EndPos] in [' ',#9,#10,#13]) do
|
while (EndPos<=length(Result)) and (Result[EndPos] in [#9,#10,#13]) do
|
||||||
inc(EndPos);
|
inc(EndPos);
|
||||||
if (p > 1) and not (Result[p-1] in [' ',#9,#10,#13]) then
|
if (p > 1) and not (Result[p-1] in [#9,#10,#13]) then
|
||||||
begin
|
begin
|
||||||
Result:=copy(Result,1,p-1)+' '+copy(Result,EndPos,length(Result));
|
Result:=copy(Result,1,p-1)+' '+copy(Result,EndPos,length(Result));
|
||||||
inc(p);
|
inc(p);
|
||||||
@ -477,7 +477,7 @@ begin
|
|||||||
else
|
else
|
||||||
Result:=copy(Result,1,p-1)+copy(Result,EndPos,length(Result));
|
Result:=copy(Result,1,p-1)+copy(Result,EndPos,length(Result));
|
||||||
end else if Result[p]='&' then begin
|
end else if Result[p]='&' then begin
|
||||||
// special chars: < > &
|
// special chars: < > &
|
||||||
if (p+2<Length(Result)) and (Result[p+1]='l') and (Result[p+2]='t') and (Result[p+3]=';') then begin
|
if (p+2<Length(Result)) and (Result[p+1]='l') and (Result[p+2]='t') and (Result[p+3]=';') then begin
|
||||||
EndPos:=p+4;
|
EndPos:=p+4;
|
||||||
Result:=copy(Result,1,p-1)+'<'+copy(Result,EndPos,length(Result));
|
Result:=copy(Result,1,p-1)+'<'+copy(Result,EndPos,length(Result));
|
||||||
@ -486,6 +486,10 @@ begin
|
|||||||
EndPos:=p+4;
|
EndPos:=p+4;
|
||||||
Result:=copy(Result,1,p-1)+'>'+copy(Result,EndPos,length(Result));
|
Result:=copy(Result,1,p-1)+'>'+copy(Result,EndPos,length(Result));
|
||||||
end else
|
end else
|
||||||
|
if (p+4<Length(Result)) and (Result[p+1]='n') and (Result[p+2]='b') and (Result[p+3]='s') and (Result[p+4]='p') and (Result[p+5]=';') then begin
|
||||||
|
EndPos:=p+6;
|
||||||
|
Result:=copy(Result,1,p-1)+' '+copy(Result,EndPos,length(Result));
|
||||||
|
end else
|
||||||
if (p+3<Length(Result)) and (Result[p+1]='a') and (Result[p+2]='m') and (Result[p+3]='p') and (Result[p+4]=';') then begin
|
if (p+3<Length(Result)) and (Result[p+1]='a') and (Result[p+2]='m') and (Result[p+3]='p') and (Result[p+4]=';') then begin
|
||||||
EndPos:=p+5;
|
EndPos:=p+5;
|
||||||
Result:=copy(Result,1,p-1)+'&'+copy(Result,EndPos,length(Result));
|
Result:=copy(Result,1,p-1)+'&'+copy(Result,EndPos,length(Result));
|
||||||
|
Loading…
Reference in New Issue
Block a user