Skip to content

Utf8 prompts#281

Open
razvanrus2003 wants to merge 6 commits into
ilai-deutel:masterfrom
razvanrus2003:utf8_prompts
Open

Utf8 prompts#281
razvanrus2003 wants to merge 6 commits into
ilai-deutel:masterfrom
razvanrus2003:utf8_prompts

Conversation

@razvanrus2003

Copy link
Copy Markdown
Contributor

#5 Issue solved!

@codecov

codecov Bot commented Jan 21, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (991dc7b) 48.70% compared to head (945b3e6) 48.33%.
Report is 1 commits behind head on master.

Files Patch % Lines
src/editor.rs 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #281      +/-   ##
==========================================
- Coverage   48.70%   48.33%   -0.38%     
==========================================
  Files          11       11              
  Lines        1043     1051       +8     
==========================================
  Hits          508      508              
- Misses        535      543       +8     
Flag Coverage Δ
wasm32-wasi 49.75% <0.00%> (-0.40%) ⬇️
x86_64-apple-darwin 49.85% <0.00%> (-0.40%) ⬇️
x86_64-pc-windows-gnu 0.20% <0.00%> (-0.01%) ⬇️
x86_64-unknown-linux-gnu 49.75% <0.00%> (-0.40%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ilai-deutel ilai-deutel left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Razvan, thank you for your contribution and so sorry for the delay, it looks like I never pressed "Submit review" 🫤

Comment thread src/editor.rs
macro_rules! set_status { ($editor:expr, $($arg:expr),*) => ($editor.status_msg = Some(StatusMessage::new(format!($($arg),*)))) }

// `width!` returns the display width of a string, plus one for the cursor
fn dsp_width(msg: &String) -> usize { UnicodeWidthStr::width(msg.as_str()) + 1 }

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this function is only used once, is it could it be inlined, or does that mess up the line count?

Comment thread src/editor.rs
Cancelled,
}

thread_local! (static CHARACTER: RefCell<Vec<u8>> = {let cache = Vec::new(); RefCell::new(cache)});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather avoid thread local static in this code, could this be added as a field to PromptMode::Find etc. instead (similar to the string buffer)?

Comment thread src/editor.rs
Comment on lines +855 to +857
let character = CHARACTER.with(|cache| String::from_utf8(cache.borrow_mut().clone()));
let _ = character.clone().map_or((), |c| buffer.push_str(c.as_str()));
let _ = character.map_or((), |_| CHARACTER.with(|cache| cache.borrow_mut().clear()));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be clearer as a single if instead of 3 assignments, something like

if let Ok(s) = std::str::from_utf8(&cache) {
  buffer.push_str(s);
  cache.clear();
}

What do you think?

Note that using std::str::from_utf8 instead of String::from_utf8 avoids allocating an extra string, and there is no need for mutable borrow + cloning, a simple borrow is enough

Signed-off-by: Ilaï Deutel <ilai-deutel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants