Skip to content

Commit

Permalink
feat: fix test bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jincheng.zhang committed Apr 1, 2024
1 parent 176e957 commit 7e866b1
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 14 deletions.
41 changes: 35 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ eframe = { version = "0.27.0", default-features = false, features = [
"glow", # Use the glow rendering backend. Alternative: "wgpu".
] }
futures-util = "0.3.29"
rayon = "1.10.0"
rayon = "1.10.0"
prettify-js = "=0.1.0"
8 changes: 5 additions & 3 deletions crates/egui_code_editor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ impl CodeEditor {

let mut after_cursor_text: String = text.as_str().chars().skip(c.primary.ccursor.index).collect();
after_cursor_text = after_cursor_text.replace("\n"," ")
.replace(","," ")
.replace("\t"," ").replace(";"," ");
if !after_cursor_text.starts_with(" ")&&!after_cursor_text.is_empty(){
ui.memory_mut(|mem| {
Expand Down Expand Up @@ -481,15 +482,16 @@ impl CodeEditor {
sentence.chars().filter(|&c| c == dot).count()
}
fn find_prompt(&self,text:String)->(String,Vec<String>){
let replace = text
let mut replace = text
.replace("{"," ")
.replace(")"," ")
.replace("("," ")
.replace("}"," ")
.replace(";"," ")
.replace(","," ")
.replace("\t"," ")
.replace("\n"," ");
if text.ends_with("("){
replace = replace.replace("("," ");
}
let sentence = replace.split(" ").last().unwrap_or_default();
if sentence.is_empty(){
return ("".to_string(),vec![])
Expand Down
2 changes: 1 addition & 1 deletion crates/netpurr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ chrono.workspace = true
dirs.workspace = true
poll-promise.workspace = true
futures-util.workspace = true

prettify-js.workspace = true
openapiv3 = "2.0.0"
[profile.release]
opt-level = 2 # fast and small wasm
Expand Down
7 changes: 6 additions & 1 deletion crates/netpurr/src/panels/request_pre_script_panel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ops::Add;

use egui::Ui;
use prettify_js::prettyprint;

use egui_code_editor::{CodeEditor, ColorTheme, Prompt};
use netpurr_core::data::workspace_data::{TestItem, WorkspaceData};
Expand Down Expand Up @@ -114,7 +115,11 @@ console.log(response)"#)
} else {
code_editor = code_editor.with_theme(ColorTheme::GRUVBOX_LIGHT)
}
code_editor.show(ui, &mut script);
let response = code_editor.show(ui, &mut script).response;
if response.lost_focus(){
let (pretty, _) = prettyprint(script.as_str());
script = pretty;
}
});
});
if compare_script != script {
Expand Down
9 changes: 7 additions & 2 deletions crates/netpurr/src/panels/test_script_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ops::Add;
use std::rc::Rc;

use egui::Ui;
use prettify_js::prettyprint;

use egui_code_editor::{CodeEditor, ColorTheme, Prompt};
use netpurr_core::data::collections::CollectionFolder;
Expand Down Expand Up @@ -119,7 +120,11 @@ impl TestScriptPanel {
} else {
code_editor = code_editor.with_theme(ColorTheme::GRUVBOX_LIGHT)
}
code_editor.show(ui, &mut script);
let response = code_editor.show(ui, &mut script).response;
if response.lost_focus(){
let (pretty, _) = prettyprint(script.as_str());
script = pretty;
}
});

if compare_script != script {
Expand All @@ -141,4 +146,4 @@ impl TestScriptPanel {
}
}
}
}
}
1 change: 1 addition & 0 deletions crates/netpurr_core/src/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,4 @@ impl ScriptTree {
.unwrap_or_default()
}
}

0 comments on commit 7e866b1

Please sign in to comment.