anchor.diff:    HScrollbar.RePaint;
   end;
   
  -//BG, 26.01.2014: debug stuff:
  -var
  -    AStr: AnsiString;
  -    StartPos: Integer;
  -    EndPos: Integer;
  -    LenFrag: Integer;
  -//BG, 26.01.2014: end of debug stuff:
  -
   procedure THtmlViewer.CopyToClipboard;
   
     procedure CopyToClipboardAsHtml(HTML: ThtString; StSrc, EnSrc: Integer);
   
  -    procedure CopyToClipBoard(const Source: ThtString);
  +    procedure CopyToClipBoard(const Utf8: AnsiString; Len: Integer);
       // Put SOURCE on the clipboard, using FORMAT as the clipboard format
     {$ifdef LCL}
       var
  -      Utf8: UTF8String;
  +//      Len: Integer;
  +//      Utf8: UTF8String;
         CF_HTML: UINT;
       begin
         CF_HTML := RegisterClipboardFormat('HTML Format'); {not sure this is necessary}
  -      Utf8 := UTF8Encode(Source);
  -      Clipboard.AddFormat(CF_HTML, Utf8, Length(Utf8));
  +//      Len := Length(Utf8);
  +//      Utf8 := UTF8Encode(Source);
  +      Clipboard.AddFormat(CF_HTML, Utf8, Len);
       end;
     {$else}
       var
  -      Len: Integer;
         Mem: HGLOBAL;
         Buf: PAnsiChar;
  -      L: Integer;
         CF_HTML: UINT;
       begin
  -      Len := WideCharToMultiByte(CP_UTF8, 0, PWideChar(Source), Length(Source), nil, 0, nil, nil);;
         CF_HTML := RegisterClipboardFormat('HTML Format'); {not sure this is necessary}
         Mem := GlobalAlloc(GMEM_DDESHARE + GMEM_MOVEABLE, Len + 1);
         try
           Buf := GlobalLock(Mem);
           try
  -          L := WideCharToMultiByte(CP_UTF8, 0, PWideChar(Source), Length(Source), Buf, Len, nil, nil);
  -          Buf[L] := #0;
  -//BG, 26.01.2014: debug stuff:
  -          AStr := Buf;
  -          StartPos := Pos('<!--StartFragment-->', AStr);
  -          EndPos := Pos('<!--EndFragment-->', AStr);
  -          LenFrag := EndPos - StartPos;
  -//BG, 26.01.2014: end of debug stuff:
  +          Move(Utf8[1], Buf[0], Len);
  +          Buf[Len] := #0;
             SetClipboardData(CF_HTML, Mem);
           finally
             GlobalUnlock(Mem);
  
positive.code:     HTML := DocumentSource;
      StSrc := FindSourcePos(FSectionList.SelB);
      EnSrc := FindSourcePos(FSectionList.SelE);
      if (FDocument <> nil) and ((FDocument.CodePage = CP_UTF16LE) or (FDocument.CodePage = CP_UTF16BE)) then
      begin
        StSrc := StSrc div 2;
        if EnSrc > 0 then
          EnSrc := EnSrc div 2;
      end;
      Inc(StSrc);
  
  
negative.code:       // about clipboard format: http://msdn.microsoft.com/en-us/library/aa767917%28v=vs.85%29.aspx
        StartFrag: ThtString = '<!--StartFragment-->';
        EndFrag: ThtString = '<!--EndFragment-->';
  
      function GetCopy(const HTML: ThtString): AnsiString;
      const
        PreliminaryHeader: ThtString =
          'Version:1.0'#13#10 +
          'StartHTML:'#13#10 +
          'EndHTML:'#13#10 +
          'StartFragment:'#13#10 +
          'EndFragment:'#13#10 +
          'SourceURL:'#13#10;
        IndexLength = 10;
  
        procedure InsertAfter(var Str: ThtString; const SubStr, InsStr: ThtString);
        var
          I: Integer;
        begin
          I := Pos(SubStr, Str);
          Assert(I > 0, Format('"%s" not found in "%s"', [SubStr, Str]));
          Inc(I, Length(SubStr));
          Insert(InsStr, Str, I);
        end;
  
      var
        Header: ThtString;
        URLString: ThtString;
        Utf8Header: AnsiString;
        Utf8Html: AnsiString;
  
        StartHTMLIndex,
        EndHTMLIndex,
        StartFragmentIndex,
        EndFragmentIndex: Integer;
  
      begin
        // prepare header (without indexes yet):
        if CurrentFile = '' then
          UrlString := 'unsaved:///THtmlViewer.htm'
        else if Pos('://', CurrentFile) > 0 then
          URLString := CurrentFile {already has protocol}
        else
          URLString := 'file://' + CurrentFile;
        Header := PreliminaryHeader;
        InsertAfter(Header, 'SourceURL:', URLString);
  
        // calculate indexes into utf8 clipboard text:
        Utf8Header := UTF8Encode(Header);
        Utf8Html := UTF8Encode(HTML);
        StartHTMLIndex      := Length(Utf8Header) + 4 * IndexLength;
        EndHTMLIndex        := StartHTMLIndex + Length(Utf8Html);
        StartFragmentIndex  := StartHTMLIndex + Pos(AnsiString(StartFrag), Utf8Html) + Length(StartFrag) - 1;
        EndFragmentIndex    := StartHTMLIndex + Pos(AnsiString(EndFrag), Utf8Html) - 1;
  
        // insert indexes into header:        IndexLength must match the format width:
        InsertAfter(Header, 'StartHTML:'    , Format('%.10d', [StartHTMLIndex]));
        InsertAfter(Header, 'EndHTML:'      , Format('%.10d', [EndHTMLIndex]));
        InsertAfter(Header, 'StartFragment:', Format('%.10d', [StartFragmentIndex]));
        InsertAfter(Header, 'EndFragment:'  , Format('%.10d', [EndFragmentIndex]));
  
        // return the complete clipboard text
        Result := UTF8Encode(Header) + Utf8Html;
      end;
  
      procedure RemoveTag(const Tag: ThtString);
  