Take into account that only the product of the `multiplier` and `count`
are relevant to execute motions.
From 140f6d0eda/runtime/doc/motion.txt (L63-L70)
> If the motion includes a count and the operator also had a count before it,
> the two counts are multiplied. For example: "2d3w" deletes six words.
> When doubling the operator it operates on a line. When using a count, before
> or after the first character, that many lines are operated upon. Thus `3dd`
> deletes three lines. A count before and after the first character is
> multiplied, thus `2y3y` yanks six lines.
Necessary to complete nushell/nushell#6590
(Comment: this whole module feels intricately linked to the nushell
implementation as we do not implement the string parsing in reedline)
* change history session_id to a systematically generated number
* added env var, removed comments
* tweak test
* add public function to get the history session id
* switch from reedline commit date to unix_epoch
* Fix vi character search parsing
Fixes#473
The parser has to consume the items from the iterator to be in a
consistent state!
* Move `ViToTill` logically to `motion.rs`
* Add basic regression test for #473
Addresses #320, #236
* Adding External printer
* Made ExternalPrinter as an optional feature. Clippy is happy, test pass, docs added.
* ExternalPrinter: prints multiple messages if available, more on error-handling.
* Bug(s) fixed. Prints messages. Working example in examples folder. Code formatted, clippyed, tests pass.
* Generic ExternalPrinter<T> where T: Display.
* Fixed: Works with buffers larger than a line.
* Fixed: Works with buffers larger than a line, refactored.
* Different approach, seems to look like what is expected. Gives the "illusion" of one line being entered. Needs more testing, could have some off by one errors ;)
Co-authored-by: Gregor Engberding <gregor@meinkopter.de>
This allows nushell to implement a command similar to fish's `commandline`:
https://fishshell.com/docs/current/cmds/commandline.html
that would allow commands run via `executehostcommand` bindings to do interesting
things to the contents of the input buffer.
This is necessary to avoid the problem with running executehostcommand keybindings in nushell
right after launching it (without having run actual user-input commands yet).
Since the error types are not exposed outside of the crate, we have to use a check instead of
matching on the error.
- Fixed anchor links (some links were not pointing to correct headings).
- Updated headings (some headings in outline didn't match the content).
- Fixed heading level for "Integrate with History" (was 2 should be 3).
* Delete unused code in `CircularCompletionHandler`
I could not find anywhere that the `Reedline::ActionHandler` event is
actually created, except for a bit of deserialization code in nushell
(reedline_config.rs:817). I suspect its functionality is no longer
needed in the current version of reedline.
* Improve word-level undo and completions undo
* Adds completions and history searches to the undo stack
This required changing all the menu interfaces to do their edits through
the `Editor` struct, so it can track undo state
* Improves the system of coalescing word-level edits on the undo stack
This involved expanding the `UndoBehavior` system. Now, every edit gets
tagged with `UndoBehavior`, and by comparing the `UndoBehavior` of the
current and previous edit, we can decide whether these changes should
be grouped together on the undo stack.
Chains of repeated backspace, delete, insertion, or history naviagition
can each be grouped together to form a single undo entry when
appropriate.
* Removing low-usage wrapper methods from editor.rs
Removes LineBuffer wrappers from Editor wherever the wrapper is used
only once, or only internally to the `editor.rs` file.
* Run cargo fmt
* Fixed undo coalescing for backspace/delete with \n
The logic was a bit trickier than I thought. Added some tests
to confirm the intended behavior where adding/deleting newlines creates
additional undo points
* Remove debugging logging code
* Revert "Removing low-usage wrapper methods from editor.rs"
- Also revert reintroduction of `CutFromStart` bug in vi mode
8b5e70fc0e
* Fix undo coalescing for CRLF deletions
* Ensure proper undo tracking in public Editor fns
Delete or make private all Editor functions that modify the line buffer
without tracking UndoBehavior
* Make Editor crate level pub
Added documentation for pub methods on Editor. Kept the public API
smaller by making many convenience methods pub(crate) if they can be
implemented via the pub methods
* Cleanup changes
* word_starts and word_ends functions no longer needed with current
word-level undo tracking algorithm
* `undo` and `redo` don't need to call `update_undo_behavior` because they are
private methods and `run_edit_command` already calls `update_undo_behavior`
* Fix for new clippy warning
* Editor+LineBuffer API updates for nushell merge
* Make `LineBuffer::replace_range` pub rather than pub(crate)
* Make `Editor::set_line_buffer` and `Editor::set_buffer` pub(crate) in
favor of the new `Editor::edit_buffer`.
I believe the `edit_buffer` change is a better API to expose for
`Menu` implementations, as it avoids the need for `clones` while
enforcing proper undo tracking.
Export `crossterm::event::{KeyCode, KeyModifiers}` as our own.
This way users of the library don't have to import crossterm with the
same version explicitly to set their own keybindings.
Closes#456
* Vi mode add support for d0, d^, c0, and c^
Also changes d$ to delete just current line for
multiline inputs
* Make `d0` line aware
* Make `c0` line aware
Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
`rstest = 0.12` added support for asynchronous timeouts during testing
thus requiring a larger set of dependencies. Since `rstest = 0.14` this
can be disabled if not used.
Should keep build times for local or CI tests in check.
This new crossterm version includes a breaking change to the indexing of
certain cursor move operations:
https://github.com/crossterm-rs/crossterm/releases/tag/0.24
While reedline itself might not be affected, check the code of the
consuming application that needs to match the crossterm version!
> Switch case of the character under the cursor and move the cursor to
> the right.
vi behavior is to only swap the case of an ASCII character so this is
implementation matches that behavior
* Support vi mode ; and , motions
The f, F, t, and T left-right motions can be repeated with the ; motion,
or reversed with the , motion:
> ; Repeat latest f, t, F or T [count] times. See cpo-;
>
> , Repeat latest f, t, F or T in opposite direction
> [count] times. See also cpo-;
I named these "to-till" motions as the first word of the description for
the f and T motions are "To" and "Till" respectively.
Add storage for the last To or Till motion on the `Vi` struct, and pass
it through to `parse_command()` so `;` or `,` can re-use it.
When a to-till motion is fully parsed the new to-till motion is stored
in the `Vi` struct.
* Correctly implement ,
The last to or till motion should be recorded from f, F, t, or T.
Using , to reverse the to/till motion must not change the motion that
will be replayed.
In other words, if you f to move to the right then pressing , will only
move you left. Pressing , will not swap between the two matching
characters your cursor is on or between.
* Fix clippy
This is an incomplete implementation as it omits the behaviors for
CTRL-V, CTRL-E, and CTRL-Y:
> Replace the character under the cursor with {char}. If {char} is a
> <CR> or <NL>, a line break replaces the character. To replace with a
> real <CR>, use CTRL-V <CR>. CTRL-V <NL> replaces with a <Nul>.
>
> If {char} is CTRL-E or CTRL-Y the character from the line below or
> above is used, just like with |i_CTRL-E| and |i_CTRL-Y|. This also
> works with a count, thus `10r<C-E>` copies 10 characters from the line
> below.
The similarly-named ReplaceChars is used for history substitution and
is more complicated than we need (n_chars will always be 1, string will
always be a single character string), but could be used if the extra
replace_char() function is too much.
* Add vi W motion
This moves forward by WORD which is a sequence of non-blank characters
separated by whitespace.
* Add vi B motion
Support deleting backward for word (db) and WORD (dB)
* Add vi E motion
Makes the history querying structs and enums pub as it seems reasonable
for now. Useful to create nushells `history` command.
Might make sense to change that API to something simpler cleaner later.
Changes the history API to support different storage backends and more rich information to be used as metadata/filtering criterions.
Includes a SQLite backed history with additional fields and ports the simple `FileBackedHistory` format consistent.
Includes a `HistoryCursor` to abstract the internal interactive browsing.
Updates `History` trait to cover the API to load and store to the storage backend.
Commits
* basic sqlite history
* fix test compilation
* final touches for MVP
* better documentation
* fix for empty history
* partial change to non-generic history
* mostly working
* fix tests and ci
* fixes, format
* move history item to new file
* fix some comments, fix test compile errors
todo: fix tests
* ci features matrix
* fix index creation
* fix file-based tests
* move logic for not saving empty entries to engine
* fix update last command on empty, set up application_id and check version
* add specific error variants
* format
* fix compile errors
* fix fmt
* sqlite with bashisms
* hide with features
* cargo fmt
* improve performance of bashisms selectors
* Style: Remove commented out code
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: Fernando Herrera <fernando.j.herrera@gmail.com>
Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
* Fix clippy lints that will become warnings
clippy from the nightly future
* Revent false positive `.to_string()` removal
This [lint](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned) is nasty as `ansi_term` and thus `nu_ansi_term` on their `AnsiGenericString` implement `Display` to apply the styling and `Deref` to just return the underlying `&str`.
As [`ToString` is implemented for any `T: Display + ?Sized` ](https://doc.rust-lang.org/std/string/trait.ToString.html#impl-ToString-6) the to_string implementation relies on the `Display` defined for the type alias `AnsiString` and not on the `impl ToString for str` for the `&str` accessible through `Deref`.
Applying the suggested fix will remove syntax highlighting!!!
* don't panic whan parent directory is not exists
* no need to check parent exists
Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
Group the common keybindings into three functions:
- `add_common_control_bindings`
- `add_common_navigation_bindings`
- `add_common_edit_bindings`
Vi normal uses the first two
Vi insert uses all of them
Emacs extends upon those
Goals:
- Provide pointers to further reading for folks not too familiar with the
problem set on the terminal
- Explain the architecture a bit to get people up to speed
The code didn't account for the index
and the indicator in its calculation for
the number of lines in the list_menu.
Now the unicode_width of the indicator and the
number of digits of the index are accountet for.
Amortized growing of the history based on the amount read from the file
is cheap. Allocating for the capacity is expensive and can cause OOM for
large capacities.
Fix for nushell/nushell#5593