Add open permalink to line
action (#7562)
Release Notes: - Added `open permalink to line` action. --------- Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
17c203fef9
commit
b25044393e
3 changed files with 29 additions and 1 deletions
|
@ -194,6 +194,7 @@ gpui::actions!(
|
||||||
NewlineBelow,
|
NewlineBelow,
|
||||||
NextScreen,
|
NextScreen,
|
||||||
OpenExcerpts,
|
OpenExcerpts,
|
||||||
|
OpenPermalinkToLine,
|
||||||
Outdent,
|
Outdent,
|
||||||
PageDown,
|
PageDown,
|
||||||
PageUp,
|
PageUp,
|
||||||
|
|
|
@ -8393,7 +8393,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_permalink_to_line(&mut self, _: &CopyPermalinkToLine, cx: &mut ViewContext<Self>) {
|
fn get_permalink_to_line(&mut self, cx: &mut ViewContext<Self>) -> Result<url::Url> {
|
||||||
use git::permalink::{build_permalink, BuildPermalinkParams};
|
use git::permalink::{build_permalink, BuildPermalinkParams};
|
||||||
|
|
||||||
let permalink = maybe!({
|
let permalink = maybe!({
|
||||||
|
@ -8439,6 +8439,11 @@ impl Editor {
|
||||||
selection: selection.map(|selection| selection.range()),
|
selection: selection.map(|selection| selection.range()),
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
permalink
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn copy_permalink_to_line(&mut self, _: &CopyPermalinkToLine, cx: &mut ViewContext<Self>) {
|
||||||
|
let permalink = self.get_permalink_to_line(cx);
|
||||||
|
|
||||||
match permalink {
|
match permalink {
|
||||||
Ok(permalink) => {
|
Ok(permalink) => {
|
||||||
|
@ -8458,6 +8463,27 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn open_permalink_to_line(&mut self, _: &OpenPermalinkToLine, cx: &mut ViewContext<Self>) {
|
||||||
|
let permalink = self.get_permalink_to_line(cx);
|
||||||
|
|
||||||
|
match permalink {
|
||||||
|
Ok(permalink) => {
|
||||||
|
cx.open_url(&permalink.to_string());
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
let message = format!("Failed to open permalink: {err}");
|
||||||
|
|
||||||
|
Err::<(), anyhow::Error>(err).log_err();
|
||||||
|
|
||||||
|
if let Some(workspace) = self.workspace() {
|
||||||
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
workspace.show_toast(Toast::new(0x45a8978, message), cx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn highlight_rows(&mut self, rows: Option<Range<u32>>) {
|
pub fn highlight_rows(&mut self, rows: Option<Range<u32>>) {
|
||||||
self.highlighted_rows = rows;
|
self.highlighted_rows = rows;
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,6 +278,7 @@ impl EditorElement {
|
||||||
register_action(view, cx, Editor::copy_relative_path);
|
register_action(view, cx, Editor::copy_relative_path);
|
||||||
register_action(view, cx, Editor::copy_highlight_json);
|
register_action(view, cx, Editor::copy_highlight_json);
|
||||||
register_action(view, cx, Editor::copy_permalink_to_line);
|
register_action(view, cx, Editor::copy_permalink_to_line);
|
||||||
|
register_action(view, cx, Editor::open_permalink_to_line);
|
||||||
register_action(view, cx, |editor, action, cx| {
|
register_action(view, cx, |editor, action, cx| {
|
||||||
if let Some(task) = editor.format(action, cx) {
|
if let Some(task) = editor.format(action, cx) {
|
||||||
task.detach_and_log_err(cx);
|
task.detach_and_log_err(cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue