Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions crates/repl/src/notebook/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use settings::Settings as _;
use theme_settings::ThemeSettings;
use ui::{CommonAnimationExt, IconButtonShape, prelude::*};
use util::ResultExt;
use zed_actions::notebook::InterruptKernel;

use crate::{
notebook::{CODE_BLOCK_INSET, GUTTER_WIDTH},
Expand All @@ -32,6 +33,7 @@ pub enum CellPosition {
pub enum CellControlType {
RunCell,
RerunCell,
StopCell,
ClearCell,
CellOptions,
CollapseCell,
Expand All @@ -53,12 +55,24 @@ impl CellControlType {
match self {
CellControlType::RunCell => IconName::PlayFilled,
CellControlType::RerunCell => IconName::ArrowCircle,
CellControlType::StopCell => IconName::Stop,
CellControlType::ClearCell => IconName::ListX,
CellControlType::CellOptions => IconName::Ellipsis,
CellControlType::CollapseCell => IconName::ChevronDown,
CellControlType::ExpandCell => IconName::ChevronRight,
}
}
fn id(&self) -> &'static str {
match self {
CellControlType::RunCell => "CellControlType::RunCell",
CellControlType::RerunCell => "CellControlType::RerunCell",
CellControlType::StopCell => "CellControlType::StopCell",
CellControlType::ClearCell => "CellControlType::ClearCell",
CellControlType::CellOptions => "CellControlType::CellOptions",
CellControlType::CollapseCell => "CellControlType::CollapseCelln",
CellControlType::ExpandCell => "CellControlType::ExpandCell",
}
}
}

pub struct CellControl {
Expand Down Expand Up @@ -951,23 +965,25 @@ impl RenderableCell for CodeCell {
}

fn control(&self, _window: &mut Window, cx: &mut Context<Self>) -> Option<CellControl> {
let control_type = if self.has_outputs() {
let control_type = if self.is_executing {
CellControlType::StopCell
} else if self.has_outputs() {
CellControlType::RerunCell
} else {
CellControlType::RunCell
};

let cell_control = CellControl::new(
if self.has_outputs() {
"rerun-cell"
} else {
"run-cell"
},
control_type,
Some(
CellControl::new(control_type.id(), control_type).on_click(cx.listener(
move |this, _, window, cx| {
if this.is_executing {
window.dispatch_action(Box::new(InterruptKernel), cx);
} else {
this.run(window, cx);
}
},
)),
)
.on_click(cx.listener(move |this, _, window, cx| this.run(window, cx)));

Some(cell_control)
}

fn selected(&self) -> bool {
Expand Down
Loading