Compare commits

...

111 Commits

Author SHA1 Message Date
trivernis bd32cb3114
Add --show-explorer cli arg 1 year ago
trivernis 432522e724
Add update of selected file in explorer when switching buffers 1 year ago
wongjiahau cf9669f276 fix(ci): clippy error 1 year ago
wongjiahau 88ac941407 Merge branch 'master' of https://github.com/helix-editor/helix into tree_explore 1 year ago
wongjiahau f37c795c96 chore(ui/prompt): use &str instead of Cow<str>
- Resolve https://github.com/helix-editor/helix/pull/5768/files#r1140994104
1 year ago
wongjiahau eebff622de chore(doc/configuration/explorer/position): remove `overlay` option 1 year ago
wongjiahau a331e52971 chore(keymap): remove "<space>E"
- Personally, I never uses this shortcut
- Secondly, we are running out of keys for mappings, so I would like to
  reserve "<space>E" for other more useful mappings
1 year ago
wongjiahau f5aec54fe2 chore(commands): revert accidental typo
- Resolve https://github.com/helix-editor/helix/pull/5768/files#r1143859919
1 year ago
wongjiahau 33542e9ddb refactor: remove unnecessary dev-dependencies
- Resolve https://github.com/helix-editor/helix/pull/5768/files#r1126720143
1 year ago
wongjiahau 898c1670d1 fix(integration-test/test_goto_file_impl): failing due to untested changes 1 year ago
wongjiahau 404f950b09 fix(tests/explorer/new_folder): failing on Windows
Co-authored-by: LEI <github@lei.sh>
Reference: https://github.com/helix-editor/helix/pull/5768#discussion_r1143991188
1 year ago
wongjiahau ee34720a31 style(explorer): move title to statusline
- so that the UI is more consistent with other component of the editor
- also it may improve the focus indication
1 year ago
wongjiahau 1be2ac286b fix(ui/explorer): tree search cursor not rendered 1 year ago
wongjiahau e5dfde2a9b refactor(explorer): remove overlay option 1 year ago
wongjiahau afda68a11d chore: cargo fmt 1 year ago
wongjiahau f5af209f09 refactor(explorer): remove preview
- Also moved Tree search prompt to bottom
1 year ago
wongjiahau 52be2e0c43 refactor(ui/tree): remove filter 1 year ago
wongjiahau 41ebc30ea6 fix(ui/tree/clone): `is_openend` should not be false
Resolve https://github.com/helix-editor/helix/pull/5768#discussion_r1133066209
1 year ago
wongjiahau 8b561e2e88 fix: type error 1 year ago
wongjiahau 9a1aff25bd refactor(ui/explorer/close_documents): concise code
Resolve https://github.com/helix-editor/helix/pull/5768#discussion_r1133065427
1 year ago
wongjiahau 178086767f refactor(ui/explorer/handle_prompt_event): remove unnecessary function
Resolve https://github.com/helix-editor/helix/pull/5768#discussion_r1133064955
1 year ago
wongjiahau c4c3e8075e style(explorer/delete): capitalize default choice
Resolve https://github.com/helix-editor/helix/pull/5768#discussion_r1133064678
1 year ago
wongjiahau 54b16936db Merge branch 'master' of https://github.com/helix-editor/helix into tree_explore 1 year ago
wongjiahau 20241fb256 Merge branch 'master' of https://github.com/helix-editor/helix into tree_explore 1 year ago
wongjiahau eb9287d816 fix(ci): cargo fmt and windows test 1 year ago
WJH 1108c883c4
Merge branch 'master' into tree_explore 1 year ago
wongjiahau d043ea4db4 Merge branch 'master' of https://github.com/helix-editor/helix into tree_explore 1 year ago
wongjiahau 10032eb156 fix(ci): cargo fmt 1 year ago
wongjiahau 7ccee10297 chore: correction of e991ed9 1 year ago
wongjiahau 9726ae7dbb fix(ci/test): failing on Windows 1 year ago
wongjiahau e991ed9b17 refactor(runtime/themes): revert changes to theme files
- This is because explorer specific styling has been abandoned for
  simplicity
