-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File explorer and tree helper (v3) #5768
base: master
Are you sure you want to change the base?
Changes from all commits
b652f96
d9d4daa
c446c39
d04a1ce
aa397ef
bdab93e
82fe4a3
0f8b641
458fa1c
2af8b41
44b46dd
5a5a1de
52a26ff
ec2059b
ddb7564
2bafac0
35ffc60
2c221f0
790192d
b38a941
56056e8
a079477
85fa1c5
9bd534b
7249536
94e2c29
374b8dd
c8578ba
30bac64
ef73559
0f8e0a5
70984fd
f0a4b10
4dfa869
c88164f
64059fb
2a60662
2e654a0
2e7709e
a259c20
bcb1672
78bb297
6321dc9
7b63fda
f9ff01d
899491b
6af9a06
9205117
cf9b60a
dffbc15
36769cb
b5d92ac
38ef079
24b50bb
72b845d
ba00a80
601f2c4
ef18502
5d600fe
d578f8a
c3b8be9
c0073ed
4a0c620
7e4feb0
fae4990
8379669
b18a974
19d436e
a2cb28d
43b226a
c2e2f05
a4943a7
8ef95ee
d3db1b6
31c0e84
bc62b76
aa6780e
80a2f86
d62b487
d1e6a21
e991ed9
9726ae7
7ccee10
10032eb
d043ea4
1108c88
eb9287d
20241fb
54b1693
c4c3e80
1780867
9a1aff2
8b561e2
41ebc30
52be2e0
f5af209
afda68a
e5dfde2
1be2ac2
ee34720
404f950
898c167
33542e9
f5aec54
a331e52
eebff62
f37c795
88ac941
cf9669f
e2c3757
2d1ca23
4fe9896
d86abf1
0885057
99e3db4
10f302d
fd80660
2c27974
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -492,6 +492,8 @@ impl MappableCommand { | |||||
record_macro, "Record macro", | ||||||
replay_macro, "Replay macro", | ||||||
command_palette, "Open command palette", | ||||||
open_or_focus_explorer, "Open or focus explorer", | ||||||
reveal_current_file, "Reveal current file in explorer", | ||||||
); | ||||||
} | ||||||
|
||||||
|
@@ -2623,6 +2625,49 @@ fn file_picker_in_current_directory(cx: &mut Context) { | |||||
cx.push_layer(Box::new(overlaid(picker))); | ||||||
} | ||||||
|
||||||
fn open_or_focus_explorer(cx: &mut Context) { | ||||||
cx.callback = Some(Box::new( | ||||||
|compositor: &mut Compositor, cx: &mut compositor::Context| { | ||||||
if let Some(editor) = compositor.find::<ui::EditorView>() { | ||||||
match editor.explorer.as_mut() { | ||||||
Some(explore) => explore.focus(), | ||||||
None => match ui::Explorer::new(cx) { | ||||||
Ok(explore) => editor.explorer = Some(explore), | ||||||
Err(err) => cx.editor.set_error(format!("{}", err)), | ||||||
}, | ||||||
} | ||||||
} | ||||||
}, | ||||||
)); | ||||||
} | ||||||
|
||||||
fn reveal_file(cx: &mut Context, path: Option<PathBuf>) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
since commands are globally namespaced this should be a little more specific about where it's being revealed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may also make sense to call this "focus" or "select" rather than "reveal" to match the vocabulary used in |
||||||
cx.callback = Some(Box::new( | ||||||
|compositor: &mut Compositor, cx: &mut compositor::Context| { | ||||||
if let Some(editor) = compositor.find::<ui::EditorView>() { | ||||||
(|| match editor.explorer.as_mut() { | ||||||
wongjiahau marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Some(explorer) => match path { | ||||||
Some(path) => explorer.reveal_file(path), | ||||||
None => explorer.reveal_current_file(cx), | ||||||
}, | ||||||
None => { | ||||||
editor.explorer = Some(ui::Explorer::new(cx)?); | ||||||
if let Some(explorer) = editor.explorer.as_mut() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is safe to just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
explorer.reveal_current_file(cx)?; | ||||||
} | ||||||
Ok(()) | ||||||
} | ||||||
})() | ||||||
.unwrap_or_else(|err| cx.editor.set_error(err.to_string())) | ||||||
} | ||||||
}, | ||||||
)); | ||||||
Comment on lines
+2645
to
+2664
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The IIFE is really unnatural looking here and elsewhere. It's a pattern we don't use in the codebase at all AFAIK. I'd like to see them all eliminated. This and fn with_explorer<F>(cx: &mut Context, with_explorer_fn: F)
where
F: FnOnce(&mut ui::Explorer, &mut compositor::Context) + 'static,
{
cx.callback = Some(Box::new(
move |compositor: &mut Compositor, cx: &mut compositor::Context| {
let Some(editor) = compositor.find::<ui::EditorView>() else { return };
if let Some(explorer) = editor.explorer.as_mut() {
with_explorer_fn(explorer, cx);
return;
}
// Open the explorer.
let explorer = match ui::Explorer::new(cx) {
Ok(explorer) => {
editor.explorer = Some(explorer);
editor.explorer.as_mut().unwrap()
}
Err(err) => {
cx.editor.set_error(err.to_string());
return;
}
};
with_explorer_fn(explorer, cx);
},
));
} |
||||||
} | ||||||
|
||||||
fn reveal_current_file(cx: &mut Context) { | ||||||
reveal_file(cx, None) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function should have the logic in fn reveal_current_file(cx: &mut Context) {
match doc!(cx.editor).path() {
Some(path) => reveal_file(cx, path.clone()),
None => open_or_focus_explorer(cx),
}
} And this also simplifies |
||||||
} | ||||||
|
||||||
fn buffer_picker(cx: &mut Context) { | ||||||
let current = view!(cx.editor).doc; | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> { | |
"r" => rename_symbol, | ||
"h" => select_references_to_symbol_under_cursor, | ||
"?" => command_palette, | ||
"e" => reveal_current_file, | ||
Comment on lines
279
to
+280
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this binding up so that it's just under |
||
}, | ||
"z" => { "View" | ||
"z" | "c" => align_view_center, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small typo: explore => explorer