1
0
Fork 0
mirror of https://github.com/helix-editor/helix synced 2024-06-01 19:56:04 +02:00

Port over Doc::relative_path.

This commit is contained in:
Blaž Hrastnik 2020-12-18 17:18:11 +09:00
parent 8b263ef04b
commit 0b63e838e0
2 changed files with 9 additions and 2 deletions

View File

@ -226,7 +226,7 @@ pub fn render_statusline(
);
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);
}

View File

@ -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 @@ pub fn selection(&self) -> &Selection {
&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<R>(&self, range: R) -> RopeSlice where R: RangeBounds {
// self.state.doc.slice
// }