Merge pull request #2363 from zed-industries/add-copy-path-commands

Update copy path commands
This commit is contained in:
Joseph T. Lyons 2023-04-07 12:09:39 -04:00 committed by GitHub
commit c58601ab8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 9 deletions

View file

@ -261,6 +261,8 @@ actions!(
Format,
ToggleSoftWrap,
RevealInFinder,
CopyPath,
CopyRelativePath,
CopyHighlightJson
]
);
@ -381,6 +383,8 @@ pub fn init(cx: &mut AppContext) {
cx.add_action(Editor::jump);
cx.add_action(Editor::toggle_soft_wrap);
cx.add_action(Editor::reveal_in_finder);
cx.add_action(Editor::copy_path);
cx.add_action(Editor::copy_relative_path);
cx.add_action(Editor::copy_highlight_json);
cx.add_async_action(Editor::format);
cx.add_action(Editor::restart_language_server);
@ -6252,6 +6256,26 @@ impl Editor {
}
}
pub fn copy_path(&mut self, _: &CopyPath, cx: &mut ViewContext<Self>) {
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) {
if let Some(path) = file.abs_path(cx).to_str() {
cx.write_to_clipboard(ClipboardItem::new(path.to_string()));
}
}
}
}
pub fn copy_relative_path(&mut self, _: &CopyRelativePath, cx: &mut ViewContext<Self>) {
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) {
if let Some(path) = file.path().to_str() {
cx.write_to_clipboard(ClipboardItem::new(path.to_string()));
}
}
}
}
pub fn highlight_rows(&mut self, rows: Option<Range<u32>>) {
self.highlighted_rows = rows;
}