ely-mark: rustfmt the files R3.1 left unformatted
Formatting alone; cargo fmt --check failed on these six. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
256240c365
commit
d07f0ddb7c
6 files changed
+168
-56
No files matched your search
@@ -196,8 +196,8 @@ impl Desk {
|
||||
mod tests {
|
||||
use ely_gpui_component::documents::DocumentLook;
|
||||
use gpui::{
|
||||
Entity, Modifiers, ScrollDelta, ScrollWheelEvent, TestAppContext, VisualTestContext,
|
||||
point, rems,
|
||||
Entity, Modifiers, ScrollDelta, ScrollWheelEvent, TestAppContext, VisualTestContext, point,
|
||||
rems,
|
||||
};
|
||||
|
||||
use crate::desk::{
|
||||
@@ -286,8 +286,11 @@ mod tests {
|
||||
tempfile::tempdir().expect("files"),
|
||||
);
|
||||
let path = files.path().join("a.md");
|
||||
std::fs::write(&path, "a
|
||||
").expect("a file");
|
||||
std::fs::write(
|
||||
&path, "a
|
||||
",
|
||||
)
|
||||
.expect("a file");
|
||||
let (desk, cx) = start(cx, data.path());
|
||||
open(&desk, &path, cx);
|
||||
let focus = desk.read_with(cx, |desk, _| desk.core.focus.clone());
|
||||
@@ -300,12 +303,22 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
let other = match cfg!(target_os = "macos") {
|
||||
true => Modifiers { control: true, ..Default::default() },
|
||||
false => Modifiers { platform: true, ..Default::default() },
|
||||
true => Modifiers {
|
||||
control: true,
|
||||
..Default::default()
|
||||
},
|
||||
false => Modifiers {
|
||||
platform: true,
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
cx.simulate_event(wheel(other, 3.0));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(document_look(&desk, cx).scale, 1.0, "only Ctrl, or Cmd on macOS");
|
||||
assert_eq!(
|
||||
document_look(&desk, cx).scale,
|
||||
1.0,
|
||||
"only Ctrl, or Cmd on macOS"
|
||||
);
|
||||
cx.simulate_event(wheel(Modifiers::secondary_key(), 3.0));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(document_look(&desk, cx).scale, 1.1, "a notch is one step");
|
||||
|
||||
@@ -293,7 +293,13 @@ impl Desk {
|
||||
}
|
||||
|
||||
/// A new file with the saved text; edits stay.
|
||||
fn keep_edits(&mut self, id: u64, disk: Source, fingerprint: Fingerprint, cx: &mut Context<Self>) {
|
||||
fn keep_edits(
|
||||
&mut self,
|
||||
id: u64,
|
||||
disk: Source,
|
||||
fingerprint: Fingerprint,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let Some(tab) = self.tab_mut(id) else {
|
||||
return;
|
||||
};
|
||||
@@ -398,7 +404,10 @@ fn watch(dirs: &[PathBuf], cx: &mut Context<Desk>) -> notify::Result<Recommended
|
||||
let (sender, mut changes) = mpsc::unbounded();
|
||||
let mut watcher = notify::recommended_watcher(move |event: notify::Result<notify::Event>| {
|
||||
// Reads, ours included, are no change.
|
||||
if event.as_ref().is_ok_and(|event| ely_ui::watching::only_read(&event.kind)) {
|
||||
if event
|
||||
.as_ref()
|
||||
.is_ok_and(|event| ely_ui::watching::only_read(&event.kind))
|
||||
{
|
||||
return;
|
||||
}
|
||||
let _ = sender.unbounded_send(event.map(|_| ()).map_err(|error| error.to_string()));
|
||||
|
||||
@@ -141,8 +141,11 @@ impl Keeping {
|
||||
/// The untitled tabs to make: their place here and name.
|
||||
pub fn untitled(&self) -> Vec<(usize, String)> {
|
||||
let waiting = self.waiting.iter().enumerate();
|
||||
let untitled = waiting.filter(|(_, waiting)| waiting.kept.path.is_none() && waiting.tab.is_none());
|
||||
untitled.map(|(at, waiting)| (at, waiting.kept.name.clone())).collect()
|
||||
let untitled =
|
||||
waiting.filter(|(_, waiting)| waiting.kept.path.is_none() && waiting.tab.is_none());
|
||||
untitled
|
||||
.map(|(at, waiting)| (at, waiting.kept.name.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Entry `at` belongs to untitled tab `tab`.
|
||||
@@ -152,11 +155,14 @@ impl Keeping {
|
||||
|
||||
/// What tab `id` takes: its file or its copy.
|
||||
fn take(&mut self, real: Option<&PathBuf>, id: u64) -> Option<Waiting> {
|
||||
let at = self.waiting.iter().position(|waiting| match (&waiting.real, real) {
|
||||
(Some(kept), Some(open)) => kept == open,
|
||||
(None, None) => waiting.tab == Some(id),
|
||||
_ => false,
|
||||
})?;
|
||||
let at = self
|
||||
.waiting
|
||||
.iter()
|
||||
.position(|waiting| match (&waiting.real, real) {
|
||||
(Some(kept), Some(open)) => kept == open,
|
||||
(None, None) => waiting.tab == Some(id),
|
||||
_ => false,
|
||||
})?;
|
||||
Some(self.waiting.remove(at))
|
||||
}
|
||||
|
||||
@@ -243,7 +249,9 @@ impl Desk {
|
||||
// Modes take focus: in the window, after this update.
|
||||
cx.spawn(async move |desk, cx| {
|
||||
let shown = ely_office::in_window(&desk, cx, |_, window, cx| {
|
||||
view.update(cx, |view, cx| view.reopen(mode, kept.place, back, window, cx))
|
||||
view.update(cx, |view, cx| {
|
||||
view.reopen(mode, kept.place, back, window, cx)
|
||||
})
|
||||
});
|
||||
if let Err(error) = shown {
|
||||
log::warn!("mark: tab {id} did not restore: {error:#}");
|
||||
@@ -285,7 +293,8 @@ impl Desk {
|
||||
.spawn(async move {
|
||||
let now = SystemTime::now();
|
||||
let limits = ely_platform::storage::limits(ely_platform::AppId::Mark)?;
|
||||
let mut recovery = Recovery::new(folder).with_limits(limits.keep, limits.megabytes * 1024 * 1024);
|
||||
let mut recovery = Recovery::new(folder)
|
||||
.with_limits(limits.keep, limits.megabytes * 1024 * 1024);
|
||||
recovery.write_once(current.as_bytes(), None, now)
|
||||
})
|
||||
.await;
|
||||
@@ -350,7 +359,11 @@ impl Desk {
|
||||
None => text(cx, "office.stopped.never", &[]).to_string(),
|
||||
};
|
||||
let name = tab.name.to_string();
|
||||
let said = text(cx, "mark.recovery.failed", &[("name", &name), ("error", &error), ("at", &at)]);
|
||||
let said = text(
|
||||
cx,
|
||||
"mark.recovery.failed",
|
||||
&[("name", &name), ("error", &error), ("at", &at)],
|
||||
);
|
||||
self.toast_unlogged(said, ely_gpui_component::primitives::Severity::Danger, cx);
|
||||
}
|
||||
|
||||
|
||||
+38
-15
@@ -15,8 +15,7 @@ use ely_office::prelude::*;
|
||||
use ely_ui::{commands, i18n::text};
|
||||
use gpui::{
|
||||
AnyElement, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render,
|
||||
SharedString, Styled as _, WeakEntity, Window, div,
|
||||
ParentElement as _, Render, SharedString, Styled as _, WeakEntity, Window, div,
|
||||
};
|
||||
|
||||
use crate::desk::Desk;
|
||||
@@ -251,17 +250,21 @@ impl Side {
|
||||
},
|
||||
);
|
||||
let outline = outline.on_select(move |key, window, cx| {
|
||||
let Some(heading) = key.parse::<usize>().ok().and_then(|at| headings.get(at)) else {
|
||||
return log::error!("mark: the outline chose no heading");
|
||||
};
|
||||
// The heading in view, the caret on it.
|
||||
let line = heading.line;
|
||||
view.update(cx, |view, cx| view.reveal((line, 0), window, cx));
|
||||
});
|
||||
let Some(heading) = key.parse::<usize>().ok().and_then(|at| headings.get(at)) else {
|
||||
return log::error!("mark: the outline chose no heading");
|
||||
};
|
||||
// The heading in view, the caret on it.
|
||||
let line = heading.line;
|
||||
view.update(cx, |view, cx| view.reveal((line, 0), window, cx));
|
||||
});
|
||||
ScrollArea::new("mark-outline-scroll")
|
||||
.vertical()
|
||||
.size_full()
|
||||
.child(div().debug_selector(|| "mark-outline".into()).child(outline))
|
||||
.child(
|
||||
div()
|
||||
.debug_selector(|| "mark-outline".into())
|
||||
.child(outline),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
@@ -269,9 +272,17 @@ impl Side {
|
||||
let this = cx.entity();
|
||||
let scope = SegmentedControl::new("mark-scope", if self.wide { "folder" } else { "file" })
|
||||
.size(ControlSize::Sm)
|
||||
.segment("file", text(cx, "mark.search.file", &[]), Some(IconName::File));
|
||||
.segment(
|
||||
"file",
|
||||
text(cx, "mark.search.file", &[]),
|
||||
Some(IconName::File),
|
||||
);
|
||||
let scope = match desk.read(cx).folder {
|
||||
Some(_) => scope.segment("folder", text(cx, "mark.search.folder", &[]), Some(IconName::Folder)),
|
||||
Some(_) => scope.segment(
|
||||
"folder",
|
||||
text(cx, "mark.search.folder", &[]),
|
||||
Some(IconName::Folder),
|
||||
),
|
||||
None => scope,
|
||||
};
|
||||
let scope = scope.on_change(move |key, _, cx| {
|
||||
@@ -350,9 +361,21 @@ impl Render for Side {
|
||||
};
|
||||
let panes = SegmentedControl::new("mark-pane", key)
|
||||
.size(ControlSize::Sm)
|
||||
.segment("files", text(cx, "mark.pane.files", &[]), Some(IconName::Folder))
|
||||
.segment("outline", text(cx, "mark.pane.outline", &[]), Some(IconName::List))
|
||||
.segment("search", text(cx, "mark.pane.search", &[]), Some(IconName::Search))
|
||||
.segment(
|
||||
"files",
|
||||
text(cx, "mark.pane.files", &[]),
|
||||
Some(IconName::Folder),
|
||||
)
|
||||
.segment(
|
||||
"outline",
|
||||
text(cx, "mark.pane.outline", &[]),
|
||||
Some(IconName::List),
|
||||
)
|
||||
.segment(
|
||||
"search",
|
||||
text(cx, "mark.pane.search", &[]),
|
||||
Some(IconName::Search),
|
||||
)
|
||||
.on_change(move |key, _, cx| {
|
||||
this.update(cx, |side, cx| {
|
||||
side.pane = match key.as_ref() {
|
||||
|
||||
+69
-20
@@ -1,9 +1,6 @@
|
||||
//! Whether Git sees the file changed; ElyTree does the rest.
|
||||
|
||||
use std::{
|
||||
io,
|
||||
path::Path,
|
||||
};
|
||||
use std::{io, path::Path};
|
||||
|
||||
use ely_gpui_component::{primitives::Severity, shell::StatusBarItem};
|
||||
use ely_office::prelude::*;
|
||||
@@ -145,7 +142,10 @@ impl Desk {
|
||||
}
|
||||
let (this, file) = (this.clone(), file.clone());
|
||||
cx.spawn(async move |cx| {
|
||||
let opened = cx.background_executor().spawn(async move { ely_platform::apps::open(AppId::Tree, &[file]) }).await;
|
||||
let opened = cx
|
||||
.background_executor()
|
||||
.spawn(async move { ely_platform::apps::open(AppId::Tree, &[file]) })
|
||||
.await;
|
||||
if let Err(error) = opened {
|
||||
log::error!("mark: ElyTree did not open: {error}");
|
||||
cx.update(|cx| {
|
||||
@@ -176,7 +176,9 @@ mod tests {
|
||||
fn spaces_stay_and_broken_repositories_say_why() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
// Windows names end in no space.
|
||||
let repo = dir.path().join(if cfg!(windows) { "re po" } else { "repo " });
|
||||
let repo = dir
|
||||
.path()
|
||||
.join(if cfg!(windows) { "re po" } else { "repo " });
|
||||
std::fs::create_dir(&repo).expect("the folder");
|
||||
git(&repo, &["init", "-q"]);
|
||||
std::fs::write(repo.join("t.md"), "a").expect("a file");
|
||||
@@ -193,11 +195,28 @@ mod tests {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let repo = dir.path();
|
||||
git(repo, &["init", "-q"]);
|
||||
std::fs::write(repo.join(".gitignore"), "skip.md
|
||||
").expect("ignores");
|
||||
std::fs::write(
|
||||
repo.join(".gitignore"),
|
||||
"skip.md
|
||||
",
|
||||
)
|
||||
.expect("ignores");
|
||||
std::fs::write(repo.join("t.md"), "a").expect("a file");
|
||||
git(repo, &["add", "."]);
|
||||
git(repo, &["-c", "user.name=T", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", "commit", "-qm", "one"]);
|
||||
git(
|
||||
repo,
|
||||
&[
|
||||
"-c",
|
||||
"user.name=T",
|
||||
"-c",
|
||||
"user.email=t@t",
|
||||
"-c",
|
||||
"commit.gpgsign=false",
|
||||
"commit",
|
||||
"-qm",
|
||||
"one",
|
||||
],
|
||||
);
|
||||
assert_eq!(ask(&repo.join("t.md")), Tracked::Unchanged);
|
||||
std::fs::write(repo.join("t.md"), "b").expect("an edit");
|
||||
assert_eq!(ask(&repo.join("t.md")), Tracked::Changed);
|
||||
@@ -208,30 +227,60 @@ mod tests {
|
||||
#[gpui::test]
|
||||
fn the_status_item_follows_a_save(cx: &mut gpui::TestAppContext) {
|
||||
use ely_office::prelude::*;
|
||||
let (data, dir) = (tempfile::tempdir().expect("data"), tempfile::tempdir().expect("repo"));
|
||||
let (data, dir) = (
|
||||
tempfile::tempdir().expect("data"),
|
||||
tempfile::tempdir().expect("repo"),
|
||||
);
|
||||
let repo = dir.path();
|
||||
git(repo, &["init", "-q"]);
|
||||
std::fs::write(repo.join("t.md"), "a
|
||||
").expect("a file");
|
||||
std::fs::write(
|
||||
repo.join("t.md"),
|
||||
"a
|
||||
",
|
||||
)
|
||||
.expect("a file");
|
||||
git(repo, &["add", "."]);
|
||||
git(repo, &["-c", "user.name=T", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", "commit", "-qm", "one"]);
|
||||
git(
|
||||
repo,
|
||||
&[
|
||||
"-c",
|
||||
"user.name=T",
|
||||
"-c",
|
||||
"user.email=t@t",
|
||||
"-c",
|
||||
"commit.gpgsign=false",
|
||||
"commit",
|
||||
"-qm",
|
||||
"one",
|
||||
],
|
||||
);
|
||||
let (desk, cx) = crate::desk::tests::start(cx, data.path());
|
||||
crate::desk::tests::open(&desk, &repo.join("t.md"), cx);
|
||||
let said = |cx: &mut gpui::VisualTestContext| desk.read_with(cx, |desk, _| desk.tracked.clone());
|
||||
let said =
|
||||
|cx: &mut gpui::VisualTestContext| desk.read_with(cx, |desk, _| desk.tracked.clone());
|
||||
assert_eq!(said(cx), Some(Tracked::Unchanged));
|
||||
let (id, view) = desk.read_with(cx, |desk, _| {
|
||||
let tab = desk.active_tab().expect("a tab");
|
||||
(tab.id, tab.view.clone())
|
||||
});
|
||||
view.update(cx, |view, cx| view.adopt("b
|
||||
".into(), cx));
|
||||
cx.executor().advance_clock(std::time::Duration::from_secs(1));
|
||||
view.update(cx, |view, cx| {
|
||||
view.adopt(
|
||||
"b
|
||||
"
|
||||
.into(),
|
||||
cx,
|
||||
)
|
||||
});
|
||||
cx.executor()
|
||||
.advance_clock(std::time::Duration::from_secs(1));
|
||||
cx.run_until_parked();
|
||||
desk.update_in(cx, |desk, window, cx| desk.save(id, None, window, cx));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(std::fs::read_to_string(repo.join("t.md")).expect("saved"), "b
|
||||
");
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(repo.join("t.md")).expect("saved"),
|
||||
"b
|
||||
"
|
||||
);
|
||||
assert_eq!(said(cx), Some(Tracked::Changed));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,16 @@ fn main() {
|
||||
let app = env::var("CARGO_PKG_NAME").expect("cargo names the package");
|
||||
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("cargo names the folder"));
|
||||
let icon = root.join("../../assets/icons").join(format!("{app}.ico"));
|
||||
let icon = fs::canonicalize(&icon).unwrap_or_else(|error| panic!("{}: {error}", icon.display()));
|
||||
let icon =
|
||||
fs::canonicalize(&icon).unwrap_or_else(|error| panic!("{}: {error}", icon.display()));
|
||||
println!("cargo:rerun-if-changed={}", icon.display());
|
||||
// gpui's window icon is resource 1.
|
||||
let rc = PathBuf::from(env::var("OUT_DIR").expect("cargo gives OUT_DIR")).join("icon.rc");
|
||||
let path = icon.to_str().expect("a UTF-8 path").trim_start_matches(r"\\?\").replace('\\', "/");
|
||||
let path = icon
|
||||
.to_str()
|
||||
.expect("a UTF-8 path")
|
||||
.trim_start_matches(r"\\?\")
|
||||
.replace('\\', "/");
|
||||
fs::write(&rc, format!("1 ICON \"{path}\"\n")).expect("the resource script is written");
|
||||
embed_resource::compile(&rc, embed_resource::NONE)
|
||||
.manifest_optional()
|
||||
|
||||
Reference in new issue
Block a user