-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to select and cut text in the input buffer #689
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main nushell/nushell#689 +/- ##
==========================================
+ Coverage 49.32% 49.69% +0.37%
==========================================
Files 46 46
Lines 7998 8433 +435
==========================================
+ Hits 3945 4191 +246
- Misses 4053 4242 +189
|
This looks like a promising start. Is it enabled in any of the reedline demos so we can try it out? |
You can try it out in the basic example of reedline. It is not gated behind a feature. But if you want to use Ctrl+V you have to compile with feature system_clipboard, at least on windows. |
Hmmm, I'm on macos and can't get it to work. I compiled with |
I have not yet implemented highlighting of the selection. If you hold down Shift and move the cursor to over text and afterwards press Ctrl + X you should have the text in the clipboard. At least pasting inside the terminal again worked without problem for me. Edit: I just tested pasting outside of the terminal, that works for me, too. |
oh, i see. seems to work great with that little tidbit. 😆 thanks. |
3abf24c
to
5e1cabd
Compare
Is there anything left to do before you can consider to merge it? The two failing clippy lints are not related to the code I touched, so I don't know what to do about them... |
Just change the code like the clippy lints suggest, replacing Do you plan on making a PR for nushell based on this PR? |
8926787
to
e5d1b2d
Compare
Yeah, that was my plan |
I'd like to know/see what changes are required in nushell before landing this. |
e5d1b2d
to
b06ce6a
Compare
I've looked over this several times now and I'm about ready to land it. I see you have a builder pattern to implement it in nushell (and others). How are you feeling about this PR/Do you still have things you want to do or are you ready? |
Yes, that should work just like any other EditCommand. However, the bindings
Actually, I am currently working on making selection an option for all of the previously existing |
Would you mind talking a bit about how the selection, etc works in relation to graphemes? Seems like we have a lot of grapheme work here but I'm not sure all that is accommodated in your new code or not and I'd hate to break that type of thing. |
Of course, I will try to give a brief summary of the selection logic and how it relates to grapheme boundaries. Any
By this logic, the
the indices bracketing the selected text in the line buffer are always valid indices at grapheme boundaries. |
Thanks so much for the detailed explanation ❤️. It seems like we'd want to remove this maintenance hazard if we could, although I believe that to be outside the scope of this PR. |
ok, let's go with this then! |
now you can update your nushell PR and we can troubleshoot there. hopefully we don't have to come back here to make any changes. |
This PR should close #1171 # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR introduces the capability to select text using the existing move.. `EditCommand`s of `reedline`. Those commands are extended with an optional parameter specifying if text should be selected while navigating. This enables a workflow familiar from a wide variety of text editors, where holding `shift` while navigating selects all text between the initial cursor position when pressing `shift` and the current cursor position. Before this PR can be merged the [sibling PR for reedline](nushell/reedline#689) has to land first. # User-Facing Changes ## Additional `EditCommand`s 1. `SelectAll` 2. `CutSelection` 3. `CopySelection` ## New optional parameter on existing `EditCommand`s All `EditCommand`s of `EditType` `MoveCursor` have a new optional parameter named `select` of type `bool`. If this parameter is not set by a user it is treated as false, which corresponds to their behavior up to now. I am relatively new to `nushell` and as such may not know of existing behavior that might change through this PR. However, I believe there should be none. I come to this conclusion because 1. Existing commands are extended only with an *optional* additional parameter, users who currently use these EditCommands keep their existing behavior if they don't use it. 2. A few new commands are introduced which were previously not valid. 3. The default keybindings specified in `default_config.nu` are untouched. # Tests + Formatting Tests for the new optional parameter for the move commands are included to make sure that they truly are optional and an unused optional parameter conforms to the previous behavior.
@Tastaturtaste when you have a minute, could you help us figure out why these cut/copy/select_all/paste keybindings are not working in nushell when it's launched with |
I will have to see if I get to it tomorrow. |
Hmm, I just cloned a fresh copy of nushell and tried to reproduce the commands not working. But for me everything works as expected. Just to be sure I did the right steps to reproduce:
Are there specific steps to reproduce the issue? |
@amtoine can you comment on this? @Tastaturtaste It works on flawlessly on Windows for me with |
@Tastaturtaste on WSL Ubuntu, when I typed |
I can't take a closer look today, but will look into it in the next few days. Sadly my weekend is packed already, so maybe after that. The backtrace gives a good hint already. Somewhere in I can reproduce the crash with a shorter prompt on windows:
Edit: Or rather a crash in that function. I get a
Seems I botched some logic in that function :/ |
@Tastaturtaste Sounds good. We appreciate your help whenever you can get to it! |
@Tastaturtaste Could you put that panic with repro steps in a separate issue and slap the "Critical" label on it? So that we can track easier in case you won't have time in the next few days. |
I think this is a similar panic in nushell #750 |
#689 (comment) |
I reproduced the error on WSL. The fix for my subtraction with overflow error also fixes this one. Unless someone says otherwise I consider this bug fixed with #751. |
Thanks @Tastaturtaste. Do you have a nushell branch that I can easily test this in? I'm not quite sure how to reproduce it in reedline. I've tried but can't make it fail. |
I don't have one pushed. Locally I tested with the nushell main branch and set reedshell patch to my git branch. Do you need me to push a nushell branch to test? |
If it's not too much trouble. It would make it easier for us to test. |
https://github.com/Tastaturtaste/nushell/tree/test-reedline-style-text-fix |
Let me try to reproduce the problem and try your branch and see how far that gets. Thanks so much! Gimme a few and I'll ping you back. |
Looks like it fixes it to me. Thanks |
# Description This fixes a panic with the text selection. Reference nushell/reedline#751 nushell/reedline#750 nushell/reedline#689 (comment) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This PR should close nushell#1171 # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR introduces the capability to select text using the existing move.. `EditCommand`s of `reedline`. Those commands are extended with an optional parameter specifying if text should be selected while navigating. This enables a workflow familiar from a wide variety of text editors, where holding `shift` while navigating selects all text between the initial cursor position when pressing `shift` and the current cursor position. Before this PR can be merged the [sibling PR for reedline](nushell/reedline#689) has to land first. # User-Facing Changes ## Additional `EditCommand`s 1. `SelectAll` 2. `CutSelection` 3. `CopySelection` ## New optional parameter on existing `EditCommand`s All `EditCommand`s of `EditType` `MoveCursor` have a new optional parameter named `select` of type `bool`. If this parameter is not set by a user it is treated as false, which corresponds to their behavior up to now. I am relatively new to `nushell` and as such may not know of existing behavior that might change through this PR. However, I believe there should be none. I come to this conclusion because 1. Existing commands are extended only with an *optional* additional parameter, users who currently use these EditCommands keep their existing behavior if they don't use it. 2. A few new commands are introduced which were previously not valid. 3. The default keybindings specified in `default_config.nu` are untouched. # Tests + Formatting Tests for the new optional parameter for the move commands are included to make sure that they truly are optional and an unused optional parameter conforms to the previous behavior.
# Description This fixes a panic with the text selection. Reference nushell/reedline#751 nushell/reedline#750 nushell/reedline#689 (comment) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
# Description This fixes a panic with the text selection. Reference nushell/reedline#751 nushell/reedline#750 nushell/reedline#689 (comment) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
Addresses issue nushell/nushell#380.
This is already the case if the crate is compiled with the feature
system_clipboard
. This is, afaik, not (yet) done for nushell.