MG: history jumps now works without double jumps

git-svn-id: trunk@2784 -
This commit is contained in:
lazarus 2002-08-18 08:54:04 +00:00
parent 336984eb44
commit ba9b7722bd
2 changed files with 105 additions and 42 deletions

View File

@ -6510,8 +6510,6 @@ begin
if DeleteForwardHistory then Project1.JumpHistory.DeleteForwardHistory; if DeleteForwardHistory then Project1.JumpHistory.DeleteForwardHistory;
Project1.JumpHistory.InsertSmart(Project1.JumpHistory.HistoryIndex+1, Project1.JumpHistory.InsertSmart(Project1.JumpHistory.HistoryIndex+1,
NewJumpPoint); NewJumpPoint);
if Project1.JumpHistory.HistoryIndex=Project1.JumpHistory.Count-2 then
Project1.JumpHistory.HistoryIndex:=Project1.JumpHistory.Count-1;
//writeln('[TMainIDE.OnSrcNoteBookAddJumpPoint] END Line=',ACaretXY.Y,',DeleteForwardHistory=',DeleteForwardHistory,' Count=',Project1.JumpHistory.Count,',HistoryIndex=',Project1.JumpHistory.HistoryIndex); //writeln('[TMainIDE.OnSrcNoteBookAddJumpPoint] END Line=',ACaretXY.Y,',DeleteForwardHistory=',DeleteForwardHistory,' Count=',Project1.JumpHistory.Count,',HistoryIndex=',Project1.JumpHistory.HistoryIndex);
//Project1.JumpHistory.WriteDebugReport; //Project1.JumpHistory.WriteDebugReport;
end; end;
@ -6523,54 +6521,94 @@ end;
Procedure TMainIDE.OnSrcNotebookJumpToHistoryPoint(var NewCaretXY: TPoint; Procedure TMainIDE.OnSrcNotebookJumpToHistoryPoint(var NewCaretXY: TPoint;
var NewTopLine, NewPageIndex: integer; Action: TJumpHistoryAction); var NewTopLine, NewPageIndex: integer; Action: TJumpHistoryAction);
var DestIndex, UnitIndex, NewHistoryIndex: integer; { How the HistoryIndex works:
ActiveSrcEdit: TSourceEditor;
When the user jumps around each time an item is added to the history list
and the HistoryIndex points to the last added item (i.e. Count-1).
Jumping back:
The sourceditor will be repositioned to the item with the HistoryIndex.
Then the historyindex is moved to the previous item.
If HistoryIndex is the last item in the history, then this is the first
back jump and the current sourceeditor position is smart added to the
history list. Smart means that if the added Item is similar to the last
item then the last item will be replaced else a new item is added.
Jumping forward:
}
var DestIndex, UnitIndex: integer;
ASrcEdit: TSourceEditor;
AnUnitInfo: TUnitInfo;
DestJumpPoint: TProjectJumpHistoryPosition; DestJumpPoint: TProjectJumpHistoryPosition;
CursorPoint, NewJumpPoint: TProjectJumpHistoryPosition;
begin begin
//writeln('[TMainIDE.OnSrcNotebookJumpToHistoryPoint] A Back=',Action=jhaBack); //writeln('[TMainIDE.OnSrcNotebookJumpToHistoryPoint] A Back=',Action=jhaBack);
{ jumping back/forward is also a jump, that's why the current source position
should be saved to the jump history before the jump.
The InsertSmart method prevents putting positions twice in the history. }
// update jump history (e.g. delete jumps to closed editors) // update jump history (e.g. delete jumps to closed editors)
Project1.JumpHistory.DeleteInvalidPositions; Project1.JumpHistory.DeleteInvalidPositions;
//writeln('[TMainIDE.OnSrcNotebookJumpToHistoryPoint] B Count=',Project1.JumpHistory.Count,',HistoryIndex=',Project1.JumpHistory.HistoryIndex); // get destination jump point
DestIndex:=Project1.JumpHistory.HistoryIndex; DestIndex:=Project1.JumpHistory.HistoryIndex;
if Action=jhaForward then begin if Action=jhaForward then
inc(DestIndex,2); inc(DestIndex);
if DestIndex=Project1.JumpHistory.Count then
Dec(DestIndex);
end;
if (DestIndex<0) or (DestIndex>=Project1.JumpHistory.Count) then exit; if (DestIndex<0) or (DestIndex>=Project1.JumpHistory.Count) then exit;
DestJumpPoint:=Project1.JumpHistory[DestIndex];
//writeln('[TMainIDE.OnSrcNotebookJumpToHistoryPoint] C Line=',DestJumpPoint.CaretXY.Y);
NewHistoryIndex:=Project1.JumpHistory.HistoryIndex;
if Action=jhaBack then begin
dec(NewHistoryIndex);
if Project1.JumpHistory.HistoryIndex=Project1.JumpHistory.Count-1 then begin
// insert current source position into history
if SourceNoteBook.NoteBook=nil then exit;
ActiveSrcEdit:=SourceNotebook.GetActiveSE;
if (ActiveSrcEdit=nil) then exit;
OnSrcNoteBookAddJumpPoint(ActiveSrcEdit.EditorComponent.CaretXY,
ActiveSrcEdit.EditorComponent.TopLine,SourceNotebook.Notebook.PageIndex,
false);
end;
end else
inc(NewHistoryIndex);
Project1.JumpHistory.HistoryIndex:=NewHistoryIndex;
UnitIndex:=Project1.IndexOfFilename(DestJumpPoint.Filename); CursorPoint:=nil;
if (UnitIndex>=0) and (Project1.Units[UnitIndex].EditorIndex>=0) then begin if (SourceNoteBook<>nil) then begin
with Project1.JumpHistory do begin // this is the first back jump
NewCaretXY:=DestJumpPoint.CaretXY; // -> insert current source position into history
NewTopLine:=DestJumpPoint.TopLine; GetCurrentUnit(ASrcEdit,AnUnitInfo);
if (ASrcEdit<>nil) and (AnUnitInfo<>nil) then begin
CursorPoint:=TProjectJumpHistoryPosition.Create(AnUnitInfo.Filename,
ASrcEdit.EditorComponent.CaretXY,ASrcEdit.EditorComponent.TopLine);
//writeln(' Current Position: ',CursorPoint.Filename,
// ' ',CursorPoint.CaretXY.X,',',CursorPoint.CaretXY.Y);
end; end;
NewPageIndex:=Project1.Units[UnitIndex].EditorIndex;
end; end;
//writeln('[TMainIDE.OnSrcNotebookJumpToHistoryPoint] END Count=',Project1.JumpHistory.Count,',HistoryIndex=',Project1.JumpHistory.HistoryIndex);
//Project1.JumpHistory.WriteDebugReport; if (Action=jhaBack) and (Project1.JumpHistory.Count=DestIndex+1)
and (CursorPoint<>nil) then begin
// this is the first back jump
// -> insert current source position into history
//writeln(' First back jump -> add current cursor position');
NewJumpPoint:=TProjectJumpHistoryPosition.Create(CursorPoint);
Project1.JumpHistory.InsertSmart(Project1.JumpHistory.HistoryIndex+1,
NewJumpPoint);
end;
// find the next jump point that is not where the cursor is
DestIndex:=Project1.JumpHistory.HistoryIndex;
if Action=jhaForward then
inc(DestIndex);
while (DestIndex>=0) or (DestIndex<Project1.JumpHistory.Count) do begin
DestJumpPoint:=Project1.JumpHistory[DestIndex];
//writeln(' DestIndex=',DestIndex);
if (CursorPoint=nil)
or not DestJumpPoint.IsSimilar(CursorPoint) then begin
if Action=jhaBack then
dec(DestIndex);
Project1.JumpHistory.HistoryIndex:=DestIndex;
UnitIndex:=Project1.IndexOfFilename(DestJumpPoint.Filename);
if (UnitIndex>=0) and (Project1.Units[UnitIndex].EditorIndex>=0) then
begin
NewCaretXY:=DestJumpPoint.CaretXY;
NewTopLine:=DestJumpPoint.TopLine;
NewPageIndex:=Project1.Units[UnitIndex].EditorIndex;
//writeln('[TMainIDE.OnSrcNotebookJumpToHistoryPoint] Result Line=',NewCaretXY.Y,' Col=',NewCaretXY.X);
break;
end;
end;
if Action=jhaBack then
dec(DestIndex)
else
inc(DestIndex);
end;
CursorPoint.Free;
//writeln('[TMainIDE.OnSrcNotebookJumpToHistoryPoint] END Count=',Project1.JumpHistory.Count,',HistoryIndex=',Project1.JumpHistory.HistoryIndex);
//Project1.JumpHistory.WriteDebugReport;
end; end;
Procedure TMainIDE.OnSrcNotebookViewJumpHistory(Sender : TObject); Procedure TMainIDE.OnSrcNotebookViewJumpHistory(Sender : TObject);
@ -7145,6 +7183,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.389 2002/09/19 14:54:53 lazarus
MG: history jumps now works without double jumps
Revision 1.388 2002/09/17 22:19:32 lazarus Revision 1.388 2002/09/17 22:19:32 lazarus
MG: fixed creating project from file MG: fixed creating project from file

