Page 1 of 1

How to control the caret position after pasting content

Posted: Thu Oct 19, 2017 3:14 am
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;

Re: How to control the caret position after pasting content

Posted: Thu Oct 19, 2017 9:16 am
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.

Re: How to control the caret position after pasting content

Posted: Thu Oct 19, 2017 10:39 am
by wolf1860
It works perfect good by ur solution, thank u!