mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-25 08:37:29 +01:00
SynEdit: Refactor, LengthOfLongestLine
git-svn-id: trunk@25789 -
This commit is contained in:
parent
4ab9eaac1b
commit
0e98a5118a
@ -311,10 +311,8 @@ end;
|
|||||||
function TSynEditStringTabExpander.GetLengthOfLongestLine: integer;
|
function TSynEditStringTabExpander.GetLengthOfLongestLine: integer;
|
||||||
var
|
var
|
||||||
Line: String;
|
Line: String;
|
||||||
CharWidths: TPhysicalCharWidths;
|
CharWidths: PPhysicalCharWidth;
|
||||||
n, m: Integer;
|
i, j, n, m: Integer;
|
||||||
//var
|
|
||||||
i, j: integer;
|
|
||||||
begin
|
begin
|
||||||
if (fIndexOfLongestLine >= 0) and (fIndexOfLongestLine < Count) then begin
|
if (fIndexOfLongestLine >= 0) and (fIndexOfLongestLine < Count) then begin
|
||||||
Result := FTabData[fIndexOfLongestLine];
|
Result := FTabData[fIndexOfLongestLine];
|
||||||
@ -322,40 +320,45 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := 0;
|
try
|
||||||
m := 0;
|
Result := 0;
|
||||||
for i := 0 to Count - 1 do begin
|
m := 0;
|
||||||
j := FTabData[i];
|
CharWidths := nil;
|
||||||
if j = LINE_LEN_UNKNOWN then begin
|
for i := 0 to Count - 1 do begin
|
||||||
// embedd a copy of ExpandedStringLength
|
j := FTabData[i];
|
||||||
// allows to re-use CharWidths
|
if j = LINE_LEN_UNKNOWN then begin
|
||||||
Line := fSynStrings[i];
|
// embedd a copy of ExpandedStringLength
|
||||||
j := 0;
|
// allows to re-use CharWidths
|
||||||
if (Line = '') then begin
|
Line := fSynStrings[i];
|
||||||
FTabData[i] := j + NO_TAB_IN_LINE_OFFSET;
|
j := 0;
|
||||||
end else begin
|
if (Line = '') then begin
|
||||||
n := length(Line);
|
|
||||||
if n > m then begin
|
|
||||||
SetLength(CharWidths, n);
|
|
||||||
m := n;
|
|
||||||
end;
|
|
||||||
DoGetPhysicalCharWidths(Pchar(Line), n, i, @CharWidths[0]);
|
|
||||||
for m := 0 to n-1 do
|
|
||||||
j := j + CharWidths[m];
|
|
||||||
|
|
||||||
if FLastLineHasTab then // FLastLineHasTab is set by GetPhysicalCharWidths
|
|
||||||
FTabData[i] := j
|
|
||||||
else
|
|
||||||
FTabData[i] := j + NO_TAB_IN_LINE_OFFSET;
|
FTabData[i] := j + NO_TAB_IN_LINE_OFFSET;
|
||||||
|
end else begin
|
||||||
|
n := length(Line);
|
||||||
|
if n > m then begin
|
||||||
|
ReAllocMem(CharWidths, n * SizeOf(TPhysicalCharWidth));
|
||||||
|
m := n;
|
||||||
|
end;
|
||||||
|
DoGetPhysicalCharWidths(Pchar(Line), n, i, CharWidths);
|
||||||
|
for m := 0 to n-1 do
|
||||||
|
j := j + CharWidths[m];
|
||||||
|
|
||||||
|
if FLastLineHasTab then // FLastLineHasTab is set by GetPhysicalCharWidths
|
||||||
|
FTabData[i] := j
|
||||||
|
else
|
||||||
|
FTabData[i] := j + NO_TAB_IN_LINE_OFFSET;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if j >= NO_TAB_IN_LINE_OFFSET then
|
||||||
|
j := j - NO_TAB_IN_LINE_OFFSET;
|
||||||
|
if j > Result then begin
|
||||||
|
Result := j;
|
||||||
|
fIndexOfLongestLine := i;
|
||||||
end;
|
end;
|
||||||
end
|
|
||||||
else
|
|
||||||
if j >= NO_TAB_IN_LINE_OFFSET then
|
|
||||||
j := j - NO_TAB_IN_LINE_OFFSET;
|
|
||||||
if j > Result then begin
|
|
||||||
Result := j;
|
|
||||||
fIndexOfLongestLine := i;
|
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
|
ReAllocMem(CharWidths, 0);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user