Replace selection

General TRichView support forum. Please post your questions here
Post Reply
dspa72
Posts: 3
Joined: Fri Dec 05, 2008 10:44 am

Replace selection

Post by dspa72 »

Hi,

I would like to replace a manually selected text in rvedit leaving the selection.
Actually, I select the text, use InsertText to replace the text. But, in this way, I loose the selection


Hope I was clear .... :?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

InsertText, like any other Insert*** methods introduced in TCustomRichViewEdit, deletes a selected fragment before the insertion.

So I am not sure that I understand you.
dspa72
Posts: 3
Joined: Fri Dec 05, 2008 10:44 am

Post by dspa72 »

Ok, I try to explain better my problem (sorry for my poor english).

I have this
Sports cars are performance vehicles that provide driving satisfaction
I select with the mouse the words "performance vehicles"
Sports cars are performance vehicles that provide driving satisfaction
(underline means selected)

I want to replace the selected text with "stunning autos"
so I use

rv->InsertText("stunning autos",false);


the result is
Sports cars are stunning autos that provide driving satisfaction
but i would like to have
Sports cars are stunning autos that provide driving satisfaction
Hope this is more clear
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

  int SelStart, SelLength, SelStartNew;
  RVGetSelection(RichViewEdit1->TopLevelEditor, SelStart, SelLength);
  if (SelLength<0)
    SelStart -=SelLength;
  RichViewEdit1->InsertText("aaaaaaaaaa", false);
  SelStartNew = RVGetLinearCaretPos(RichViewEdit1->TopLevelEditor);
  RVSetSelection(RichViewEdit1->TopLevelEditor, SelStart, SelStartNew-SelStart);
Post Reply