How to control the caret position after pasting content

General TRichView support forum. Please post your questions here
Post Reply
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

How to control the caret position after pasting content

Post by wolf1860 »

I want to adjust the pictures valign property after the paste action, the problem is after I finished the adjusting ,the caret position is set to the pasted content beginning automatic, not at the end of the pasted content normally.How to fix this?

this is my code:

Code: Select all

private
  pasted:Boolean;
  
procedure TfrmRvfEditorMain.SRichViewEdit1Paste(Sender: TCustomRichViewEdit; var DoDefault: Boolean);
begin
  pasted := True;
  DoDefault:=True;
end;

procedure TfrmRvfEditorMain.SRichViewEdit1Change(Sender: TObject);
var
  rve: TRichViewEdit;
begin
  rve := TSRichViewEdit(Sender).RichViewEdit;
  if pasted then
  begin
    //adjust the valign
    RVAlignImages(rve);
    pasted := False;
  end;
end;

procedure TfrmRvfEditorMain.RVAlignImages(rve: TRichViewEdit; iAlign: TRVVAlign = rvvaAbsMiddle);
var
  i: Integer;
  StyleNo: Integer;
begin
  if rve = nil then
    exit;
  for i := 0 to rve.ItemCount - 1 do
  begin
    StyleNo := rve.GetItemStyle(i);
    if StyleNo = rvsPicture then
    begin
      rve.SetItemVAlign(i, iAlign);
    end;
  end;
  rve.Format;
end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to control the caret position after pasting content

Post by Sergey Tkachenko »

You can store the caret position using RVGetSelection, and restore it using RVSetSelection (unit RVLinear).

But I can suggest another solution. You can adjust VALign of images in OnItemAction event, ItemAction = rviaInserted, if pasted = True.
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

Re: How to control the caret position after pasting content

Post by wolf1860 »

It works perfect good by ur solution, thank u!
Post Reply