Repository: helix-editor/helix
File: helix-term/src/commands.rs (Rust)

Code before:
/// Goto files in selection.
fn goto_file_impl(cx: &mut Context, action: Action) {
    let (view, doc) = current_ref!(cx.editor);
    let text = doc.text();
    let selections = doc.selection(view.id);
    let rel_path = doc
        .relative_path()
        .map(|path| path.parent().unwrap().to_path_buf())
        .unwrap_or_default();
    let mut paths: Vec<_> = selections
        .iter()
        .map(|r| text.slice(r.from()..r.to()).to_string())
        .collect();
    let primary = selections.primary();
    // Checks whether there is only one selection with a width of 1
    if selections.len() == 1 && primary.len() == 1 {
        paths.clear();

        let is_valid_path_char = |c: &char| {
            #[cfg(target_os = "windows")]
            let valid_chars: &[char] = &[
                '@', '/', '\\', '.', '-', '_', '+', '#', '$', '%', '{', '}', '[', ']', ':', '!',
                '~', '=',
            ];
            #[cfg(not(target_os = "windows"))]
            let valid_chars: &[char] = &['@', '/', '.', '-', '_', '+', '#', '$', '%', '~', '='];

            valid_chars.contains(c) || c.is_alphabetic() || c.is_numeric()
        };

        let cursor_pos = primary.cursor(text.slice(..));
        let pre_cursor_pos = cursor_pos.saturating_sub(1);
        let post_cursor_pos = cursor_pos + 1;
        let start_pos = if is_valid_path_char(&text.char(cursor_pos)) {
            cursor_pos
        } else if is_valid_path_char(&text.char(pre_cursor_pos)) {
            pre_cursor_pos
        } else {
            post_cursor_pos
        };

        let prefix_len = text
            .chars_at(start_pos)
            .reversed()
            .take_while(is_valid_path_char)
            .count();

        let postfix_len = text
            .chars_at(start_pos)
            .take_while(is_valid_path_char)
            .count();

Review comment (suggestion):
We should also include `:` here so that `gf` can work on links. (since https://github.com/helix-editor/helix/pull/5820)

Code after:
    push_jump(view, doc);
    doc.set_selection(view.id, selection);
}

fn goto_file(cx: &mut Context) {
    goto_file_impl(cx, Action::Replace);
}

fn goto_file_hsplit(cx: &mut Context) {
    goto_file_impl(cx, Action::HorizontalSplit);
}

fn goto_file_vsplit(cx: &mut Context) {
    goto_file_impl(cx, Action::VerticalSplit);
}

/// Goto files in selection.
fn goto_file_impl(cx: &mut Context, action: Action) {
    let (view, doc) = current_ref!(cx.editor);
    let text = doc.text();
    let selections = doc.selection(view.id);
    let rel_path = doc
        .relative_path()
        .map(|path| path.parent().unwrap().to_path_buf())
        .unwrap_or_default();
    let mut paths: Vec<_> = selections
        .iter()
        .map(|r| text.slice(r.from()..r.to()).to_string())
        .collect();
    let primary = selections.primary();
    // Checks whether there is only one selection with a width of 1
    if selections.len() == 1 && primary.len() == 1 {
        paths.clear();

        let is_valid_path_char = |c: &char| {
            #[cfg(target_os = "windows")]
            let valid_chars = &[
                '@', '/', '\\', '.', '-', '_', '+', '#', '$', '%', '{', '}', '[', ']', ':', '!',
                '~', '=',
            ];
            #[cfg(not(target_os = "windows"))]
            let valid_chars = &['@', '/', '.', '-', '_', '+', '#', '$', '%', '~', '=', ':'];

            valid_chars.contains(c) || c.is_alphabetic() || c.is_numeric()
        };

        let cursor_pos = primary.cursor(text.slice(..));
        let pre_cursor_pos = cursor_pos.saturating_sub(1);
        let post_cursor_pos = cursor_pos + 1;
        let start_pos = if is_valid_path_char(&text.char(cursor_pos)) {
            cursor_pos