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

Code before:
            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)
            .clone()
            .reversed()
            .take_while(is_valid_path_char)
            .count();

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

        let path = Cow::Borrowed(
            text.slice((start_pos - prefix_len)..(start_pos + postfix_len))
                .as_str()
                .unwrap(),
        );
        log::debug!("Goto file path: {}", path);

        match shellexpand::full(&path) {
            Ok(path) => paths.push(path.to_string()),
            Err(e) => cx.editor.set_error(format!("{}", e)),
        };
    }

    for sel in paths {
        let p = sel.trim();
        if p.is_empty() {
            continue;
        }

        if let Ok(url) = Url::parse(p) {
            return open_url(cx, url, action);
        }

        let path = &rel_path.join(p);
        if path.is_dir() {
            let picker = ui::file_picker(path.into(), &cx.editor.config());
            cx.push_layer(Box::new(overlaid(picker)));
        } else if let Err(e) = cx.editor.open(path, action) {
            cx.editor.set_error(format!("Open file failed: {:?}", e));
        }

Review comment (suggestion):
```suggestion
        let path: Cow<str> = text
            .slice((start_pos - prefix_len)..(start_pos + postfix_len))
            .into();
```

Code after:
        .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
        } 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();

        let path: Cow<str> = text
            .slice((start_pos - prefix_len)..(start_pos + postfix_len))
            .into();
        log::debug!("Goto file path: {}", path);

        match expand_tilde(PathBuf::from(path.as_ref())).to_str() {
            Some(path) => paths.push(path.to_string()),
            None => cx.editor.set_error("Couldn't get string out of path."),
        };
    }