Skip to content

Commit

Permalink
feat: fix request body ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jincheng.zhang committed Apr 30, 2024
1 parent 33daf77 commit 24357e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions crates/netpurr/src/panels/request_body_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ impl RequestBodyPanel {
Err(_) => {}
}
}
let render_text = netpurr_core::utils::replace_variable(
crt.record.must_get_rest().request.body.body_str.clone(),
envs.clone(),
);
ui.button("Render").on_hover_text(render_text);
}
if let Some(operation_id) = crt.record.must_get_rest().operation_id.clone() {
if ui.button("Generate Schema").clicked() {
Expand Down Expand Up @@ -145,6 +150,7 @@ impl RequestBodyPanel {
crt = workspace_data.must_get_mut_crt(crt_id.clone(), |crt| {
HighlightTemplateSinglelineBuilder::default()
.multiline()
.quick_render(false)
.envs(envs)
.all_space(true)
.build(
Expand Down
14 changes: 13 additions & 1 deletion crates/netpurr/src/widgets/highlight_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct HighlightTemplate<'t> {
popup_id: String,
multiline: bool,
filter: HashSet<String>,
quick_render: bool,
}

impl HighlightTemplate<'_> {
Expand Down Expand Up @@ -65,6 +66,10 @@ impl HighlightTemplate<'_> {
.chars()
.take(c.primary.ccursor.index)
.collect();
let after_cursor_text:&String = &self.content.as_str().chars().skip(c.primary.ccursor.index).collect();
if !(after_cursor_text.starts_with(" ")||after_cursor_text.starts_with("\n")){
return;
}
let prompt_option = self.find_prompt(before_cursor_text.to_string());
if prompt_option.is_some() && self.envs.clone().len() > 0 {
let prompt = prompt_option.unwrap_or_default();
Expand Down Expand Up @@ -210,7 +215,7 @@ impl Widget for HighlightTemplate<'_> {
self.content.as_str().to_string(),
self.envs.clone(),
);
if response.hovered() && text.len() > 0 && text != self.content.as_str() {
if response.hovered() && text.len() > 0 && text != self.content.as_str() &&self.quick_render {
response = response.on_hover_text(text);
}
output.cursor_range.map(|c| {
Expand Down Expand Up @@ -242,6 +247,7 @@ pub struct HighlightTemplateSinglelineBuilder {
all_space: bool,
size: f32,
multiline: bool,
quick_render: bool,
filter: HashSet<String>,
envs: BTreeMap<String, EnvironmentItemValue>,
}
Expand All @@ -253,6 +259,7 @@ impl Default for HighlightTemplateSinglelineBuilder {
all_space: true,
size: 12.0,
multiline: false,
quick_render: true,
filter: Default::default(),
envs: BTreeMap::default(),
}
Expand Down Expand Up @@ -284,6 +291,10 @@ impl HighlightTemplateSinglelineBuilder {
self.multiline = true;
self
}
pub fn quick_render(&mut self, render:bool) -> &mut HighlightTemplateSinglelineBuilder {
self.quick_render = render;
self
}

pub fn filter(&mut self, filter: HashSet<String>) -> &mut HighlightTemplateSinglelineBuilder {
self.filter = filter;
Expand All @@ -297,6 +308,7 @@ impl HighlightTemplateSinglelineBuilder {
envs: self.envs.clone(),
content,
popup_id: id,
quick_render: self.quick_render,
multiline: self.multiline,
filter: self.filter.clone(),
}
Expand Down

0 comments on commit 24357e3

Please sign in to comment.