Skip to content

Commit 2232525

Browse files
committed
Merge pull request #2 from fsfod/filereload-improvments
Improved modified file reload behavior
2 parents 67ced7d + 288dfe4 commit 2232525

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/Frontend/MainFrame.cpp

+33-1
Original file line numberDiff line numberDiff line change
@@ -5231,8 +5231,40 @@ void MainFrame::GetNotebookTabSelectedFileNames(std::vector<std::string>& fileNa
52315231

52325232
void MainFrame::ReloadFile(OpenFile* file)
52335233
{
5234-
file->edit->LoadFile(file->file->fileName.GetFullPath());
5234+
5235+
CodeEdit& editor = *file->edit;
5236+
int oldScrollPos = editor.GetScrollPos(wxVSCROLL);
5237+
5238+
//Disable modified events so OnCodeEditModified is not called
5239+
editor.SetModEventMask(0);
5240+
5241+
editor.LoadFile(file->file->fileName.GetFullPath());
52355242
file->timeStamp = GetFileModifiedTime(file->file->fileName.GetFullPath());
5243+
5244+
editor.SetModEventMask(wxSCI_MODEVENTMASKALL);
5245+
5246+
int newLineCount = editor.GetLineCount();
5247+
5248+
std::vector<unsigned int>& breakpoints = file->file->breakpoints;
5249+
5250+
//Erase breakpoints past the end of the file and re-add the markers for the rest
5251+
for (std::vector<unsigned int>::iterator it = breakpoints.begin(); it != breakpoints.end() ;)
5252+
{
5253+
if (*it >= newLineCount)
5254+
{
5255+
it = breakpoints.erase(it);
5256+
}
5257+
else
5258+
{
5259+
UpdateFileBreakpoint(file, *it, true);
5260+
it++;
5261+
}
5262+
}
5263+
5264+
m_breakpointsWindow->UpdateBreakpoints(file->file);
5265+
5266+
//Scroll the editor back to the same line we were before the reload
5267+
editor.ScrollToLine(oldScrollPos < newLineCount ? oldScrollPos : newLineCount);
52365268
}
52375269

52385270
void MainFrame::FindInFiles(const wxString& text, const wxArrayString& fileNames, bool matchCase, bool matchWholeWord, const wxString& baseDirectory)

0 commit comments

Comments
 (0)