1 year ago
wongjiahau d1e6a21016 Merge branch 'master' of https://github.com/helix-editor/helix into tree_explore 1 year ago
wongjiahau d62b487321 feat(ui/tree): undo breaking changes
- bind tree-based movements to other keys, namely J,K,H,L
1 year ago
wongjiahau 80a2f8642c Merge branch 'tree_explore' of github.com:pinelang/helix-tree-explorer into tree_explore 1 year ago
wongjiahau aa6780e149 feat(ui/tree): tree-based movements 1 year ago
wongjiahau bc62b7615d fix(ci): failing windows test & clippy 1 year ago
wongjiahau 31c0e84461 fix(ci): failing windows test & clippy 1 year ago
wongjiahau d3db1b6204 style(tree): improve ancestor contrast 1 year ago
wongjiahau 8ef95ee56a Merge branch 'master' of https://github.com/helix-editor/helix into tree_explore 1 year ago
wongjiahau a4943a7226 fix(explorer/overlay): prompt overflow
- Previously the prompt appears within the float, which has very limited
  space
- Now, the prompt will be rendered at the editor command area
1 year ago
wongjiahau c2e2f050da feat(explorer/delete): no need to press Enter, just press y
Reference: https://github.com/helix-editor/helix/pull/5768#issuecomment-1449536275
1 year ago
wongjiahau 43b226a2ab feat(explorer/keymap): combine 'a' with 'A'
Reference: https://github.com/helix-editor/helix/pull/5768#issuecomment-1449536275
1 year ago
wongjiahau a2cb28d1d1 chore(keymap): merge with the correct version 1 year ago
wongjiahau 19d436ee56 Merge branch 'master' of https://github.com/helix-editor/helix into tree_explore 1 year ago
wongjiahau b18a9746e9 fix(explorer): go to previous root does not update state.current_root 1 year ago
wongjiahau 8379669742 Merge branch 'master' of https://github.com/helix-editor/helix into tree_explore 1 year ago
wongjiahau fae4990444 test(tree): search prompt and filter prompt 1 year ago
wongjiahau 7e4feb02ef fix(explore): search using previous search word after filter does not work
- Also implemented restore_saved_view for filter and search
1 year ago
wongjiahau 4a0c620b77 fix(explorer/filter): not working for newly opened folder 1 year ago
wongjiahau c0073edebf Merge branch 'tree_explore' of github.com:pinelang/helix-tree-explorer into tree_explore 1 year ago
WJH c3b8be978e
fix(ci): clippy + failure on Windows 1 year ago
wongjiahau d578f8af61 chore: fix clippy warning 1 year ago
wongjiahau 5d600fef0f doc(helix-term/.gitignore): document purpose of test-explorer 1 year ago
wongjiahau ef1850295b chore: remove temp file 1 year ago
wongjiahau 601f2c4e5f chore(ui/tree): remove useless comments 1 year ago
wongjiahau ba00a80037 fix(tree): shouldn't use patched font 1 year ago
wongjiahau 72b845da15 Merge branch 'master' of https://github.com/helix-editor/helix into tree_explore 1 year ago
wongjiahau 24b50bb525 feat(explorer): toggle preview 1 year ago
wongjiahau 38ef079099 feat(tree): jump forward 1 year ago
wongjiahau b5d92aca45 chore: fix clippy warnings 1 year ago
wongjiahau 36769cb3f6 fix(explorer/keymap): change 'b' to 'B'
- to not clash with Tree 'zb'
1 year ago
wongjiahau dffbc15067 refactor(explorer,tree): remove unwrap to avoid panics 1 year ago
wongjiahau cf9b60a3d1 feat(tree): sticky ancestors 1 year ago
wongjiahau 9205117505 fix: failing tests 1 year ago
wongjiahau 6af9a06e74 feat(explorer): bind "="/"_" to "Zoom in"/"Zoom out" 1 year ago
wongjiahau 899491ba25 feat(tree): add C-n/C-p keybinding 1 year ago
wongjiahau f9ff01dd9c chore(ui/tree): bind 'o' to Toggle 1 year ago
wongjiahau 7b63fda7d2 test(explorer): add integration tests 1 year ago
wongjiahau 6321dc9ade chore: rename explore to explorer 1 year ago
wongjiahau 78bb29732a Merge branch 'master' of https://github.com/helix-editor/helix into add-integration-test 1 year ago
wongjiahau bcb1672378 fix(explore):
- preview panics when term height becomes too small
- preview content not sorted
1 year ago
wongjiahau a259c205c0 fix(explore): help overflow
- render with Info
1 year ago
wongjiahau 2e7709e505 MULTI
- refactor(explore):Move filter to Tree
- feat(explore): Implement mkdir -p (but not tested yet)
- feat(ui/tree): Implement jump backward
- test(ui/tree): Refresh
1 year ago
wongjiahau 2e654a0775 refactor(explore): move search function to Tree 1 year ago
wongjiahau 2a60662e8b feat(explore): add focus indicator 1 year ago
wongjiahau 64059fba47 feat(tree): move left/right 1 year ago
wongjiahau c88164f2fa feat(tree-view): add unit tests 1 year ago
wongjiahau 4dfa8696bd style(tree): increase indentation 1 year ago
wongjiahau f0a4b109ad Merge branch 'refactor-tree-explorer' of github.com:pinelang/helix-tree-explorer into refactor-tree-explorer 1 year ago
wongjiahau 70984fd148 Merge branch 'master' of https://github.com/helix-editor/helix into refactor-tree-explorer 1 year ago
wongjiahau 0f8e0a51ba fix(tree): deleting last file causes panic 1 year ago
wongjiahau ef73559a8e fix(explore): cannot focus explorer if no opened document 1 year ago
wongjiahau 30bac647ef Revert "style(explore): make Right the default position"
This reverts commit 374b8ddd4e.
1 year ago
wongjiahau c8578ba3cc fix: warnings 1 year ago
wongjiahau 374b8ddd4e style(explore): make Right the default position
Refer https://twitter.com/JustinWGrote/status/1346575528560455682
1 year ago
wongjiahau 94e2c2989b fix(command): space e does not focus explorer when no files are opened 1 year ago
wongjiahau 72495363f1 fix(explore): 'h' does not realign preview properly 1 year ago
wongjiahau 9bd534bb6f fix(explore): filter 1 year ago
wongjiahau 85fa1c56b7 feat(explore):
- filter
- close document if the file is deleted or renamed
1 year ago
wongjiahau a079477a23 fix(compile): warnings 1 year ago
wongjiahau 56056e8556 fix(explore): increase size will cause panic 1 year ago
wongjiahau b38a941955 feat(explore): close without clearing previous state 1 year ago
wongjiahau 790192dfd4 doc(explorer): up to date 1 year ago
wongjiahau 2c221f0af1 fix(explore): help page overflow 1 year ago
wongjiahau 35ffc6036d feat(explore): increase/decrease explorer size 1 year ago
wongjiahau 2bafac0c4e feat(explore): go to previous root 1 year ago
wongjiahau ddb7564809 feat(explore): add help 1 year ago
wongjiahau ec2059bf93 style(ui/tree): highlight ancestor 1 year ago
wongjiahau 52a26ff72c feat(explore): refresh 1 year ago
wongjiahau 5a5a1de4b8 fix(explore/rename): should regenarate index 1 year ago
wongjiahau 44b46dda6a feat(explore): rename file/folder 1 year ago
wongjiahau 2af8b41007 feat(explore): remove files/folder 1 year ago
wongjiahau 458fa1ca58 feat(explore): add folder/file 1 year ago
wongjiahau 0f8b641a5d feat(tree): filter 1 year ago
wongjiahau 82fe4a309d test(ui/tree): find 1 year ago
wongjiahau bdab93e856 feat(explore): search 1 year ago
wongjiahau aa397ef801 feat(explore): reveal current file 1 year ago
wongjiahau d04a1ce214 refactor(tree): change internal implementation
Previous: Vec+Tree hybrid, hard to debug and understand
Now: Pure Tree structure, easy to understand and test
1 year ago
wongjiahau c446c39645 feat(explorer/position): right
According to https://github.com/helix-editor/helix/pull/5768#issuecomment-1413162928
1 year ago
wongjiahau d9d4daa87d feat(ui/explore): implement "focus current file" 1 year ago
cossonleo b652f96449 tree helper and file explorer 2 years ago

