Skip to content

Commit

Permalink
implement "Open in GitHub" command
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-observer committed Aug 15, 2024
1 parent 9ca4a99 commit 20358a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lapce-app/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ pub enum LapceWorkbenchCommand {
#[strum(message = "Reveal in Panel")]
RevealInPanel,

#[strum(serialize = "open_in_git_bub")]
#[strum(message = "Open In GitHub")]
OpenInGitHub,

#[cfg(not(target_os = "macos"))]
#[strum(serialize = "reveal_in_file_explorer")]
#[strum(message = "Reveal in System File Explorer")]
Expand Down
1 change: 1 addition & 0 deletions lapce-app/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2743,6 +2743,7 @@ impl EditorData {
Some(CommandKind::Workbench(
LapceWorkbenchCommand::RevealInFileExplorer,
)),
Some(CommandKind::Workbench(LapceWorkbenchCommand::OpenInGitHub)),
None,
Some(CommandKind::Edit(EditCommand::ClipboardCut)),
Some(CommandKind::Edit(EditCommand::ClipboardCopy)),
Expand Down
27 changes: 27 additions & 0 deletions lapce-app/src/window_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use floem::{
peniko::kurbo::{Point, Rect, Vec2},
reactive::{use_context, Memo, ReadSignal, RwSignal, Scope, WriteSignal},
text::{Attrs, AttrsList, FamilyOwned, LineHeightValue, TextLayout},
views::editor::core::buffer::rope_text::RopeText,
ViewId,
};
use indexmap::IndexMap;
Expand Down Expand Up @@ -1392,6 +1393,32 @@ impl WindowTabData {
}
}
}
OpenInGitHub => {
if let Some(editor_data) =
self.main_split.active_editor.get_untracked()
{
if let DocContent::File {path, ..} = editor_data.doc().content.get_untracked() {
let offset = editor_data.cursor().with_untracked(|c| c.offset());
let line = editor_data.doc()
.buffer
.with_untracked(|buffer| buffer.line_of_offset(offset));
self.common.proxy.git_get_remote_file_url(
path,
create_ext_action(self.scope, move |result| {
if let Ok(ProxyResponse::GitGetRemoteFileUrl {
file_url
}) = result
{
if let Err(err) = open::that(format!("{}#L{}", file_url, line)) {
error!("Failed to open file in github: {}", err);
}
}
}),
);

}
}
}
RevealInFileExplorer => {
if let Some(editor_data) =
self.main_split.active_editor.get_untracked()
Expand Down

0 comments on commit 20358a0

Please sign in to comment.