mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
HackStudio: Make sure project files are created with an absolute path
This fixes an issue were "Find in Files" would not use the up-to-date content of a file with unsaved changes. The issue existed because 'FindInFilesWidget' uses Project::for_each_text_file, which retrieves files by their absolute path. However, when a file is opened in an Editor, it is created with a relative path. This caused us to store two ProjectFile objects that refer to the same file - one with a relative path and one with an absolute path.
This commit is contained in:
parent
74070ef74d
commit
fa4d9da237
2 changed files with 15 additions and 4 deletions
|
@ -70,15 +70,24 @@ void Project::for_each_text_file(Function<void(const ProjectFile&)> callback) co
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<ProjectFile> Project::get_file(const String& path) const
|
NonnullRefPtr<ProjectFile> Project::get_file(const String& path) const
|
||||||
{
|
{
|
||||||
|
auto full_path = to_absolute_path(path);
|
||||||
for (auto& file : m_files) {
|
for (auto& file : m_files) {
|
||||||
if (file.name() == path)
|
if (file.name() == full_path)
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
auto file = ProjectFile::construct_with_name(path);
|
auto file = ProjectFile::construct_with_name(full_path);
|
||||||
m_files.append(file);
|
m_files.append(file);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String Project::to_absolute_path(const String& path) const
|
||||||
|
{
|
||||||
|
if (LexicalPath { path }.is_absolute()) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
return LexicalPath { String::formatted("{}/{}", m_root_path, path) }.string();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,15 @@ public:
|
||||||
String name() const { return LexicalPath(m_root_path).basename(); }
|
String name() const { return LexicalPath(m_root_path).basename(); }
|
||||||
String root_path() const { return m_root_path; }
|
String root_path() const { return m_root_path; }
|
||||||
|
|
||||||
RefPtr<ProjectFile> get_file(const String& path) const;
|
NonnullRefPtr<ProjectFile> get_file(const String& path) const;
|
||||||
|
|
||||||
void for_each_text_file(Function<void(const ProjectFile&)>) const;
|
void for_each_text_file(Function<void(const ProjectFile&)>) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Project(const String& root_path);
|
explicit Project(const String& root_path);
|
||||||
|
|
||||||
|
String to_absolute_path(const String&) const;
|
||||||
|
|
||||||
RefPtr<GUI::FileSystemModel> m_model;
|
RefPtr<GUI::FileSystemModel> m_model;
|
||||||
mutable NonnullRefPtrVector<ProjectFile> m_files;
|
mutable NonnullRefPtrVector<ProjectFile> m_files;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue