Page 1 of 1
TdbRichViewEdit cursor position
Posted: Sat Nov 14, 2020 2:39 pm
by jota
Hi
Can somebody help me?
How can you detect that the cursor is positioned on the first character of a line (with or without a bullet)?
Thanks in advance
Re: TdbRichViewEdit cursor position
Posted: Sat Nov 14, 2020 5:09 pm
by Sergey Tkachenko
Do you mean paragraph?
If yes, the code is
Code: Select all
function IsAtTheBeginningOfParagraph(rve: TCustomRichViewEdit): Boolean;
var
ItemNo, Offs: Integer;
begin
rve := rve.TopLevelEditor;
// caret position
ItemNo := rve.CurItemNo;
Offs := rve.OffsetInCurItem;
// is it at the beginning of an item?
Result := Offs = rve.GetOffsBeforeItem(ItemNo);
if not Result then
exit;
// is this item at the beginning of paragraph?
Result := rve.IsParaStart(ItemNo);
if Result then
exit;
// this is definitely not the first item. maybe it is after a list marker?
Result := rve.GetItemStyle(ItemNo-1) = rvsListMarker;
end;
If you want to check not only beginnings of paragraphs, but also breaks added by Shift+Enter, change IsParaStart to IsFromNewLine.
If you want to check a screen line (that depends on word wrapping), I can post a code, but it requires using undocumented methods.