helix-mods/helix-term/src/ui/text.rs
Gokul Soumya d84f8b5fde
Show file preview in split pane in fuzzy finder (#534)
* Add preview pane for fuzzy finder

* Fix picker preview lag by caching

* Add picker preview for document symbols

* Cache picker preview per document instead of view

* Use line instead of range for preview doc

* Add picker preview for buffer picker

* Fix render bug and refactor picker

* Refactor picker preview rendering

* Split picker and preview and compose

The current selected item is cloned on every event, which is
undesirable

* Refactor out clones in previewed picker

* Retrieve doc from editor if possible in filepicker

* Disable syntax highlight for picker preview

Files already loaded in memory have syntax highlighting enabled

* Ignore directory symlinks in file picker

* Cleanup unnecessary pubs and derives

* Remove unnecessary highlight from file picker

* Reorganize buffer rendering

* Use normal picker for code actions

* Remove unnecessary generics and trait impls

* Remove prepare_for_render and make render mutable

* Skip picker preview if screen small, less padding
2021-08-12 16:00:42 +09:00

32 lines
955 B
Rust

use crate::compositor::{Component, Context};
use tui::buffer::Buffer as Surface;
use helix_view::graphics::Rect;
pub struct Text {
contents: String,
}
impl Text {
pub fn new(contents: String) -> Self {
Self { contents }
}
}
impl Component for Text {
fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
use tui::widgets::{Paragraph, Widget, Wrap};
let contents = tui::text::Text::from(self.contents.clone());
let par = Paragraph::new(contents).wrap(Wrap { trim: false });
// .scroll(x, y) offsets
par.render(area, surface);
}
fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
let contents = tui::text::Text::from(self.contents.clone());
let width = std::cmp::min(contents.width() as u16, viewport.0);
let height = std::cmp::min(contents.height() as u16, viewport.1);
Some((width, height))
}
}