Index: src/fileviews/ucolumnsfileview.pas
===================================================================
--- src/fileviews/ucolumnsfileview.pas	(revision 5463)
+++ src/fileviews/ucolumnsfileview.pas	(working copy)
@@ -142,7 +142,7 @@
     procedure RedrawFile(FileIndex: PtrInt); override;
     procedure RedrawFile(DisplayFile: TDisplayFile); override;
     procedure RedrawFiles; override;
-    procedure SetActiveFile(FileIndex: PtrInt); override;
+    procedure SetActiveFile(FileIndex, aLastTopRowIndex: PtrInt); override;
     procedure SetSorting(const NewSortings: TFileSortings); override;
     procedure ShowRenameFileEdit(aFile: TFile); override;
 
@@ -385,11 +385,13 @@
 {$IF lcl_fullversion >= 093100}
   dgPanel.Options := dgPanel.Options - [goDontScrollPartCell];
 {$ENDIF}
-  DoFileIndexChanged(aRow - dgPanel.FixedRows);
+  DoFileIndexChanged(aRow - dgPanel.FixedRows, dgPanel.TopRow);
 end;
 
 procedure TColumnsFileView.dgPanelTopLeftChanged(Sender: TObject);
 begin
+  if not FUpdatingActiveFile then
+    DoFileIndexChanged(dgPanel.Row - dgPanel.FixedRows, dgPanel.TopRow);
   Notify([fvnVisibleFilePropertiesChanged]);
 end;
 
@@ -599,7 +601,8 @@
   begin
     AVisibleRows := GetFullVisibleRows;
     if iRow < AVisibleRows.First then
-      TopRow := AVisibleRows.First;
+      TopRow := iRow
+    else
     if iRow > AVisibleRows.Last then
       TopRow := iRow - (AVisibleRows.Last - AVisibleRows.First);
   end;
@@ -611,9 +614,11 @@
     MakeVisible(dgPanel.Row);
 end;
 
-procedure TColumnsFileView.SetActiveFile(FileIndex: PtrInt);
+procedure TColumnsFileView.SetActiveFile(FileIndex, aLastTopRowIndex: PtrInt);
 begin
   dgPanel.Row := FileIndex + dgPanel.FixedRows;
+  if (aLastTopRowIndex <> -1) then
+    dgPanel.TopRow := aLastTopRowIndex;
   MakeVisible(dgPanel.Row);
 end;
 
@@ -832,10 +837,10 @@
   SetFilesDisplayItems;
   RedrawFiles;
 
-  if SetActiveFileNow(RequestedActiveFile) then
+  if SetActiveFileNow(RequestedActiveFile, FLastTopRowIndex) then
     RequestedActiveFile := ''
   // Requested file was not found, restore position to last active file.
-  else if not SetActiveFileNow(LastActiveFile) then
+  else if not SetActiveFileNow(LastActiveFile, FLastTopRowIndex) then
   // Make sure at least that the previously active file is still visible after displaying file list.
     MakeActiveVisible;
 
Index: src/fileviews/ufileviewwithgrid.pas
===================================================================
--- src/fileviews/ufileviewwithgrid.pas	(revision 5463)
+++ src/fileviews/ufileviewwithgrid.pas	(working copy)
@@ -76,7 +76,7 @@
     procedure RedrawFile(FileIndex: PtrInt); override;
     procedure RedrawFile(DisplayFile: TDisplayFile); override;
     procedure RedrawFiles; override;
-    procedure SetActiveFile(FileIndex: PtrInt); override;
+    procedure SetActiveFile(FileIndex, aLastTopRowIndex: PtrInt); override;
     procedure DoFileUpdated(AFile: TDisplayFile; UpdatedProperties: TFilePropertiesTypes = []); override;
     procedure DoHandleKeyDown(var Key: Word; Shift: TShiftState); override;
     procedure UpdateInfoPanel; override;
@@ -428,11 +428,11 @@
   dgPanel.CalculateColumnWidth;
   SetFilesDisplayItems;
 
-  if SetActiveFileNow(RequestedActiveFile) then
+  if SetActiveFileNow(RequestedActiveFile, FLastTopRowIndex) then
     RequestedActiveFile := ''
   else
     // Requested file was not found, restore position to last active file.
-    SetActiveFileNow(LastActiveFile);
+    SetActiveFileNow(LastActiveFile, FLastTopRowIndex);
 
   Notify([fvnVisibleFilePropertiesChanged]);
 
@@ -606,7 +606,7 @@
   TabHeader.UpdateSorting(Sorting);
 end;
 
