Issue #136: adjust code for displaying cursor position to the new SynMemo approach

This commit is contained in:
Ansgar Becker
2021-03-16 18:38:27 +01:00
parent 3647316425
commit c75dfc2274
2 changed files with 2 additions and 32 deletions

View File

@@ -289,7 +289,6 @@ type
function IsInt(Str: String): Boolean;
function IsFloat(Str: String): Boolean;
function ScanLineBreaks(Text: String): TLineBreaks;
function CountLineBreaks(Text: String; LineBreak: TLineBreaks=lbsWindows): Cardinal;
function fixNewlines(txt: String): String;
function GetShellFolder(FolderId: TGUID): String;
function ValidFilename(Str: String): String;
@@ -744,28 +743,6 @@ begin
end;
function CountLineBreaks(Text: String; LineBreak: TLineBreaks=lbsWindows): Cardinal;
var
Offset: Integer;
BreakStr: String;
begin
// Count number of given line breaks in text
Result := 0;
case LineBreak of
lbsWindows: BreakStr := CRLF;
lbsUnix: BreakStr := LB_UNIX;
lbsMac: BreakStr := LB_MAC;
lbsWide: BreakStr := LB_WIDE;
else Exit;
end;
Offset := PosEx(BreakStr, Text, 1);
while Offset <> 0 do begin
Inc(Result);
Offset := PosEx(BreakStr, Text, Offset + Length(BreakStr));
end;
end;
{***
Unify CR's and LF's to CRLF

View File

@@ -141,23 +141,16 @@ end;
procedure TfrmTextEditor.TimerMemoChangeTimer(Sender: TObject);
var
Lines: Cardinal;
TextLen: Integer;
MaxLen, CursorPos: String;
begin
// Timer based onchange handler, so we don't scan the whole text on every typed character
TimerMemoChange.Enabled := False;
TextLen := Length(MemoText.Text);
if FMaxLength = 0 then
MaxLen := '?'
else
MaxLen := FormatNumber(FMaxLength);
if TextLen = 0 then
Lines := 0
else
Lines := CountLineBreaks(MemoText.Text) + 1;
CursorPos := 'x:z'; //FormatNumber(MemoText.CaretPos.Y+1) + ' : ' + FormatNumber(MemoText.CaretPos.X+1);
lblTextLength.Caption := f_('%s characters (max: %s), %s lines, cursor at %s', [FormatNumber(TextLen), MaxLen, FormatNumber(Lines), CursorPos]);
CursorPos := MemoText.CaretY.ToString + ':' + MemoText.CaretX.ToString;
lblTextLength.Caption := f_('%s characters (max: %s), %s lines, cursor at %s', [FormatNumber(MemoText.GetTextLen), MaxLen, FormatNumber(MemoText.Lines.Count), CursorPos]);
end;