feat(editor): make copy selection report failure without selection - #1166
feat(editor): make copy selection report failure without selection#1166catlover-bot wants to merge 3 commits into
Conversation
|
Nice! |
|
Yes, I think there are a few other commands that naturally have an "inapplicable" state. For example, the original issue mentions moving to the line start when already there, cutting with no selection, and deleting a word when there is nothing to delete. Undo/redo at the end of their stacks and motions/searches that cannot find a target seem similar. At the editor layer, I think two states may be enough for now: something like That also makes me think an internal enum may communicate the intent better than the If that matches what you had in mind, I can change this PR from |
|
Yeah I am a big fan of using enums since they make it possible to easily extend it if we find out there are other states we want to represent, and they are also self documenting. |
ecf536d to
1824a3c
Compare
|
Thanks! I changed the boolean result to a separate internal The command-list path aggregates that status without short-circuiting, so all commands in an edit event still run as before, while I also rebased the PR onto current |
kronberger-droid
left a comment
There was a problem hiding this comment.
Two seperate things also:
Right now if we aggregate multiple EditCommands and the Inapplicable always win. But if we would have a Edit(vec![InsertString("abc"), CopySelection]) It reports Inapplicable after having changed the buffer.
The early return then skips abbrevation expansion and the menu block, ant the top loop skips the repaint.
Multiple answers te same question with any Handled wins.
Nothing right now hits this, but i would flip it into any-Applied-wins for now.
|
Thanks for the review. I changed command-list aggregation to any- I also added a regression test for an edit containing The copy-selection helpers now return Local validation is green: 1605 tests passed, 1 ignored, 30 doctests passed, and clippy/fmt/diff checks are clean. |
|
If you rebase it onto the current main I think we are ready to land it. |
6afb412 to
002ac82
Compare
|
Thanks! I rebased the branch onto the current |
Summary
Make
CopySelectionandCopySelectionSystemreport whether they actually had a selection to copy, and propagate that status throughReedlineEvent::EditsoUntilFoundcan continue when there is no active selection.This follows the direction discussed in #876 of making edit operations explicit about their outcome.
Editor::run_edit_commandreports a dedicatedEditCommandStatuswithAppliedandInapplicablevariants, keeping edit-command outcomes separate fromEventStatusand leaving room for additional states later. This PR intentionally reportsInapplicableonly for the two copy-selection commands; broader command semantics andExecuteHostCommandremain out of scope.Observable behavior changes only for
UntilFoundchains containingCopySelectionorCopySelectionSystem.Before
ReedlineEvent::Editwas always treated asHandled, even whenCopySelectionorCopySelectionSystemhad no active selection. As a result, anUntilFoundchain stopped at the copy command and never tried a fallback event such asCtrlC.After
CopySelectionandCopySelectionSystemreportEditCommandStatus::Inapplicablewhen no selection is active.ReedlineEvent::Editconverts that result toEventStatus::Inapplicable, allowingUntilFoundto try the next event. When a selection exists they reportApplied, and the chain stops as before.Regression tests cover both copy commands with and without an active selection.
Additional notes
Addresses the
CopySelection/CopySelectionSystemportion of #876.Validation performed locally:
cargo fmt --all -- --checkcargo clippy --locked --all-targets --all-featurescargo test --all --all-features -- --test-threads=1(1605 passed, 1 ignored; doctests: 30 passed)git diff --check