-procedure TFileViewWithGrid.SetActiveFile(FileIndex: PtrInt);
+procedure TFileViewWithGrid.SetActiveFile(FileIndex, aLastTopRowIndex: PtrInt);
 var
   ACol, ARow: Integer;
 begin
@@ -652,7 +652,7 @@
 
 procedure TFileViewWithGrid.dgPanelSelection(Sender: TObject; aCol, aRow: Integer);
 begin
-  DoFileIndexChanged(dgPanel.CellToIndex(aCol, aRow));
+  DoFileIndexChanged(dgPanel.CellToIndex(aCol, aRow), dgPanel.TopRow);
   UpdateFooterDetails;
 end;
 
Index: src/fileviews/ufileviewwithmainctrl.pas
===================================================================
--- src/fileviews/ufileviewwithmainctrl.pas	(revision 5463)
+++ src/fileviews/ufileviewwithmainctrl.pas	(working copy)
@@ -585,7 +585,7 @@
     case Button of
       mbRight:
       begin
-        SetActiveFile(FileIndex);
+        SetActiveFile(FileIndex, -1);
 
         if gMouseSelectionEnabled and (gMouseSelectionButton = 1) then
         begin
@@ -627,7 +627,7 @@
         end;//of mouse selection handler
       end;
     else
-      SetActiveFile(FileIndex);
+      SetActiveFile(FileIndex, -1);
     end;
 
     { Dragging }
@@ -758,7 +758,7 @@
         SelEndIndex := FMouseSelectionStartIndex;
       end;
 
-      SetActiveFile(FileIndex);
+      SetActiveFile(FileIndex, -1);
       MarkFiles(SelStartIndex, SelEndIndex, FMouseSelectionLastState);
     end;
   end;
Index: src/fileviews/uorderedfileview.pas
===================================================================
--- src/fileviews/uorderedfileview.pas	(revision 5463)
+++ src/fileviews/uorderedfileview.pas	(working copy)
@@ -54,7 +54,8 @@
   protected
     lblFilter: TLabel;
     quickSearch: TfrmQuickSearch;
-    FLastActiveFileIndex: Integer;
+    FLastActiveFileIndex: PtrInt;
+    FLastTopRowIndex: PtrInt;
     FRangeSelecting: Boolean;
     FRangeSelectionStartIndex: Integer;
     FRangeSelectionEndIndex: Integer;
@@ -63,7 +64,7 @@
     procedure InvertActiveFile;
     procedure AfterChangePath; override;
     procedure CreateDefault(AOwner: TWinControl); override;
-    procedure DoFileIndexChanged(NewFileIndex: PtrInt);
+    procedure DoFileIndexChanged(NewFileIndex, TopRowIndex: PtrInt);
     procedure DoHandleKeyDown(var Key: Word; Shift: TShiftState); override;
     procedure DoHandleKeyDownWhenLoading(var Key: Word; Shift: TShiftState); override;
     procedure DoSelectionChanged; override; overload;
@@ -89,13 +90,13 @@
                          SearchDirection: TQuickSearchDirection = qsdNone);
     procedure Selection(Key: Word; CurIndex: PtrInt);
     procedure SelectRange(FileIndex: PtrInt);
-    procedure SetActiveFile(FileIndex: PtrInt); overload; virtual; abstract;
-    procedure SetLastActiveFile(FileIndex: PtrInt);
+    procedure SetActiveFile(FileIndex, aLastTopRowIndex: PtrInt); overload; virtual; abstract;
+    procedure SetLastActiveFile(FileIndex, TopRowIndex: PtrInt);
     {en
        Sets a file as active if the file currently exists.
        @returns(@true if the file was found and selected.)
     }
-    function SetActiveFileNow(aFilePath: String): Boolean;
+    function SetActiveFileNow(aFilePath: String; aLastTopRowIndex: PtrInt): Boolean;
 
   public
     procedure CloneTo(AFileView: TFileView); override;
@@ -158,7 +159,7 @@
   if not (IsEmpty or IsLoadingFileList) then
   begin
     SetFocus;
-    SetActiveFile(0);
+    SetActiveFile(0, -1);
   end;
 end;
 
@@ -167,7 +168,7 @@
   if not (IsEmpty or IsLoadingFileList) then
   begin
     SetFocus;
-    SetActiveFile(FFiles.Count - 1);
+    SetActiveFile(FFiles.Count - 1, -1);
   end;
 end;
 
@@ -209,9 +210,13 @@
   pmOperationsCancel.Parent := Self;
 end;
 
