Repository: nushell/nushell
File: crates/nu-explore/src/explore_regex/ui.rs (Rust)

Code before:
        }
    }

    // Default: pass to editor
    KeyAction::PassToEditor(*key)
}

// ─── Helper Functions ─────────────────────────────────────────────────────

/// Check if the cursor is at the boundary of the last word in the text.
/// Used to fix Ctrl+Right navigation to move past the last character instead of stopping before it.
fn is_at_last_word_boundary(text: &str, cursor_pos: usize) -> bool {
    if cursor_pos >= text.len() {
        return false; // Already at end
    }

    // Find the next word boundary after cursor
    let remaining = &text[cursor_pos..];
    let next_word_start = remaining
        .char_indices()
        .find(|(_, c)| c.is_alphanumeric())
        .map(|(i, _)| i)
        .unwrap_or(remaining.len());

    // If there's no more alphanumeric characters after cursor, we're at the last word
    next_word_start == remaining.len()
}

// ─── Main Loop ───────────────────────────────────────────────────────────────
///
/// Returns `true` if the application should quit, `false` otherwise.
fn execute_action(
    app: &mut App,
    action: KeyAction,
    event_handler: &mut EditorEventHandler,
) -> bool {
    match action {
        KeyAction::Quit => return true,
        KeyAction::ToggleQuickRef => app.toggle_quick_ref(),
        KeyAction::ShowHelp => app.toggle_help(),
        KeyAction::CloseHelp => app.show_help = false,
        KeyAction::SwitchFocus => {
            app.input_focus = match app.input_focus {
                InputFocus::Regex => InputFocus::Sample,
                InputFocus::Sample | InputFocus::QuickRef => InputFocus::Regex,
            };
        }
        KeyAction::FocusRegex => {
            if app.show_quick_ref && app.input_focus == InputFocus::QuickRef {
                app.close_quick_ref();
            } else {

Review comment (suggestion):
This did not work. You have to negate the predicate on line 194: `!c.is_alphanumeric()`.
But even with that, it does not match what EdTUI does. E.g., when the line ends with punctuation, the cursor still lands before the last character:

<img width="296" height="128" alt="Image" src="https://github.com/user-attachments/assets/e0e716fb-7e0b-4318-8f52-e3acc82a98e0" />


This is my best effort to make it work:
The concept is taken from EdTUI: https://github.com/preiter93/edtui/blob/87e31f9eb3bc2d057d40853f57bd3a0ccf8acf51/src/actions/motion.rs#L126-L132.


```suggestion
    let remaining = &text[cursor_pos..];

    let cursor_char = remaining.chars().next();
    let start_alphanumeric = cursor_char.is_some_and(|c| c.is_alphanumeric());
    let start_punctuation = cursor_char.is_some_and(|c| c.is_ascii_punctuation());

    // Find the next char that is not of the same type (alphanumeric or punctuation)
    for (index, next_char) in remaining.char_indices() {
        if start_alphanumeric && !next_char.is_alphanumeric() || start_punctuation && !next_char.is_ascii_punctuation() {
            // If there is still some non-whitespace remaining, we didn't reach the end of the line
            return remaining[index..].chars().all(|c| c.is_whitespace());
        }
    }

    // All remaining characters are of the same type
    true
```



Code after:
        }
    }

    // Default: pass to editor
    KeyAction::PassToEditor(*key)
}

// ─── Helper Functions ─────────────────────────────────────────────────────

/// Check if the cursor is at the boundary of the last word in the text.
/// Used to fix Ctrl+Right navigation to move past the last character instead of stopping before it.
fn is_at_or_past_last_word_boundary(text: &str, cursor_pos: usize) -> bool {
    let mut chars = text.chars();
    // advance the iterator so that the next char would be at position `cursor_pos`
    if cursor_pos > 0 {
        chars.nth(cursor_pos - 1);
    }
    let remaining = chars.as_str();
    let cursor_char = remaining.chars().next();
    let start_alphanumeric = cursor_char.is_some_and(|c| c.is_ascii_alphanumeric());
    let start_punctuation = cursor_char.is_some_and(|c| c.is_ascii_punctuation());
    // Find the next char that is not of the same type
    for (index, next_char) in remaining.char_indices().skip(1) {
        let next_alphanumeric = next_char.is_ascii_alphanumeric();
        let next_punctuation = next_char.is_ascii_punctuation();
        if next_alphanumeric && !start_alphanumeric
            || next_punctuation && !start_punctuation
            || !next_alphanumeric && !next_punctuation
        {
            // If there is still some non-whitespace remaining, we didn't reach the end of the line
            return remaining.chars().skip(index).all(|c| c.is_whitespace());
        }
    }
    // All remaining characters are of the same type
    true
}

// ─── Main Loop ───────────────────────────────────────────────────────────────
///
/// Returns `true` if the application should quit, `false` otherwise.
fn execute_action(
    app: &mut App,
    action: KeyAction,
    event_handler: &mut EditorEventHandler,
) -> bool {
    match action {
        KeyAction::Quit => return true,
        KeyAction::ToggleQuickRef => app.toggle_quick_ref(),
        KeyAction::ShowHelp => app.toggle_help(),
        KeyAction::CloseHelp => app.show_help = false,
        KeyAction::SwitchFocus => {