Page 1 of 1

[Example] How to move caret to the paragraph

Posted: Sun Aug 28, 2005 10:25 am
by Sergey Tkachenko
A very simple example: how to move caret to the beginning of the n-th paragraph

Code: Select all

procedure GoToParagraph(rve: TCustomRichViewEdit; ParagraphIndex: Integer);
var i: Integer;
begin
  for i := 0 to rve.ItemCount-1 do begin
    if rve.IsParaStart(i) then
      dec(ParagraphIndex);
    if ParagraphIndex<0 then begin
      rve.SetSelectionBounds(i, rve.GetOffsBeforeItem(i), i, rve.GetOffsBeforeItem(i));
      rve.Invalidate;
      exit;
    end;
  end;
end;
Call:

Code: Select all

GoToParagraph(RichViewEdit1, 7);
ParagraphIndex is zero-based.

Posted: Tue Apr 30, 2013 4:22 pm
by Sergey Tkachenko
Moving to the end of the current line. This function used some undocumented methods

Code: Select all

uses CRVFData, RVERVData;
procedure GoToEndOfLine(rve: TCustomRichViewEdit);
var DItemNo, DOffs, ItemNo, Offs: Integer;
    RVData: TRVEditRVData;
begin
  RVData := TRVEditRVData(rve.TopLevelEditor.RVData);
  DItemNo := RVData.CaretDrawItemNo+1;
  while (DItemNo<RVData.DrawItems.Count) and not RVData.DrawItems[DItemNo].FromNewLine do
    inc(DItemNo);
  dec(DItemNo);
  DOffs := RVData.GetOffsAfterDrawItem(DItemNo);
  RVData.DrawItem2Item(DItemNo, DOffs, ItemNo, Offs);
  RVData.SetSelectionBounds(ItemNo, Offs, ItemNo, Offs);
end;
Moving to the end of the current paragraph

Code: Select all

procedure GoToEndOfPara(rve: TCustomRichViewEdit);
var ItemNo, Offs: Integer;
begin
  rve := rve.TopLevelEditor;
  ItemNo := rve.CurItemNo+1;
  while (ItemNo<rve.ItemCount) and not rve.IsParaStart(ItemNo) do
    inc(ItemNo);
  dec(ItemNo);
  Offs := rve.GetOffsAfterItem(ItemNo);
  rve.SetSelectionBounds(ItemNo, Offs, ItemNo, Offs);
end;
Moving to the end of the document

Code: Select all

procedure GoToEndOfDoc(rve: TCustomRichViewEdit);
var ItemNo, Offs: Integer;
begin
  ItemNo := rve.ItemCount-1;
  Offs := rve.GetOffsAfterItem(ItemNo);
  rve.SetSelectionBounds(ItemNo, Offs, ItemNo, Offs);
end;