Add editor::OpenUrl action and bind to gx in Vim mode (#7972)
This adds one feature I've been missing a lot in Vim mode: `gx` to open the URL under the cursor. Technically, in Vim, `gx` opens more "paths", not just URLs, but I think this is a good start. Release Notes: - Added `gx` to Vim mode to open the URL under the cursor. Demo: https://github.com/zed-industries/zed/assets/1185253/6a19490d-b61d-40b7-93e8-4819599f6977
This commit is contained in:
@@ -123,6 +123,8 @@ use util::{maybe, post_inc, RangeExt, ResultExt, TryFutureExt};
|
||||
use workspace::Toast;
|
||||
use workspace::{searchable::SearchEvent, ItemNavHistory, Pane, SplitDirection, ViewId, Workspace};
|
||||
|
||||
use crate::hover_links::find_url;
|
||||
|
||||
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
|
||||
const MAX_LINE_LEN: usize = 1024;
|
||||
const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
|
||||
@@ -7368,6 +7370,28 @@ impl Editor {
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
pub fn open_url(&mut self, _: &OpenUrl, cx: &mut ViewContext<Self>) {
|
||||
let position = self.selections.newest_anchor().head();
|
||||
let Some((buffer, buffer_position)) = self
|
||||
.buffer
|
||||
.read(cx)
|
||||
.text_anchor_for_position(position.clone(), cx)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
cx.spawn(|editor, mut cx| async move {
|
||||
if let Some((_, url)) = find_url(&buffer, buffer_position, cx.clone()) {
|
||||
editor.update(&mut cx, |_, cx| {
|
||||
cx.open_url(&url);
|
||||
})
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
pub fn navigate_to_hover_links(
|
||||
&mut self,
|
||||
mut definitions: Vec<HoverLink>,
|
||||
|
||||
Reference in New Issue
Block a user