//ecSyntTree.pas

//add procedure EditorUncollapseLine from unit unProc.pas from Synwrite source.
//change:

procedure TCustomSyntaxTreeView.MemoCaretUpdate(aAutoFocus : Boolean);
var sp, ep: integer;
  P: TPoint; //AT
  NN, NW, NH: integer;
  AScroll: boolean;
begin
  if Assigned(Selected) and Assigned(FSyntaxMemo) and
     (FClickAction in [staMoveCaret, staSelect, staSelectEnd]) then
  with Selected as TTreeNode do
   if Data <> nil then
    with TSyntNodeRange(Data) do
     if StartPos >= 0 then
      begin
       sp := FChanges.OldToCur(StartPos);
       if EndPos <> -1 then
         ep := FChanges.OldToCur(EndPos)
       else
         ep := sp;
       if FClickAction = staSelectEnd then
         begin
           FSyntaxMemo.CaretPos := FSyntaxMemo.StrPosToCaretPos(ep);
           FSyntaxMemo.TopLine := FSyntaxMemo.StrPosToCaretPos(sp).Y;
         end
       else
         begin //AT
           P := FSyntaxMemo.StrPosToCaretPos(sp);
           EditorUncollapseLine(FSyntaxMemo, P.Y);

           NH := (FSyntaxMemo.ClientHeight -
             IfThen(FSyntaxMemo.HorzRuler.Visible, FSyntaxMemo.HorzRuler.Height))
             div FSyntaxMemo.DefTextExt.cy;
           NW := (FSyntaxMemo.ClientWidth -
             IfThen(FSyntaxMemo.Gutter.Visible, FSyntaxMemo.Gutter.Width))
             div FSyntaxMemo.DefTextExt.cx;

           AScroll := not ((P.Y >= FSyntaxMemo.TopLine) and
             (P.Y <= FSyntaxMemo.TopLine + NH - 1));
           FSyntaxMemo.CaretPos := P;

           //scroll vert
           {
           if AScroll then
             FSyntaxMemo.TopLine := P.Y - NH div 2;
           }
           //hardcoded indent 3 lines from top
           FSyntaxMemo.TopLine := P.Y - 3;

           //scroll horz
           if not FSyntaxMemo.WordWrap then
           begin
             NN:= FSyntaxMemo.LinesPosToLog(P).X;
             if (NN <= FSyntaxMemo.ScrollPosX + 6) or
               (NN >= FSyntaxMemo.ScrollPosX + NW - 6) then
               FSyntaxMemo.ScrollPosX := NN - NW div 2;
           end;
         end;
       FSyntaxMemo.CollapsedChanged; //AT

       if (EndPos <> -1) and (FClickAction in [staSelect, staSelectEnd]) then
         FSyntaxMemo.SetSelection(sp, ep - sp);
       if aAutoFocus then
         Windows.SetFocus(FSyntaxMemo.Handle);
      end;
end;
