From 0b63e838e0ffe9a36a2cb51790f464d634b843af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Fri, 18 Dec 2020 17:18:11 +0900 Subject: [PATCH] Port over Doc::relative_path. --- helix-term/src/ui/editor.rs | 2 +- helix-view/src/document.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index ceb5a442..996e182f 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -226,7 +226,7 @@ impl EditorView { ); surface.set_string(1, viewport.y, mode, text_color); - if let Some(path) = view.doc.path() { + if let Some(path) = view.doc.relative_path() { surface.set_string(6, viewport.y, path.to_string_lossy(), text_color); } diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 7c4596ad..323c7bff 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -1,6 +1,6 @@ use anyhow::Error; use std::future::Future; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use helix_core::{ syntax::LOADER, ChangeSet, Diagnostic, History, Position, Range, Rope, RopeSlice, Selection, @@ -201,6 +201,13 @@ impl Document { &self.state.selection } + pub fn relative_path(&self) -> Option<&Path> { + self.path.as_ref().map(|path| { + path.strip_prefix(std::env::current_dir().unwrap()) + .unwrap_or(path) + }) + } + // pub fn slice(&self, range: R) -> RopeSlice where R: RangeBounds { // self.state.doc.slice // }