Commit graph

2121 commits

Author SHA1 Message Date
Pascal Kuthe
eb9c37844c
fix syntax highlights in dynamic picker (#8206) 2023-09-09 13:41:49 +09:00
Weiyuan Wu
8017bb2999
add redraw command (#6949)
Co-authored-by: Roberto Vidal <vidal.roberto.j@gmail.com>
2023-09-08 10:46:36 +09:00
Michael Davis
c0fd8bc61b
Fix Clone definition for Injector (#8194) 2023-09-07 11:10:00 +09:00
Pascal Kuthe
e6cdc5f9d3
Don't use word splitting during fuzzy matching (#8192) 2023-09-06 23:03:48 +09:00
Pascal Kuthe
0cfd46c14f
Do not show (running) when opening picker (#8148)
* only stream from background thread if necessary

If the file transversal is longer shorter 30ms it will now be performed
on the main thread. Spawning a thread can take a while (or rather it
takes a while until that thread is scheduled) so the files can actually
take a while to show up. This prevents the `(running)` indicator from
briefly showing up when opening the file picker in a small directory.

* run partial cargo update
2023-09-06 14:01:56 +09:00
Lorenzo Bellina
e8fc77fe98
Maintain the current cursor's position and view in the vsplit/hsplit commands too (#8109)
Co-authored-by: Benjamin Bouvier <public@benj.me>
2023-09-04 12:39:48 +09:00
woojiq
bb3e6998e6
Fix find commands for buffers with non-LF line-endings (#8111) 2023-09-03 23:12:38 +02:00
Pascal Kuthe
a38ec6d6ca
avoid excessive memory consumption in picker (#8127)
* avoid excessive memory consumption from file picker

* fix typos

Co-authored-by: Chris <75008413+cd-a@users.noreply.github.com>

---------

Co-authored-by: Chris <75008413+cd-a@users.noreply.github.com>
2023-09-01 09:13:36 +09:00
Michael Davis
48373d4a2b
Clear completion when switching windows via click (#8118)
The completion component assumes that it operates on the same View but
it's possible to break this assumption by switching windows through
left-clicking. I believe we should clear the completion menu when
switching windows to fix this.

This change fixes a panic for this scenario:

* Open a buffer with LSP completion available
* Split the window (for example '<C-w>v')
* Enter insert mode and trigger the completion menu
* Select a completion candidate (for example with '<C-n>')
* Switch to the original window by left-clicking in its area
* Enter insert mode and make edits (for example 'o<backspace>')

This will trip the 'assert_eq' in Document::restore.
2023-08-31 15:12:32 +09:00
Pascal Kuthe
0cb595e226
transition to nucleo for fuzzy matching (#7814)
* transition to nucleo for fuzzy matching

* drop flakey test case

since the picker streams in results now any test that relies
on the picker containing results is potentially flakely

* use crates.io version of nucleo

* Fix typo in commands.rs

Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com>

---------

Co-authored-by: Skyler Hawthorne <skyler@dead10ck.com>
2023-08-30 13:26:21 +09:00
woojiq
b67d2c3a68
fix: line numbers remain relative when helix loses focus (#7955)
* fix: line numbers remain relative when helix loses focus

If `line number = relative` and a new window is opened in helix, lines inside unfocused windows will be `absolute`. This commit adds the same thing when helix becomes unfocused in a terminal emulator.

* partial rebase
2023-08-29 16:00:55 +09:00
Michael Davis
546c8ca344 Handle switch from crossterm::Result to io::Result 2023-08-23 05:17:17 +09:00
Pascal Kuthe
e5f8d8ef04
create separate timer for redraw requests (#8023)
* create separate timer for redraw requests

* Update helix-view/src/editor.rs

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-08-22 06:24:30 +09:00
Mike
0cc94cd87a
goto_file_impl: use relative path to open file (#7965)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-08-21 11:15:45 -05:00
nkitsaini
22f4f313f1
Remove unnecessary Err from get_canonicalized_path (#8009)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-08-20 21:11:32 +02:00
nkitsaini
2767459f89
Remove path completions for :new command (#8010) 2023-08-20 12:51:08 -05:00
Andrés Cabero
090a225f28
goto_file: open picker if a directory is selected (#7909)
* feat: open file picker on directories using goto_file (gf)

* remove helper and call to canonicalize
2023-08-15 09:37:44 +02:00
Jonathan LEI
3a162e2bef
Make editor remember the latest search register (#5244) 2023-08-14 18:59:49 -05:00
quantonganh
085706e0cd
Include completions for git-ignored files in debugger prompt (#7936) 2023-08-14 08:46:06 -05:00
Daniel Ebert
155cedc5c8 Fix broken indentation that causes the indentation tests to fail.
For some reason, `cargo fmt` does not change the indentation in
these places (maybe it isn't sure about what the correct formatting
should be).
2023-08-11 23:44:02 +09:00
Skyler Hawthorne
7078e84007 Fix YAML auto indent
YAML indents queries are tweaked to fix auto indent behavior.

A new capture type `indent.always` is introduced to address use cases
where combining indent captures on a single line is desired.

Fixes #6661
2023-08-11 06:22:22 +09:00
Alex Vinyals
48eb0d4792
Enhance :toggle to support cycling numbers (#7877) 2023-08-08 20:56:55 -05:00
woojiq
aa4d84a0b3
Align view for background buffer opened with alt-ret (#7691)
* fix(picker): `alt-ret' changes cursor pos of current file, not new one

Closes #7673

* fix other pickers

* symbol pickers
* diagnostick pickers

This is done using the already patched `jump_to_location` method.

* fix global and jumplist pickers

* use `view` as old_id; make `align_view` method of `Action`

* test(picker): basic <alt-ret> functionality

* fix: picker integrational test

* fix nit

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-08-08 15:17:29 +02:00
Connortsui20
fcbac485f8
Show whether file readonly in statusline (#7740) 2023-08-08 14:51:34 +02:00
Jesse Luehrs
a7a145ad3d
Center the picker preview selection using visual lines (#7837)
this way the preview always shows the selection even if lines were
wrapped
2023-08-07 20:06:51 -05:00
Anshul Dalal
c7e9e94f00
Skip rendering gutters when gutter width exceeds view width (#7821) 2023-08-07 19:13:10 -05:00
Austin L Wolfgram
5535ba8b7d
fix range formatting error message typo (#7823) 2023-08-04 04:33:30 -04:00
Skyler Hawthorne
15e07d4db8 feat: smart_tab
Implement `smart_tab`, which optionally makes the tab key run the
`move_parent_node_start` command when the cursor has non- whitespace to
its left.
2023-08-01 09:41:42 -05:00
Skyler Hawthorne
93acb53812 add node boundary movement 2023-08-01 09:41:42 -05:00
Michael Davis
d4f9716fbc Add yank_to_clipboard commands, bind to <space>y by default
The clipboard special registers are able to retain multiple selections
and also join the value when copying it to the clipboard. So by default
we should yank regularly to the '*' and '+' registers. That will have
the same behavior for the clipboards but will allow pasting multiple
selections if the clipboard doesn't change between yanks.
2023-07-31 15:05:38 +09:00
Michael Davis
4555a6b433 Reimplement clipboard commands in terms of special regs
Since the clipboard provider now lives on the Registers type, we want
to eliminate it from the Editor. We can do that and clean up the
commands that interact with the clipboard by calling regular yank,
paste and replace impls on the clipboard special registers.

Eventually the clipboard commands could be removed once macro keybinding
is supported.
2023-07-31 15:05:38 +09:00
Michael Davis
2d838d729c Preview the latest value for regular registers
This fixes a discrepancy between regular registers which are used for
yanking multiple values (for example via `"ay`) and regular registers
that store a history of values (for example `"a*`).

Previously, the preview shown in `select_register`'s infobox would show
the oldest value in history. It's intuitive and useful to see the most
recent value pushed to the history though.

We cannot simply switch the preview line from `values.first()`
to `values.last()`: that would fix the preview for registers
used for history but break the preview for registers used to yank
multiple values. We could push to the beginning of the values with
`Registers::push` but this is wasteful from a performance perspective.
Instead we can have `Registers::read` return an iterator that
returns elements in the reverse order and reverse the values in
`Register::write`. This effectively means that `push` adds elements to
the beginning of the register's values. For the sake of the preview, we
can switch to `values.last()` and that is then correct for both usage-
styles. This also needs a change to call-sites that read the latest
history value to switch from `last` to `first`.
2023-07-31 15:05:38 +09:00
Michael Davis
a23b70182c commands: Allow using selected register where hardcoded
These snippets use hardcoded registers but it can be useful to be able
to specify a register for these commands.
2023-07-31 15:05:38 +09:00
Michael Davis
baceb02a09 Use refactored Registers type
This is an unfortunately noisy change: we need to update virtually all
callsites that access the registers. For reads this means passing in the
Editor and for writes this means handling potential failure when we
can't write to a clipboard register.
2023-07-31 15:05:38 +09:00
Philipp Mildenberger
8a28f30593
Reformat with nightly rustfmt for better let-else formatting (#7721) 2023-07-27 11:57:19 +09:00
Michael Davis
953073a679 highlighted_code_block: Take input text as &str
This removes a handful of allocations for functions calling into the
function, which is nice because the prompt may call this function on
every keypress.
2023-07-27 11:50:19 +09:00
Michael Davis
98ef05d768 Prefer RopeSlice to &Rope in helix_core::syntax
Pascal and I discussed this and we think it's generally better to
take a 'RopeSlice' rather than a '&Rope'. The code block rendering
function in the markdown component module is a good example for how
this can be useful: we can remove an allocation of a rope and instead
directly turn a '&str' into a 'RopeSlice' which is very cheap.

A change to prefer 'RopeSlice' to '&Rope' whenever the rope isn't
modified would be nice, but it would be a very large diff (around 500+
500-). Starting off with just the syntax functions seems like a nice
middle-ground, and we can remove a Rope allocation because of it.

Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
2023-07-27 11:50:19 +09:00
Michael Davis
f0b877e258 Tune regex highlights for usage in prompts
Since regex is almost always injected into other languages,
`pattern_character`s will inherit the highlight for the structure that
injects them (for example `/foo/` in JavaScript or `~r/foo/` in Elixir).
This removes the string highlight when used in the prompt.

We also add `ERROR` node highlighting so that errors in regex syntax
appear in the prompt. This resolves a TODO in the `regex_prompt`
function about highlighting errors in the regex.
2023-07-27 11:50:19 +09:00
Michael Davis
0dc3753eb2 Syntax-highlight regex prompts
We can use tree-sitter-regex highlighting in prompts for entering
regexes, like `search` or `global_search`. The `highlighted_code_block`
function from the markdown component makes this a very small change.

This could be improved in the future by leaving the parsed syntax tree
on the prompt, allowing incremental updates. Prompt lines are usually so
short though and tree-sitter-regex is rather small and uncomplicated,
so that improvement probably wouldn't make a big difference.
2023-07-27 11:50:19 +09:00
Michael Davis
6a431afc4e
Save an undo checkpoint before accepting completion (#7747) 2023-07-27 11:48:16 +09:00
Ryan Fowler
5c41f22c2a
Add support for LSP DidChangeWatchedFiles (#7665)
* Add initial support for LSP DidChangeWatchedFiles

* Move file event Handler to helix-lsp

* Simplify file event handling

* Refactor file event handling

* Block on future within LSP file event handler

* Fully qualify uses of the file_event::Handler type

* Rename ops field to options

* Revert newline removal from helix-view/Cargo.toml

* Ensure file event Handler is cleaned up when lsp client is shutdown
2023-07-22 00:21:21 +02:00
sigmaSd
8977123f25
feat: resolve code action (#7677) 2023-07-21 14:50:08 -05:00
Pascal Kuthe
8f1c6456f3
Clear statusline while prompt is visible (#7646) 2023-07-17 14:09:07 +09:00
Alex Vinyals
843ae97120
enhanced surround_replace to provide visual feedback (#7588) 2023-07-13 22:01:44 +09:00
Jonathan
0e0501c510
Fix piping to Helix on macOS (#5468) 2023-07-13 12:01:17 +09:00
Tudyx
9893a1fbcc
Auto indent change if selection is linewise (#7316) 2023-07-11 14:01:48 -05:00
Yomain
8afc0282f2
Fix crash when cwd is deleted (#7185) 2023-07-11 19:51:04 +02:00
Pascal Kuthe
1adb19464f
search buffer contents during global search (#5652) 2023-07-11 21:26:11 +09:00
Gabriel Hansson
c1488267e5
(Updated) Apply motion API refinements (#6078)
* _apply_motion generalization where possible

API encourages users to not forget setting `editor.last_motion` when
applying a motion. But also not setting `last_motion` without applying a
motion first.

* (rename) will_find_char -> find_char

method name makes it sound like it would be returning a boolean.

* use _apply_motion in find_char

Feature that falls out from this is that repetitions of t,T,f,F are
saved with the context extention/move and count. (Not defaulting to extend
by 1 count).

* Finalize apply_motion API

last_motion is now a private field and can only be set by calling
Editor.apply_motion(). Removing need (and possibility) of writing:

`motion(editor); editor.last_motion = motion`

Now it's just: `editor.apply_motion(motion)`

* editor.last_message: rm Box wrap around Arc

* Use pre-existing `Direction` rather than custom `SearchDirection`.

* `LastMotion` type alias for `Option<Arc<dyn Fn(&mut Editor)>>`

* Take motion rather than cloning it.

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

* last_motion as Option<Motion>.

* Use `Box` over `Arc` for `last_motion`.

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
2023-07-09 16:50:24 -04:00
Alex Vinyals
28452e1f2a
Initialize log and config files right after parsing arguments (#7585) 2023-07-09 11:30:43 -05:00
Ryan Fowler
828c7432e3
Implement the wa! command (#7577) 2023-07-09 09:38:50 -05:00
Alex Vinyals
1698992de6
Fix :log-open when --log is specified (#7573) 2023-07-09 16:35:07 +02:00
Alberto Romero
507dd50860
Add filename completer for shell prompt (#7569) 2023-07-08 18:12:28 +02:00
Pascal Kuthe
618620b369
use redraw handle for debouncing LSP messages (#7538) 2023-07-08 06:46:34 +09:00
Michael Davis
4fab60030f
LSP: Use negotiated position encoding for workspace edits (#7469)
Previously this was hard-coded to UTF-8 but we might have negotiated
another position encoding.
2023-06-30 00:24:13 +09:00
Michael Davis
d3f8e0592b
LSP: Discard publishDiagnostic from uninitialized servers (#7467)
The spec explicitly disallows publishDiagnostic to be sent before
the initialize response:

> ... the server is not allowed to send any requests or notifications to
> the client until it has responded with an InitializeResult ...

(https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize)

But if a non-compliant server sends this we currently panic because we
'.expect()' the server capabilities to be known to fetch the position
encoding. Instead of panicking we can discard the notification and log
the non-compliant behavior.
2023-06-28 16:59:13 -04:00
Pascal Kuthe
a0359f7f22 make TS matching fallback to plaintext 2023-06-22 16:00:08 +09:00
Michael Davis
9690e0b733
Fix Component implementations for Picker (#7382) 2023-06-19 18:55:46 +09:00
Gokul Soumya
f18acadbd0
Completely remove old Picker and rename FilePicker to Picker 2023-06-18 12:28:26 -05:00
Michael Davis
545acfda88
Make file preview callback optional
When Picker and FilePicker are merged, not all Pickers will be able to
show a preview.

Co-authored-by: Gokul Soumya <gokulps15@gmail.com>
2023-06-18 12:28:16 -05:00
Gokul Soumya
fc111213b5
Move FilePicker struct def closer to impl block 2023-06-18 12:14:41 -05:00
Gokul Soumya
15cc09fc81
Render the preview in FilePicker 2023-06-18 12:14:09 -05:00
Gokul Soumya
34c8f9ab73
Move Picker::render into FilePicker::render 2023-06-18 12:11:24 -05:00
Gokul Soumya
49fbf8df53
Move Component methods except render() to FilePicker 2023-06-18 12:10:00 -05:00
Gokul Soumya
1e66e9198c
Move handle_event methods from Picker to FilePicker 2023-06-18 12:07:38 -05:00
Gokul Soumya
8516f43837
Move navigation methods from Picker to FilePicker 2023-06-18 12:05:59 -05:00
Gokul Soumya
7a058c7361
Move scoring functions from Picker to FilePicker 2023-06-18 12:05:17 -05:00
Gokul Soumya
104036bd7f
Copy struct fields and new() from Picker to FilePicker 2023-06-18 12:01:16 -05:00
Gokul Soumya
40916dff63
Move FilePicker::render from Component impl to normal impl
Merges the code for the Picker and FilePicker into a single Picker that
can show a file preview if a preview callback is provided. This change
was mainly made to facilitate refactoring out a simple skeleton of a
picker that does not do any filtering to be reused in a normal Picker
and a DynamicPicker (see #5714; in particular [mikes-comment] and
[gokuls-comment]).

The crux of the issue is that a picker maintains a list of predefined
options (eg. list of files in the directory) and (re-)filters them every
time the picker prompt changes, while a dynamic picker (eg. interactive
global search, #4687) recalculates the full list of options on every
prompt change. Using a filtering picker to drive a dynamic picker hence
does duplicate work of filtering thousands of matches for no reason. It
could also cause problems like interfering with the regex pattern in the
global search.

I tried to directly extract a PickerBase to be reused in Picker and
FilePicker and DynamicPicker, but the problem is that DynamicPicker is
actually a DynamicFilePicker (i.e. it can preview file contents) which
means we would need PickerBase, Picker, FilePicker, DynamicPicker and
DynamicFilePicker and then another way of sharing the previewing code
between a FilePicker and a DynamicFilePicker. By merging Picker and
FilePicker into Picker, we only need PickerBase, Picker and
DynamicPicker.

[gokuls-comment]: https://github.com/helix-editor/helix/issues/5714#issuecomment-1410949578
[mikes-comment]: https://github.com/helix-editor/helix/issues/5714#issuecomment-1407451963
2023-06-18 11:34:13 -05:00
spectre256
d8b7232a47
Add yank_joined command (#7195)
Resolves issue #6888 by adding a command to join all selections and yank
them to the specified register. The typed command takes an argument as
the separator to use when joining the selections.
2023-06-16 21:13:23 +02:00
A-Walrus
4d8c9a394e
Preview scratch buffers in jumplist picker (#7331) 2023-06-13 16:05:01 +02:00
Zisulin Morbrot
fbd22afe29
Add rl and rla aliasses for reload and reload-all commands (#7158) 2023-06-13 08:50:50 -05:00
Robert
015c079acc
Add reverse_selection_contents (#7329) 2023-06-13 08:36:28 -05:00
Philipp Mildenberger
2a11fb485d
Fix underflow when repeating a completion that has a negative shift position (#7322) 2023-06-13 01:37:47 +09:00
0xHiro / ヒロ
8c6eb88c6a
fix: add file argument in help text (#7307) 2023-06-10 18:40:39 +02:00
Luca Schlecker
dbd248fdfa add config option for instant completion entry preview (defaulting to true).
Signed-off-by: Luca Schlecker <luca.schlecker@hotmail.com>
2023-06-09 13:23:29 -04:00
spectre256
00b152facd
Add register statusline element (#7222) 2023-06-08 14:34:07 -05:00
Alex
993c68ad6f
Auto indent on insert_at_line_start (#5837) 2023-06-08 19:11:40 +02:00
Michael Davis
d4427125eb
Bail if no language servers support workspace symbols (#7286) 2023-06-08 09:48:11 +09:00
vwkd
352d1574a6
add move_prev_long_word_end and extend_prev_long_word_end (#6905) 2023-06-08 00:41:35 +02:00
Michael Davis
b3949979ae Propagate the count and register to command palette commands
Previously a count or register selection would be lost while opening
the command palette. This change allows using a register selection or
count in any command chosen from the command palette.
2023-06-08 00:48:25 +09:00
Michael Davis
0e083497a5 Persist register selection in pending keymaps
Previously the register selection (via `"`) would be lost in the middle
of any key sequence longer than one key. For example, `<space>f` would
clear the register selection after the `<space>` making it inaccessible
for the `file_picker` command.

This behavior does not currently have any effect in the default keymap
but might affect custom keymaps. This change aligns the behavior of the
register with count. Making this change allows propagating the register
to the `command_palette` (see the child commit) or other pickers should
we decide to use registers in those in the future. (Interactive global
search for example.)
2023-06-08 00:48:25 +09:00
Alex Vinyals
204bac1706
commands(toggle): use pattern matching on the Value enum (#7240) 2023-06-07 17:50:16 +09:00
gibbz00
9926c2d292 Remove Keymap(KeyTrie) and simply use KeyTrie. 2023-06-07 10:11:13 +09:00
gibbz00
b8563685ec Move keymap.reverse_keymap() to Keytrie:
The plan is let `Keymaps` simply store `KeyTrie`s, as the `Keymap(Keytrie)` wrapping serves little to no purpose.
2023-06-07 10:11:13 +09:00
gibbz00
eda4c79f2f Remove pub keymap.name();
`keymap.name` is only used internally.
2023-06-07 10:11:13 +09:00
gibbz00
3d0bc72099 Place Info::from_keymap() contents in keymap.infobox():
This makes it easier later control the order in which the key events
are presented.
2023-06-07 10:11:13 +09:00
gibbz00
19326d23d1 Keymap infobox: Idiomatic body tuple.
Does not change any behavior other than making the tuple slightly
more idiomatic.  Keymap infobox shows key events, then the respective
description. This commit makes sure that order is used from the get go,
rather than flipping it midway.
2023-06-07 10:11:13 +09:00
gibbz00
3a0892f793 Exclude config no_op bindings in command palette. 2023-06-07 10:11:13 +09:00
gibbz00
39773e48d3 Remove superfluous command description pruning for keymap infobox:
Exist under the wrong (possibly just outdated) assumption that command
descriptions are written with their `KeyTrie` name prefixed
2023-06-07 10:11:13 +09:00
gibbz00
d20c1632a7 helix_term::keymap: Remove one-liner solely used for a test. 2023-06-07 10:11:13 +09:00
gibbz00
f7df53c948 Make Keymap a tuple struct. 2023-06-07 10:11:13 +09:00
gibbz00
daea97a89f keymap: Rename KeyTrie::Leaf -> KeyTrie::MapppableCommand
The variant Sequence is technically also a leaf.
2023-06-07 10:11:13 +09:00
gibbz00
a56af221d7 keymap: Derive Default for KeyTrieNode 2023-06-07 10:11:13 +09:00
Alex Vinyals
a2b8cfdb8c
feat(core): add plaintext matching fallback to tree-sitter matching (#4288) 2023-06-05 23:13:00 +09:00
Michael Davis
428d33ab50
Exit gracefully on termination signals (#7236) 2023-06-05 22:27:57 +09:00
Alex Vinyals
d5707a4696
feat(commands): allows cycling option values at runtime (#4411) 2023-06-05 22:22:05 +09:00
Ethan Wilkes
3334e7e4b2
fixed repeat_last_motion extends selection (#7159) 2023-05-29 00:51:22 +09:00
Matthew Toohey
207829eefe
Fix off-by-one in select symbol references (#7132) 2023-05-25 14:01:56 +02:00
Poliorcetics
8e2660b5cc
Update diagnostics correctly on LSP exit (#7111)
* chore: avoid format! call with argument when useless

* feat: also clear diagnostics for unopened documents when exiting an LSP

* feat: we already worked on `self.editor.diagnostics` no need to redo the checks
2023-05-23 12:33:01 +02:00