Page 1 of 1

Move caret to original position

Posted: Tue Dec 19, 2006 10:54 am
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

Posted: Tue Dec 19, 2006 12:48 pm
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);