diff --git a/docs/lazdoc.css b/docs/lazdoc.css index 180ce908ec..7cbbca0fed 100644 --- a/docs/lazdoc.css +++ b/docs/lazdoc.css @@ -83,7 +83,8 @@ span.keyword { /* comments in source fragments */ span.comment { color: darkcyan; - font-style: italic + font-style: italic; + font-family: monospace; } /* directives in source fragments */ diff --git a/ide/codehelp.pas b/ide/codehelp.pas index f04a91b92d..64252c5e93 100644 --- a/ide/codehelp.pas +++ b/ide/codehelp.pas @@ -2693,6 +2693,43 @@ var NestedComments: Boolean; 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; begin if (CodeXYPos=nil) or (LastCodeXYPos=nil) @@ -2700,7 +2737,7 @@ var or (CodeXYPos^.Y-LastCodeXYPos^.Y>10) then begin // the last comment is at a different position => add a source link if LastComment<>'' then - Result:=Result+''+TextToHTML(LastComment) + Result:=Result+''+TextToHTML(ShiftLeft(LastComment)) +' ('+SourcePosToFPDocHint(LastCodeXYPos^,'Source')+')' +'
'+LineEnding; LastComment:=CommentStr; @@ -2713,6 +2750,40 @@ var LastCodeXYPos:=CodeXYPos; 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 Result:=''; if (Tool=nil) or (Node=nil) then exit; @@ -2731,14 +2802,12 @@ begin if (CommentStart<1) or (CommentStart>CommentCode.SourceLength) then continue; - CommentStr:=ExtractCommentContent(CommentCode.Source,CommentStart, - NestedComments,true,true,true); + CommentStr := ExtractComment(CommentCode.Source, CommentStart); AddComment; end; CommentStr:=''; CodeXYPos:=nil; AddComment; - finally FreeListOfPCodeXYPosition(ListOfPCodeXYPosition); end; @@ -2828,6 +2897,7 @@ begin while p>0 do begin 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)); diff --git a/ide/idehelpmanager.pas b/ide/idehelpmanager.pas index 54d4567d38..68ea12c71d 100644 --- a/ide/idehelpmanager.pas +++ b/ide/idehelpmanager.pas @@ -464,12 +464,12 @@ begin Result:=copy(Result,1,p-1)+NewTag+copy(Result,EndPos,length(Result)); inc(p,length(NewTag)); 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 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); - 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 Result:=copy(Result,1,p-1)+' '+copy(Result,EndPos,length(Result)); inc(p); @@ -477,7 +477,7 @@ begin else Result:=copy(Result,1,p-1)+copy(Result,EndPos,length(Result)); end else if Result[p]='&' then begin - // special chars: < > & + // special chars: < > &   if (p+2'+copy(Result,EndPos,length(Result)); end else + if (p+4