How to determine if Cursor is in the first or last line?

General TRichView support forum. Please post your questions here
Post Reply
Guest

How to determine if Cursor is in the first or last line?

Post by Guest »

i've tried curitemno=0 and curitemno=itemcount-1, but this is not working, if there are fonts changed or other formattings in that line.
I'd like to detect the presence of the cursor in the first or last line of the formatted document.
How can that be done?
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Line (lines depend on word wrapping, they are changed if you resize the editor)? Or paragraph?
Guest

Post by Guest »

Sergey,
I've digged through the help file, but can't find any helpful reference to the line property (or event).
Can you please give a short expression to determin:
a.) caret is in the first line of the document
b.) caret is in the last line of the document

Thanks
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I am still not sure what do you mean by lines.
So I am giving two answers.

1) If you really mean "lines":

Code: Select all

rve.GetCurrentLineCol(Line, Col);
InTheFirstLine := (rve.InplaceEditor=nil) and (Line=1);
InTheLastLine := (rve.InplaceEditor=nil) and (Line=rve.GetLineNo(rve.ItemCount-1, rve.GetOffsAfterItem(rve.ItemCount-1));
Lines depend on word wrapping, so when user resizes the editor window, results will be different. The method above is simple, but not very efficient. If you need to call this code often, I can give alternative version.

2) If you mean "paragraphs":

Code: Select all

if rve.TopLevelEditor<>nil then
  InTheFirstPara := False;
  InTheLastPara := False;
  exit;
end;
ItemNo := rve.CurItemNo;
while (ItemNo>0) and not rve.IsParaStart(ItemNo) do
  dec(ItemNo);
InTheFirstPara := ItemNo=0;
ItemNo := rve.CurItemNo+1;
while (ItemNo<rve.ItemCount) and not rve.IsParaStart(ItemNo) do
  inc(ItemNo);
InTheLastPara := ItemNo=rve.ItemCount;
Guest

Post by Guest »

Sergey, thanks.
example 1.) is exactly what I was looking for.
Problem solved ...
Post Reply