-procedure TOrderedFileView.DoFileIndexChanged(NewFileIndex: PtrInt);
+procedure TOrderedFileView.DoFileIndexChanged(NewFileIndex, TopRowIndex: PtrInt);
 begin
-  if IsFileIndexInRange(NewFileIndex) and (FLastActiveFileIndex <> NewFileIndex) then
+  if IsFileIndexInRange(NewFileIndex) and
+     ( (FLastActiveFileIndex <> NewFileIndex) or
+       (FLastTopRowIndex <> TopRowIndex)
+     )
+  then
   begin
     if not FRangeSelecting then
     begin
@@ -223,7 +228,7 @@
 
     if not FUpdatingActiveFile then
     begin
-      SetLastActiveFile(NewFileIndex);
+      SetLastActiveFile(NewFileIndex, TopRowIndex);
 
       if Assigned(OnChangeActiveFile) then
         OnChangeActiveFile(Self, FFiles[NewFileIndex].FSFile);
@@ -582,7 +587,7 @@
 
       if Result then
       begin
-        SetActiveFile(Index);
+        SetActiveFile(Index, -1);
         Exit;
       end;
 
@@ -685,7 +690,7 @@
   begin
     // First try to select the file in the current file list.
     // If not found save it for later selection (possibly after reload).
-    if SetActiveFileNow(aFilePath) then
+    if SetActiveFileNow(aFilePath, -1) then
       RequestedActiveFile := ''
     else
       RequestedActiveFile := aFilePath;
@@ -692,50 +697,41 @@
   end;
 end;
 
-function TOrderedFileView.SetActiveFileNow(aFilePath: String): Boolean;
+function TOrderedFileView.SetActiveFileNow(aFilePath: String; aLastTopRowIndex: PtrInt): Boolean;
 var
   Index: PtrInt;
+  PathIsAbsolute: Boolean;
 begin
   if aFilePath <> '' then // find correct cursor position in Panel (drawgrid)
   begin
-    if FileSource.GetPathType(aFilePath) = ptAbsolute then
+    PathIsAbsolute := FileSource.GetPathType(aFilePath) = ptAbsolute;
+    for Index := 0 to FFiles.Count - 1 do
     begin
-      for Index := 0 to FFiles.Count - 1 do
+      if PathIsAbsolute then
+        Result := (FFiles[Index].FSFile.FullPath = aFilePath)
+      else
+        Result := (FFiles[Index].FSFile.Name = aFilePath);
+
+      if Result then
       begin
-        if FFiles[Index].FSFile.FullPath = aFilePath then
-        begin
-          FUpdatingActiveFile := True;
-          SetActiveFile(Index);
-          FUpdatingActiveFile := False;
-          SetLastActiveFile(Index);
-          Exit(True);
-        end;
+        FUpdatingActiveFile := True;
+        SetActiveFile(Index, aLastTopRowIndex);
+        FUpdatingActiveFile := False;
+        SetLastActiveFile(Index, aLastTopRowIndex);
+        Exit;
       end;
-    end
-    else
-    begin
-      for Index := 0 to FFiles.Count - 1 do
-      begin
-        if FFiles[Index].FSFile.Name = aFilePath then
-        begin
-          FUpdatingActiveFile := True;
-          SetActiveFile(Index);
-          FUpdatingActiveFile := False;
-          SetLastActiveFile(Index);
-          Exit(True);
-        end;
-      end;
     end;
   end;
   Result := False;
 end;
 
-procedure TOrderedFileView.SetLastActiveFile(FileIndex: PtrInt);
+procedure TOrderedFileView.SetLastActiveFile(FileIndex, TopRowIndex: PtrInt);
 begin
   if IsFileIndexInRange(FileIndex) then
   begin
     LastActiveFile := FFiles[FileIndex].FSFile.FullPath;
     FLastActiveFileIndex := FileIndex;
+    FLastTopRowIndex := TopRowIndex;
   end;
 end;
 
Index: src/fviewoperations.pas
===================================================================
--- src/fviewoperations.pas	(revision 5463)
+++ src/fviewoperations.pas	(working copy)
@@ -1,4 +1,4 @@
-unit fViewOperations; 
+unit fViewOperations;
 
 {$mode objfpc}{$H+}
 
@@ -863,7 +863,7 @@
       Pen.Style := psSolid;
 
       HalfSize := ExpandSignSize shr 1;
-      if ((ExpandSignSize and 1) = 0) then
+      if not Odd(ExpandSignSize) then
         dec(HalfSize);
       ALeft := MidX - HalfSize;
       ATop := MidY - HalfSize;