@ -180,6 +180,8 @@ auto-pairs = false # defaults to `true`
The default pairs are <code>(){}[]''""``</code>, but these can be customized by
setting `auto-pairs` to a TOML table:
Example
```toml
[editor.auto-pairs]
'(' = ')'
@ -338,3 +340,11 @@ max-wrap = 25 # increase value to reduce forced mid-word wrapping
max-indent-retain = 0
wrap-indicator = "" # set wrap-indicator to "" to hide it
```
### `[editor.explorer]` Section
Sets explorer side width and style.
| Key | Description | Default |
| --- | ----------- | ------- |
| `column-width` | explorer side width | 30 |
| `position` | explorer widget position, `left` or `right` | `left` |

@ -291,6 +291,8 @@ This layer is a kludge of mappings, mostly pickers.
| `R` | Replace selections by clipboard contents | `replace_selections_with_clipboard` |
| `/` | Global search in workspace folder | `global_search` |
| `?` | Open command palette | `command_palette` |
| `e` | Reveal current file in explorer | `reveal_current_file` |
> 💡 Global search displays results in a fuzzy picker, use `Space + '` to bring it back up after opening a file.
@ -442,3 +444,7 @@ Keys to use within prompt, Remapping currently not supported.
| `Tab` | Select next completion item |
| `BackTab` | Select previous completion item |
| `Enter` | Open selected |
# File explorer
Press `?` to see keymaps. Remapping currently not supported.