View File

@ -183,6 +183,7 @@ type
procedure Assign(APosition: TProjectJumpHistoryPosition); procedure Assign(APosition: TProjectJumpHistoryPosition);
constructor Create(const AFilename: string; ACaretXY: TPoint; constructor Create(const AFilename: string; ACaretXY: TPoint;
ATopLine: integer); ATopLine: integer);
constructor Create(APosition: TProjectJumpHistoryPosition);
function IsEqual(APosition: TProjectJumpHistoryPosition): boolean; function IsEqual(APosition: TProjectJumpHistoryPosition): boolean;
function IsSimilar(APosition: TProjectJumpHistoryPosition): boolean; function IsSimilar(APosition: TProjectJumpHistoryPosition): boolean;
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string); procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
@ -581,6 +582,13 @@ begin
FTopLine:=ATopLine; FTopLine:=ATopLine;
end; end;
constructor TProjectJumpHistoryPosition.Create(
APosition: TProjectJumpHistoryPosition);
begin
inherited Create;
Assign(APosition);
end;
procedure TProjectJumpHistoryPosition.Assign( procedure TProjectJumpHistoryPosition.Assign(
APosition: TProjectJumpHistoryPosition); APosition: TProjectJumpHistoryPosition);
begin begin
@ -813,14 +821,28 @@ begin
if Index<0 then Index:=Count; if Index<0 then Index:=Count;
if (Index<=Count) then begin if (Index<=Count) then begin
if (Index>0) and Items[Index-1].IsSimilar(APosition) then begin if (Index>0) and Items[Index-1].IsSimilar(APosition) then begin
//writeln('TProjectJumpHistory.InsertSmart Replacing prev: Index=',Index,
// ' Old=',Items[Index-1].CaretXY.X,',',Items[Index-1].CaretXY.Y,' ',Items[Index-1].Filename,
// ' New=',APosition.CaretXY.X,',',APosition.CaretXY.Y,' ',APosition.Filename,
// ' ');
Items[Index-1]:=APosition; Items[Index-1]:=APosition;
APosition.Free; APosition.Free;
end else if (Index<Count) and Items[Index].IsSimilar(APosition) then begin end else if (Index<Count) and Items[Index].IsSimilar(APosition) then begin
//writeln('TProjectJumpHistory.InsertSmart Replacing next: Index=',Index,
// ' Old=',Items[Index].CaretXY.X,',',Items[Index].CaretXY.Y,' ',Items[Index].Filename,
// ' New=',APosition.CaretXY.X,',',APosition.CaretXY.Y,' ',APosition.Filename,
// ' ');
Items[Index]:=APosition; Items[Index]:=APosition;
APosition.Free; APosition.Free;
end else begin end else begin
//writeln('TProjectJumpHistory.InsertSmart Adding: Index=',Index,
// ' New=',APosition.CaretXY.X,',',APosition.CaretXY.Y,' ',APosition.Filename,
// ' ');
Insert(Index,APosition); Insert(Index,APosition);
if (Index=Count-1) and (HistoryIndex=Count-2) then
inc(FHistoryIndex);
end; end;
//writeln(' HistoryIndex=',HistoryIndex);
end else begin end else begin
APosition.Free; APosition.Free;
end; end;