-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pull Request : #3321 #3846 #3850 #3857
Conversation
@emilk I'm having trouble with I've extensively tested it in the program I created, Thank you, emilk. |
please create one PR per issue to make it easier to review |
None => CCursor::new(0), | ||
let mut count = 0; | ||
for (_i, c) in text.chars().enumerate() { | ||
count += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use the i
from the enumerate? Or just remove the enumerate()
since it is not doing anything. Or do this:
let line_indexes: Vec<_> = text
.lines()
.map(|line| line.chars().count())
.scan(0, |total, next| {
let index = *total;
*total += next;
Some(index)
})
.collect();
Is the vec supposed to always contain the last char index as well? Even if it is not a new line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'\r' and '\n'
should also be counted.
Saving the last index also reduces panic or bug
occurrence when using arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it introduce bugs, though? You are saving the last index of the last line as if it were the first index of a new line.
|
||
pub fn get_line_and_start_index(line_indexes: &mut [usize], index: usize) -> (usize, usize) { | ||
let mut current_line = 1; | ||
for (i, line_start) in line_indexes.iter().enumerate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use partition_point
.
let mut i: usize = line_start_index; | ||
let mut current_column: usize = 1; | ||
let mut total_columns: usize = 0; | ||
while let Some(c) = text.chars().nth(i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has quadratic complexity, doesn't it? Each call to nth()
is a for loop from the start of the string. You could do
for c in text.chars().skip(line_start_index) {
Since you are already breaking on the newline. Otherwise you can get the index of the next line start and use take()
to get the chars up to that index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to find a column according to the width of UTF8 characters.
@emilk
Dear emilk.
I work finished, Pull Request.
Changed :
crates/eframe/src/native/run.rs
The test results are normal.
panic
when pressing Shift + TAB in aTextEdit
#3846rev() is panic with UTF8
Not byte_index
It's char_index ( for UTF8 )
I want to use the following for accurate usage:
egui\src\text_selection\text_cursor_state.rs 360 lines
let width = unicode_width::UnicodeWidthChar::width_cjk(c).unwrap_or(2);
Thank you, emilk.