mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-23 22:40:03 +02:00
cocoa: changing the implementation of strings count. (if the last line is empty, don't recognize it a full line. Compatible with Win32. bug #36664
git-svn-id: trunk@63273 -
This commit is contained in:
parent
84a3138f6e
commit
5a3630c919
@ -166,7 +166,6 @@ type
|
|||||||
FTextView: TCocoaTextView;
|
FTextView: TCocoaTextView;
|
||||||
public
|
public
|
||||||
class procedure GetLineStart(const s: AnsiString; LineIndex: Integer; var Offset, LinesSkipped: Integer);
|
class procedure GetLineStart(const s: AnsiString; LineIndex: Integer; var Offset, LinesSkipped: Integer);
|
||||||
class function GetLinesCount(const s: AnsiString): Integer;
|
|
||||||
protected
|
protected
|
||||||
function GetTextStr: string; override;
|
function GetTextStr: string; override;
|
||||||
procedure SetTextStr(const Value: string); override;
|
procedure SetTextStr(const Value: string); override;
|
||||||
@ -1227,19 +1226,22 @@ begin
|
|||||||
Offset:=i;
|
Offset:=i;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaMemoStrings.GetLinesCount(const s: AnsiString): Integer;
|
|
||||||
var
|
|
||||||
ofs : Integer;
|
|
||||||
begin
|
|
||||||
Result:=0;
|
|
||||||
ofs:=0;
|
|
||||||
GetLineStart(s, -1, ofs, Result);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCocoaMemoStrings.GetCount:Integer;
|
function TCocoaMemoStrings.GetCount:Integer;
|
||||||
|
var
|
||||||
|
s : NSString;
|
||||||
|
i : LongWord;
|
||||||
|
strLen : LongWord;
|
||||||
begin
|
begin
|
||||||
Result:=GetLinesCount(GetTextStr);
|
s := FTextView.string_;
|
||||||
inc(Result);
|
// it's a very nice example for Apple's docs
|
||||||
|
// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/TextLayout/Tasks/CountLines.html
|
||||||
|
strLen := s.length;
|
||||||
|
i := 0;
|
||||||
|
Result := 0;
|
||||||
|
while (i < strLen) do begin
|
||||||
|
i := NSMaxRange(s.lineRangeForRange(NSMakeRange(i, 0)));
|
||||||
|
inc(Result);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaMemoStrings.Get(Index:Integer):string;
|
function TCocoaMemoStrings.Get(Index:Integer):string;
|
||||||
|
Loading…
Reference in New Issue
Block a user