mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 02:47:34 +03:00
Map initial approach to string opening
This commit is contained in:
parent
f52722b6a4
commit
23f25562b5
@ -72,9 +72,10 @@ const DEBUG_TERMINAL_HEIGHT: f32 = 30.;
|
|||||||
const DEBUG_CELL_WIDTH: f32 = 5.;
|
const DEBUG_CELL_WIDTH: f32 = 5.;
|
||||||
const DEBUG_LINE_HEIGHT: f32 = 5.;
|
const DEBUG_LINE_HEIGHT: f32 = 5.;
|
||||||
|
|
||||||
// Regex Copied from alacritty's ui_config.rs
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
// Regex Copied from alacritty's ui_config.rs
|
||||||
|
pub static ref URL_REGEX: RegexSearch = RegexSearch::new("(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)[^\u{0000}-\u{001F}\u{007F}-\u{009F}<>\"\\s{-}\\^⟨⟩`]+").unwrap();
|
||||||
|
|
||||||
static ref WORD_REGEX: RegexSearch = RegexSearch::new("[\\w.:/@-]+").unwrap();
|
static ref WORD_REGEX: RegexSearch = RegexSearch::new("[\\w.:/@-]+").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,10 +261,14 @@ impl TerminalPanel {
|
|||||||
.create_terminal(working_directory, window_id, cx)
|
.create_terminal(working_directory, window_id, cx)
|
||||||
.log_err()
|
.log_err()
|
||||||
}) {
|
}) {
|
||||||
let terminal =
|
let terminal = Box::new(cx.add_view(|cx| {
|
||||||
Box::new(cx.add_view(|cx| {
|
TerminalView::new(
|
||||||
TerminalView::new(terminal, workspace.database_id(), cx)
|
terminal,
|
||||||
}));
|
workspace.weak_handle(),
|
||||||
|
workspace.database_id(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
}));
|
||||||
pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
let focus = pane.has_focus();
|
let focus = pane.has_focus();
|
||||||
pane.add_item(terminal, true, focus, None, cx);
|
pane.add_item(terminal, true, focus, None, cx);
|
||||||
|
@ -32,7 +32,7 @@ use terminal::{
|
|||||||
},
|
},
|
||||||
Event, Terminal, TerminalBlink, WorkingDirectory,
|
Event, Terminal, TerminalBlink, WorkingDirectory,
|
||||||
};
|
};
|
||||||
use util::ResultExt;
|
use util::{paths::PathLikeWithPosition, ResultExt};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{BreadcrumbText, Item, ItemEvent},
|
item::{BreadcrumbText, Item, ItemEvent},
|
||||||
notifications::NotifyResultExt,
|
notifications::NotifyResultExt,
|
||||||
@ -117,19 +117,27 @@ impl TerminalView {
|
|||||||
.notify_err(workspace, cx);
|
.notify_err(workspace, cx);
|
||||||
|
|
||||||
if let Some(terminal) = terminal {
|
if let Some(terminal) = terminal {
|
||||||
let view = cx.add_view(|cx| TerminalView::new(terminal, workspace.database_id(), cx));
|
let view = cx.add_view(|cx| {
|
||||||
|
TerminalView::new(
|
||||||
|
terminal,
|
||||||
|
workspace.weak_handle(),
|
||||||
|
workspace.database_id(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
workspace.add_item(Box::new(view), cx)
|
workspace.add_item(Box::new(view), cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
terminal: ModelHandle<Terminal>,
|
terminal: ModelHandle<Terminal>,
|
||||||
|
workspace: WeakViewHandle<Workspace>,
|
||||||
workspace_id: WorkspaceId,
|
workspace_id: WorkspaceId,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let view_id = cx.view_id();
|
let view_id = cx.view_id();
|
||||||
cx.observe(&terminal, |_, _, cx| cx.notify()).detach();
|
cx.observe(&terminal, |_, _, cx| cx.notify()).detach();
|
||||||
cx.subscribe(&terminal, |this, _, event, cx| match event {
|
cx.subscribe(&terminal, move |this, _, event, cx| match event {
|
||||||
Event::Wakeup => {
|
Event::Wakeup => {
|
||||||
if !cx.is_self_focused() {
|
if !cx.is_self_focused() {
|
||||||
this.has_new_content = true;
|
this.has_new_content = true;
|
||||||
@ -158,12 +166,30 @@ impl TerminalView {
|
|||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Open(url) => {
|
Event::Open(maybe_url_or_path) => {
|
||||||
// TODO kb
|
// TODO kb, what is the API for this?
|
||||||
// Get a workspace pointer from the new() function above
|
// terminal::URL_REGEX.matches(maybe_url_or_path)
|
||||||
// Guess for project path or url
|
if maybe_url_or_path.starts_with("http") {
|
||||||
// Either run open buffer action OR platform open depending on whatever happens
|
cx.platform().open_url(maybe_url_or_path);
|
||||||
cx.platform().open_url(url);
|
} else if let Some(workspace) = workspace.upgrade(cx) {
|
||||||
|
let path_like =
|
||||||
|
PathLikeWithPosition::parse_str(maybe_url_or_path.as_str(), |path_str| {
|
||||||
|
Ok::<_, std::convert::Infallible>(Path::new(path_str).to_path_buf())
|
||||||
|
})
|
||||||
|
.expect("infallible");
|
||||||
|
let maybe_path = path_like.path_like;
|
||||||
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
if false { //&& workspace.contains_path() {
|
||||||
|
//
|
||||||
|
} else if maybe_path.exists() {
|
||||||
|
workspace
|
||||||
|
.open_abs_path(maybe_path, true, cx)
|
||||||
|
.detach_and_log_err(cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO kb let terminal know if we cannot open the string
|
||||||
}
|
}
|
||||||
_ => cx.emit(event.clone()),
|
_ => cx.emit(event.clone()),
|
||||||
})
|
})
|
||||||
@ -639,7 +665,7 @@ impl Item for TerminalView {
|
|||||||
project.create_terminal(cwd, window_id, cx)
|
project.create_terminal(cwd, window_id, cx)
|
||||||
})?;
|
})?;
|
||||||
Ok(pane.update(&mut cx, |_, cx| {
|
Ok(pane.update(&mut cx, |_, cx| {
|
||||||
cx.add_view(|cx| TerminalView::new(terminal, workspace_id, cx))
|
cx.add_view(|cx| TerminalView::new(terminal, workspace, workspace_id, cx))
|
||||||
})?)
|
})?)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -895,7 +895,14 @@ pub fn dock_default_item_factory(
|
|||||||
})
|
})
|
||||||
.notify_err(workspace, cx)?;
|
.notify_err(workspace, cx)?;
|
||||||
|
|
||||||
let terminal_view = cx.add_view(|cx| TerminalView::new(terminal, workspace.database_id(), cx));
|
let terminal_view = cx.add_view(|cx| {
|
||||||
|
TerminalView::new(
|
||||||
|
terminal,
|
||||||
|
workspace.weak_handle(),
|
||||||
|
workspace.database_id(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
Some(Box::new(terminal_view))
|
Some(Box::new(terminal_view))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user