Move caret to original position

General TRichView support forum. Please post your questions here
Post Reply
cychia
Posts: 104
Joined: Mon Jan 16, 2006 1:52 am

Move caret to original position

Post by cychia »

How can i remember current caret postion and then after doing some processing, and move the caret back to the original position:

example:
1. remember current caret position
2. process the rv items from 0 to count
3. during processing if located a identified item tag, select and delete it.
4. after that call to move the caret back to the original location
Sergey Tkachenko
Site Admin
Posts: 17326
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You cannot store position as a number of characters from the beginning, because this value becomes incorrect if you delete something before this position.
I think the simplest way is to store the following value:
1) RVData := RichViewEdit1.TopLevelEditor.RVData.GetSourceRVData;
2) ItemNo := RichViewEdit1.TopLevelEditor.CurItemNo;
3) Offs := RichViewEdit1.TopLevelEditor.OffsetInCurItem;
When deleting item from RVData.GetRVData, with indices <= ItemNo, the stored value of ItemNo must be decremented.
When deleting characters from the ItemNo-th item of RVData.GetRVData, Offs must be adjusted.

The caret is restored in this way:
RVData := TCustomRVFormattedData(RVData.Edit);
RVData.SetSelectionBounds(ItemNo, Offs, ItemNo, Offs);
Post Reply