TdbRichViewEdit cursor position

General TRichView support forum. Please post your questions here
Post Reply
jota
Posts: 48
Joined: Fri Sep 16, 2011 10:56 am

TdbRichViewEdit cursor position

Post 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
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TdbRichViewEdit cursor position

Post 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.
Post Reply