Repository: lapce/lapce
File: lapce-ui/src/palette.rs (Rust)

Code before:

        let svg_x = match palette_item_content {
            &PaletteItemContent::Line(_, _) | &PaletteItemContent::Workspace(_) => {
                0.0
            }
            _ => line_height,
        };

        let focus_color = config.get_color_unchecked(LapceTheme::EDITOR_FOCUS);

        let full_text = if hint.is_empty() {
            text.clone()
        } else {
            text.clone() + " " + &hint
        };
        let mut text_layout = ctx
            .text()
            .new_text_layout(full_text.clone())
            .font(config.ui.font_family(), config.ui.font_size() as f64)
            .text_color(
                config
                    .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND)
                    .clone(),
            );
        for i_start in &text_indices {
            let i_start = *i_start;
            let i_end = full_text
                .char_indices()
                .find(|(i, _)| *i == i_start)
                .map(|(_, c)| c.len_utf8() + i_start);
            let i_end = if let Some(i_end) = i_end {
                i_end
            } else {
                // Log a warning, but continue as we don't want to crash on a bug
                log::warn!(
                    "Invalid text indices in palette: text: '{}', i_start: {}",
                    text,
                    i_start
                );
                continue;
            };

            text_layout = text_layout.range_attribute(
                i_start..i_end,
                TextAttribute::TextColor(focus_color.clone()),
            );
            text_layout = text_layout.range_attribute(
                i_start..i_end,
                TextAttribute::Weight(FontWeight::BOLD),
            );
        }

Review comment (suggestion):
I feel that `start` and `end` is sufficient. i_start/i_end looks kind of like Systems Hungarian Notation

```suggestion
        for i_start in text_indices.iter().copied() {
```

Code after:

        let svg_x = match palette_item_content {
            &PaletteItemContent::Line(_, _) | &PaletteItemContent::Workspace(_) => {
                0.0
            }
            _ => line_height,
        };

        let focus_color = config.get_color_unchecked(LapceTheme::EDITOR_FOCUS);

        let full_text = if hint.is_empty() {
            text.clone()
        } else {
            text.clone() + " " + &hint
        };
        let mut text_layout = ctx
            .text()
            .new_text_layout(full_text.clone())
            .font(config.ui.font_family(), config.ui.font_size() as f64)
            .text_color(
                config
                    .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND)
                    .clone(),
            );
        for &i_start in &text_indices {
            let i_end = full_text
                .char_indices()
                .find(|(i, _)| *i == i_start)
                .map(|(_, c)| c.len_utf8() + i_start);
            let i_end = if let Some(i_end) = i_end {
                i_end
            } else {
                // Log a warning, but continue as we don't want to crash on a bug
                log::warn!(
                    "Invalid text indices in palette: text: '{}', i_start: {}",
                    text,
                    i_start
                );
                continue;
            };

            text_layout = text_layout.range_attribute(
                i_start..i_end,
                TextAttribute::TextColor(focus_color.clone()),
            );
            text_layout = text_layout.range_attribute(
                i_start..i_end,
                TextAttribute::Weight(FontWeight::BOLD),
            );
        }