anchor.diff:      end
       else
       begin
  -      Ed.Strings.TextInsert(X2, Y2, CharEnd, false, Shift, PosAfter);
  +      St.TextInsert(X2, Y2, CharEnd, false, Shift, PosAfter);
         Ed.DoCaretsShift(NCaret, X2, Y2, Shift.X, Shift.Y, PosAfter);
   
  -      Ed.Strings.TextInsert(X1, Y1, CharBegin, false, Shift, PosAfter);
  +      St.TextInsert(X1, Y1, CharBegin, false, Shift, PosAfter);
         Ed.DoCaretsShift(NCaret, X1, Y1, Shift.X, Shift.Y, PosAfter);
   
         Caret.EndX:= X1+1;
  
positive.code:       bQuoteChar:= false;
    end;
  
    //make additional loop, to detect that ALL carets need pairing.
    //if at least one caret doesn't need, stop.
    //it's needed to make pair for all or nothing. issue #3219.
    for NCaret:= Ed.Carets.Count-1 downto 0 do
    begin
      Caret:= Ed.Carets[NCaret];
      if not Ed.Strings.IsIndexValid(Caret.PosY) then Continue;
      if Caret.EndY<0 then
        if not EditorAutoCloseBracket_NeedPair(Ed, Caret, bQuoteChar) then
          exit;
  
negative.code: 
      Result:= true;
    end;
    St.EndUndoGroup;
  
    if Result then
    begin
      Ed.Modified:= true;
      Ed.DoEventChange(NLineChanged);
      Ed.Update(true);
    end;
  end;
  