@ -1 +1,4 @@
/target
# This folder is used by `test_explorer` to create temporary folders needed for testing
test_explorer

@ -21,11 +21,11 @@ use tui::backend::Backend;
use crate::{
args::Args,
commands::apply_workspace_edit,
compositor::{Compositor, Event},
compositor::{self, Compositor, Event},
config::Config,
job::Jobs,
keymap::Keymaps,
ui::{self, overlay::overlayed},
ui::{self, overlay::overlayed, Explorer},
};
use log::{debug, error, warn};
@ -155,7 +155,21 @@ impl Application {
let keys = Box::new(Map::new(Arc::clone(&config), |config: &Config| {
&config.keys
}));
let editor_view = Box::new(ui::EditorView::new(Keymaps::new(keys)));
let mut editor_view = Box::new(ui::EditorView::new(Keymaps::new(keys)));
let mut jobs = Jobs::new();
if args.show_explorer {
let mut context = compositor::Context {
editor: &mut editor,
scroll: None,
jobs: &mut jobs,
};
let mut explorer = Explorer::new(&mut context)?;
explorer.unfocus();
editor_view.explorer = Some(explorer);
}
compositor.push(editor_view);
if args.load_tutor {
@ -244,7 +258,7 @@ impl Application {
syn_loader,
signals,
jobs: Jobs::new(),
jobs,
lsp_progress: LspProgressMap::new(),
last_render: Instant::now(),
};

@ -10,6 +10,7 @@ pub struct Args {
pub health: bool,
pub health_arg: Option<String>,
pub load_tutor: bool,
pub show_explorer: bool,
pub fetch_grammars: bool,
pub build_grammars: bool,
pub split: Option<Layout>,
@ -32,6 +33,7 @@ impl Args {
"--version" => args.display_version = true,
"--help" => args.display_help = true,
"--tutor" => args.load_tutor = true,
"--show-explorer" => args.show_explorer = true,
"--vsplit" => match args.split {
Some(_) => anyhow::bail!("can only set a split once of a specific type"),
None => args.split = Some(Layout::Vertical),

@ -472,6 +472,8 @@ impl MappableCommand {
record_macro, "Record macro",
replay_macro, "Replay macro",
command_palette, "Open command palette",
open_or_focus_explorer, "Open or focus explorer",
reveal_current_file, "Reveal current file in explorer",
);
}
@ -2447,6 +2449,49 @@ fn file_picker_in_current_directory(cx: &mut Context) {
cx.push_layer(Box::new(overlayed(picker)));
}
fn open_or_focus_explorer(cx: &mut Context) {
cx.callback = Some(Box::new(
|compositor: &mut Compositor, cx: &mut compositor::Context| {
if let Some(editor) = compositor.find::<ui::EditorView>() {
match editor.explorer.as_mut() {
Some(explore) => explore.focus(),
None => match ui::Explorer::new(cx) {
Ok(explore) => editor.explorer = Some(explore),
Err(err) => cx.editor.set_error(format!("{}", err)),
},
}
}
},
));
}
fn reveal_file(cx: &mut Context, path: Option<PathBuf>) {
cx.callback = Some(Box::new(
|compositor: &mut Compositor, cx: &mut compositor::Context| {
if let Some(editor) = compositor.find::<ui::EditorView>() {
(|| match editor.explorer.as_mut() {
Some(explorer) => match path {
Some(path) => explorer.reveal_file(path),
None => explorer.reveal_current_file(cx),
},
None => {
editor.explorer = Some(ui::Explorer::new(cx)?);
if let Some(explorer) = editor.explorer.as_mut() {
explorer.reveal_current_file(cx)?;
}
Ok(())
}
})()
.unwrap_or_else(|err| cx.editor.set_error(err.to_string()))
}
},
));
}
fn reveal_current_file(cx: &mut Context) {
reveal_file(cx, None)
}
fn buffer_picker(cx: &mut Context) {
let current = view!(cx.editor).doc;

@ -34,6 +34,47 @@ impl<'a> Context<'a> {
tokio::task::block_in_place(|| helix_lsp::block_on(self.editor.flush_writes()))?;
Ok(())
}
/// Purpose: to test `handle_event` without escalating the test case to integration test
/// Usage:
/// ```
/// let mut editor = Context::dummy_editor();
/// let mut jobs = Context::dummy_jobs();
/// let mut cx = Context::dummy(&mut jobs, &mut editor);
/// ```
#[cfg(test)]
pub fn dummy(jobs: &'a mut Jobs, editor: &'a mut helix_view::Editor) -> Context<'a> {
Context {
jobs,
scroll: None,
editor,
}
}
#[cfg(test)]
pub fn dummy_jobs() -> Jobs {
Jobs::new()
}
#[cfg(test)]
pub fn dummy_editor() -> Editor {
use crate::config::Config;
use arc_swap::{access::Map, ArcSwap};
use helix_core::syntax::{self, Configuration};
use helix_view::theme;
use std::sync::Arc;
let config = Arc::new(ArcSwap::from_pointee(Config::default()));
Editor::new(
Rect::new(0, 0, 60, 120),
Arc::new(theme::Loader::new(&[])),
Arc::new(syntax::Loader::new(Configuration { language: vec![] })),
Arc::new(Arc::new(Map::new(
Arc::clone(&config),
|config: &Config| &config.editor,
))),
)
}
}
pub trait Component: Any + AnyComponent {
@ -72,6 +113,21 @@ pub trait Component: Any + AnyComponent {
fn id(&self) -> Option<&'static str> {
None
}
#[cfg(test)]
/// Utility method for testing `handle_event` without using integration test.
/// Especially useful for testing helper components such as `Prompt`, `TreeView` etc
fn handle_events(&mut self, events: &str) -> anyhow::Result<()> {
use helix_view::input::parse_macro;
let mut editor = Context::dummy_editor();
let mut jobs = Context::dummy_jobs();
let mut cx = Context::dummy(&mut jobs, &mut editor);
for event in parse_macro(events)? {
self.handle_event(&Event::Key(event), &mut cx);
}
Ok(())
}
}
pub struct Compositor {

@ -274,6 +274,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"r" => rename_symbol,
"h" => select_references_to_symbol_under_cursor,
"?" => command_palette,
"e" => reveal_current_file,
},
"z" => { "View"
"z" | "c" => align_view_center,

@ -6,7 +6,7 @@ use crate::{
keymap::{KeymapResult, Keymaps},
ui::{
document::{render_document, LinePos, TextRenderer, TranslatedPosition},
Completion, ProgressSpinners,
Completion, Explorer, ProgressSpinners,
},
};
@ -23,7 +23,7 @@ use helix_core::{
};
use helix_view::{
document::{Mode, SavePoint, SCRATCH_BUFFER_NAME},
editor::{CompleteAction, CursorShapeConfig},
editor::{CompleteAction, CursorShapeConfig, ExplorerPosition},
graphics::{Color, CursorKind, Modifier, Rect, Style},
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind},
keyboard::{KeyCode, KeyModifiers},
@ -43,6 +43,7 @@ pub struct EditorView {
pub(crate) last_insert: (commands::MappableCommand, Vec<InsertEvent>),
pub(crate) completion: Option<Completion>,
spinners: ProgressSpinners,
pub(crate) explorer: Option<Explorer>,
}
#[derive(Debug, Clone)]
@ -68,6 +69,7 @@ impl EditorView {
last_insert: (commands::MappableCommand::normal_mode, Vec::new()),
completion: None,
spinners: ProgressSpinners::default(),
explorer: None,
}
}
@ -1214,6 +1216,11 @@ impl Component for EditorView {
event: &Event,
context: &mut crate::compositor::Context,
) -> EventResult {
if let Some(explore) = self.explorer.as_mut() {
if let EventResult::Consumed(callback) = explore.handle_event(event, context) {
return EventResult::Consumed(callback);
}
}
let mut cx = commands::Context {
editor: context.editor,
count: None,
@ -1362,6 +1369,8 @@ impl Component for EditorView {
surface.set_style(area, cx.editor.theme.get("ui.background"));
let config = cx.editor.config();
let editor_area = area.clip_bottom(1);
// check if bufferline should be rendered
use helix_view::editor::BufferLine;
let use_bufferline = match config.bufferline {
@ -1370,15 +1379,43 @@ impl Component for EditorView {
_ => false,
};
// -1 for commandline and -1 for bufferline
let mut editor_area = area.clip_bottom(1);
if use_bufferline {
editor_area = editor_area.clip_top(1);
}
let editor_area = if use_bufferline {
editor_area.clip_top(1)
} else {
editor_area
};
let editor_area = if let Some(explorer) = &self.explorer {
let explorer_column_width = if explorer.is_opened() {
explorer.column_width().saturating_add(2)
} else {
0
};
// For future developer:
// We should have a Dock trait that allows a component to dock to the top/left/bottom/right
// of another component.
match config.explorer.position {
ExplorerPosition::Left => editor_area.clip_left(explorer_column_width),
ExplorerPosition::Right => editor_area.clip_right(explorer_column_width),
}
} else {
editor_area
};
// if the terminal size suddenly changed, we need to trigger a resize
cx.editor.resize(editor_area);
if let Some(explorer) = self.explorer.as_mut() {
if !explorer.is_focus() {
let area = if use_bufferline {
area.clip_top(1)
} else {
area
};
explorer.render(area, surface, cx);
}
}
if use_bufferline {
Self::render_bufferline(cx.editor, area.with_height(1), surface);
}
@ -1457,9 +1494,47 @@ impl Component for EditorView {
if let Some(completion) = self.completion.as_mut() {
completion.render(area, surface, cx);
}
if let Some(explore) = self.explorer.as_mut() {
let needs_update = explore.is_focus() || {
if let Some(current_document_path) = doc!(cx.editor).path().cloned() {
if let Some(current_explore_path) = explore.current_file() {
if *current_explore_path != current_document_path {
let _ = explore.reveal_file(current_document_path);
true
} else {
false
}
} else {
let _ = explore.reveal_file(current_document_path);
true
}
} else {
false
}
};
if needs_update {
let area = if use_bufferline {
area.clip_top(1)
} else {
area
};
explore.render(area, surface, cx);
}
}
}
fn cursor(&self, _area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {
if let Some(explore) = &self.explorer {
if explore.is_focus() {
let cursor = explore.cursor(_area, editor);
if cursor.0.is_some() {
return cursor;
}
}
}
match editor.cursor() {
// All block cursors are drawn manually
(pos, CursorKind::Block) => (pos, CursorKind::Hidden),

File diff suppressed because it is too large Load Diff

@ -1,6 +1,7 @@
mod completion;
mod document;
pub(crate) mod editor;
mod explorer;
mod fuzzy_match;
mod info;
pub mod lsp;
@ -13,12 +14,14 @@ mod prompt;
mod spinner;
mod statusline;
mod text;
mod tree;
use crate::compositor::{Component, Compositor};
use crate::filter_picker_entry;
use crate::job::{self, Callback};
pub use completion::Completion;
pub use editor::EditorView;
pub use explorer::Explorer;
pub use markdown::Markdown;
pub use menu::Menu;
pub use picker::{DynamicPicker, FileLocation, FilePicker, Picker};
@ -26,6 +29,7 @@ pub use popup::Popup;
pub use prompt::{Prompt, PromptEvent};
pub use spinner::{ProgressSpinners, Spinner};
pub use text::Text;
pub use tree::{TreeOp, TreeView, TreeViewItem};
use helix_core::regex::Regex;
use helix_core::regex::RegexBuilder;

@ -19,26 +19,7 @@ pub struct Overlay<T> {
pub fn overlayed<T>(content: T) -> Overlay<T> {
Overlay {
content,
calc_child_size: Box::new(|rect: Rect| clip_rect_relative(rect.clip_bottom(2), 90, 90)),
}
}
fn clip_rect_relative(rect: Rect, percent_horizontal: u8, percent_vertical: u8) -> Rect {
fn mul_and_cast(size: u16, factor: u8) -> u16 {
((size as u32) * (factor as u32) / 100).try_into().unwrap()
}
let inner_w = mul_and_cast(rect.width, percent_horizontal);
let inner_h = mul_and_cast(rect.height, percent_vertical);
let offset_x = rect.width.saturating_sub(inner_w) / 2;
let offset_y = rect.height.saturating_sub(inner_h) / 2;
Rect {
x: rect.x + offset_x,
y: rect.y + offset_y,
width: inner_w,
height: inner_h,
calc_child_size: Box::new(|rect: Rect| rect.overlayed()),
}
}

@ -94,6 +94,10 @@ impl Prompt {
self
}
pub fn prompt(&self) -> &str {
self.prompt.as_ref()
}
pub fn line(&self) -> &String {
&self.line
}

File diff suppressed because it is too large Load Diff

@ -210,6 +210,30 @@ impl Default for FilePickerConfig {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct ExplorerConfig {
pub position: ExplorerPosition,
/// explorer column width
pub column_width: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum ExplorerPosition {
Left,
Right,
}
impl Default for ExplorerConfig {
fn default() -> Self {
Self {
position: ExplorerPosition::Left,
column_width: 36,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct Config {
@ -280,6 +304,8 @@ pub struct Config {
pub indent_guides: IndentGuidesConfig,
/// Whether to color modes with different colors. Defaults to `false`.
pub color_modes: bool,
/// explore config
pub explorer: ExplorerConfig,
pub soft_wrap: SoftWrap,
}
@ -748,6 +774,7 @@ impl Default for Config {
bufferline: BufferLine::default(),
indent_guides: IndentGuidesConfig::default(),
color_modes: false,
explorer: ExplorerConfig::default(),
soft_wrap: SoftWrap::default(),
text_width: 80,
completion_replace: false,
@ -921,6 +948,18 @@ pub enum CloseError {
SaveError(anyhow::Error),
}
impl From<CloseError> for anyhow::Error {
fn from(error: CloseError) -> Self {
match error {
CloseError::DoesNotExist => anyhow::anyhow!("Document doesn't exist"),
CloseError::BufferModified(error) => {
anyhow::anyhow!(format!("Buffer modified: '{error}'"))
}
CloseError::SaveError(error) => anyhow::anyhow!(format!("Save error: {error}")),
}
}
}
impl Editor {
pub fn new(
mut area: Rect,

@ -248,6 +248,34 @@ impl Rect {
&& self.y < other.y + other.height
&& self.y + self.height > other.y
}
/// Returns a smaller `Rect` with a margin of 5% on each side, and an additional 2 rows at the bottom
pub fn overlayed(self) -> Rect {
self.clip_bottom(2).clip_relative(90, 90)
}
/// Returns a smaller `Rect` with width and height clipped to the given `percent_horizontal`
/// and `percent_vertical`.
///
/// Value of `percent_horizontal` and `percent_vertical` is from 0 to 100.
pub fn clip_relative(self, percent_horizontal: u8, percent_vertical: u8) -> Rect {
fn mul_and_cast(size: u16, factor: u8) -> u16 {
((size as u32) * (factor as u32) / 100).try_into().unwrap()
}
let inner_w = mul_and_cast(self.width, percent_horizontal);
let inner_h = mul_and_cast(self.height, percent_vertical);
let offset_x = self.width.saturating_sub(inner_w) / 2;
let offset_y = self.height.saturating_sub(inner_h) / 2;
Rect {
x: self.x + offset_x,
y: self.y + offset_y,
width: inner_w,
height: inner_h,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

Loading…
Cancel
Save