Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in SearchReplace procedure, returning wrong result upon Cancel . . . with fix #196

Open
ksolway opened this issue Oct 12, 2022 · 0 comments

Comments

@ksolway
Copy link

ksolway commented Oct 12, 2022

Bug in SearchReplace procedure, returning wrong result upon Cancel . . . with fix

In the "SearchReplace" function, in SynEdit.pas

There should be a "Dec(Result)" in response to "raCancel", the same as there is in response to "RaSkip".

Otherwise the function returns the wrong number of replacements.

The following change fixes it:

    if bPrompt and Assigned(FOnReplaceText) then
    begin
      nAction := DoOnReplaceText(ASearch, AReplace, ptCurrent.Line, nFound);
      if nAction = raCancel then
       begin
         Dec(Result);  // I added this   12-10-2022
         Exit;
       end;
    end
    else . . .

Also, the Search and Replace demo doesn't include a procedure for the ConfirmReplaceDialog.

Here it is:

The "OnReplaceText" event should be set to a procedure like the following:

procedure TForm1.SynEditReplaceText(Sender: TObject; const ASearch,
  AReplace: string; Line, Column: Integer; var Action: TSynReplaceAction);
var 
 res : tmodalresult;
begin                   
  ConfirmReplaceDialog := TConfirmReplaceDialog.Create(self);
  try
    ConfirmReplaceDialog.lblconfirmation.caption := 'Replace this occurrence of "' + Synedit.SelText + '"?';
    ConfirmReplaceDialog.left := self.left + self.width;
    ConfirmReplaceDialog.top := self.top + (self.height div 3);
    if  ConfirmReplaceDialog.left + ConfirmReplaceDialog.width > screen.width then
        ConfirmReplaceDialog.left := screen.Width - ConfirmReplaceDialog.width;

    res := ConfirmReplaceDialog.ShowModal;
    case res of
      mrYes : Action := raReplace;
      mrNo :  Action := raSkip;
      mrCancel : Action := raCancel;
      mrYesToAll : Action := raReplaceAll;
      else Action := raCancel;
    end;
  finally
    ConfirmReplaceDialog.Free;
  end;
end; 

In the ConfirmReplaceDialog form, mrTryAgain needs to be replaced with mrYesToAll.

pyscripter added a commit to pyscripter/SynEdit that referenced this issue Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant