Load new math resources in the native Web editor
This commit is contained in:
1 parent
8b6dab8d52
commit
fe86163767
12 files changed
+838
-106
No files matched your search
@@ -151,6 +151,34 @@ impl ProjectSnapshot {
|
||||
next.seal()
|
||||
}
|
||||
|
||||
/// Extend the immutable external inputs without changing project buffers
|
||||
/// or granting writes outside the original project.
|
||||
pub fn with_external_resources(
|
||||
self: &Arc<Self>,
|
||||
resources: &BTreeMap<PathBuf, Arc<[u8]>>,
|
||||
) -> Result<Arc<Self>, String> {
|
||||
if resources.keys().all(|path| self.files.contains_key(path)) {
|
||||
return Ok(self.clone());
|
||||
}
|
||||
let mut next = self.next_revision(self.version.revision)?;
|
||||
for (path, data) in resources {
|
||||
if next.files.contains_key(path) {
|
||||
continue;
|
||||
}
|
||||
if path.starts_with(&self.configuration.cwd) || !self.covered(path) {
|
||||
return Err(format!(
|
||||
"external resource is outside declared roots: {}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
next.files
|
||||
.insert(path.clone(), Self::capture(path.clone(), data.clone()));
|
||||
next.directories
|
||||
.extend(path.ancestors().skip(1).map(Path::to_path_buf));
|
||||
}
|
||||
next.seal()
|
||||
}
|
||||
|
||||
fn next_revision(&self, revision: u64) -> Result<Self, String> {
|
||||
self.validate()?;
|
||||
let mut next = self.clone();
|
||||
|
||||
Reference in new issue
Block a user