on master help sign in
use PathBuf::to_string_lossy() instead of to_str() (#1655)
23907a0Kirawi
helix-term/src/commands.rs+5−7
@@ -1792,9 +1792,8 @@ fn global_search(cx: &mut Context) {
1792 all_matches,
1792 all_matches,
1793 move |(_line_num, path)| {
1793 move |(_line_num, path)| {
1794 let relative_path = helix_core::path::get_relative_path(path)
1794 let relative_path = helix_core::path::get_relative_path(path)
1795− .to_str()
1795+ .to_string_lossy()
1796− .unwrap()
1796+ .into_owned();
1797− .to_owned();
1798 if current_path.as_ref().map(|p| p == path).unwrap_or(false) {
1797 if current_path.as_ref().map(|p| p == path).unwrap_or(false) {
1799 format!("{} (*)", relative_path).into()
1798 format!("{} (*)", relative_path).into()
1800 } else {
1799 } else {
@@ -3536,9 +3535,8 @@ fn workspace_symbol_picker(cx: &mut Context) {
3536 (&symbol.name).into()
3535 (&symbol.name).into()
3537 } else {
3536 } else {
3538 let relative_path = helix_core::path::get_relative_path(path.as_path())
3537 let relative_path = helix_core::path::get_relative_path(path.as_path())
3539− .to_str()
3538+ .to_string_lossy()
3540− .unwrap()
3539+ .into_owned();
3541− .to_owned();
3542 format!("{} ({})", &symbol.name, relative_path).into()
3540 format!("{} ({})", &symbol.name, relative_path).into()
3543 }
3541 }
3544 },
3542 },
@@ -4209,8 +4207,8 @@ fn goto_impl(
4209 .map(|path| path.to_path_buf())
4207 .map(|path| path.to_path_buf())
4210 .unwrap_or(path)
4208 .unwrap_or(path)
4211 })
4209 })
4210+ .map(|path| Cow::from(path.to_string_lossy().into_owned()))
4212 .ok()
4211 .ok()
4213− .and_then(|path| path.to_str().map(|path| path.to_owned().into()))
4214 })
4212 })
4215 .flatten()
4213 .flatten()
4216 .unwrap_or_else(|| location.uri.as_str().into());
4214 .unwrap_or_else(|| location.uri.as_str().into());
helix-term/src/ui/mod.rs+3−7
@@ -155,11 +155,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
155 files,
155 files,
156 move |path: &PathBuf| {
156 move |path: &PathBuf| {
157 // format_fn
157 // format_fn
158− path.strip_prefix(&root)
158+ path.strip_prefix(&root).unwrap_or(path).to_string_lossy()
159− .unwrap_or(path)
160− .to_str()
161− .unwrap()
162− .into()
163 },
159 },
164 move |cx, path: &PathBuf, action| {
160 move |cx, path: &PathBuf, action| {
165 cx.editor
161 cx.editor
@@ -288,7 +284,7 @@ pub mod completers {
288 } else {
284 } else {
289 let file_name = path
285 let file_name = path
290 .file_name()
286 .file_name()
291− .map(|file| file.to_str().unwrap().to_owned());
287+ .and_then(|file| file.to_str().map(|path| path.to_owned()));
292
288
293 let path = match path.parent() {
289 let path = match path.parent() {
294 Some(path) if !path.as_os_str().is_empty() => path.to_path_buf(),
290 Some(path) if !path.as_os_str().is_empty() => path.to_path_buf(),
@@ -331,7 +327,7 @@ pub mod completers {
331 path.push("");
327 path.push("");
332 }
328 }
333
329
334− let path = path.to_str().unwrap().to_owned();
330+ let path = path.to_str()?.to_owned();
335 Some((end.clone(), Cow::from(path)))
331 Some((end.clone(), Cow::from(path)))
336 })
332 })
337 }) // TODO: unwrap or skip
333 }) // TODO: unwrap or skip