Skip to content
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

TAB key in TextEdit, fill the space with different sizes #3879

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from

Conversation

rustbasic
Copy link
Contributor

#3850

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);

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Please try to make your code more readable with:

  • better names
  • documentation if names are not enough
  • strong typing when it makes sense

@@ -98,3 +98,4 @@ log = { workspace = true, optional = true }
puffin = { workspace = true, optional = true }
ron = { version = "0.8", optional = true }
serde = { version = "1", optional = true, features = ["derive", "rc"] }
unicode-width = "0.1.11"
Copy link
Owner

Choose a reason for hiding this comment

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

Can we avoid adding this dependency? It's not a huge one, but I wonder how much larger the .wasm becomes with these tables: https://github.com/unicode-rs/unicode-width/blob/master/src/tables.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we avoid adding this dependency? It's not a huge one, but I wonder how much larger the .wasm becomes with these tables: https://github.com/unicode-rs/unicode-width/blob/master/src/tables.rs

I don't think this dependency can be avoided. These are codes so they will not be very large and are essential for countries that use UTF8 characters. All pictograms are also affected by this.

CCursor::new(line_start_index)
}

pub fn create_char_line_indexes(text: &str) -> Vec<usize> {
Copy link
Owner

Choose a reason for hiding this comment

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

This is not a good name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not from an English-speaking country, so it's hard for me to choose even a single word.
I would appreciate it if emilk could make a suggestion.

current_column
}

pub fn get_current_column_total_column(
Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you shouldn't be using get_ everywhere

https://rust-lang.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter

I'm not from an English-speaking country, so it's hard for me to choose even a single word.
I would appreciate it if emilk could make a suggestion.

line_indexes
}

pub fn get_line_start_index(line_indexes: &mut [usize], index: usize) -> usize {
Copy link
Owner

Choose a reason for hiding this comment

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

There is a lot of naked usize. If you use CCursor you can make it clear wether or not something is a byte offset or a character offset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this, we can easily find out the current Colume and line within TextEdit. I'm using this, and I'm sure others might want to use it too.

Copy link
Owner

@emilk emilk Mar 30, 2024

Choose a reason for hiding this comment

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

does it return a byte index or a char index? The name doesn't tell me, neither does the return type.

What about the arguments, are they byte indexes or char indices? Try to put yourself into the shoes of someone who is just reading the function header

@rustbasic rustbasic requested a review from emilk March 25, 2024 11:44
@emilk emilk marked this pull request as draft April 29, 2024 07:58
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