mirror of
https://github.com/nushell/nushell.git
synced 2025-05-06 07:52:57 +00:00
update reedline editcommands in nushell (#15191)
# Description This PR tries to update the EditCommands and ReedlineEvents by adding missing items and ordering them to the same order that the reedline enum has them listed. @sholderbach When you have time, would you mind looking at this please. I left some TODOs because I wasn't sure how to implement them. I also guessed at some of the other implementations. I don't use vim much so I'm not really sure how these are supposed to act. I was really just trying to fill in the blanks. # User-Facing Changes Closes #15167 # 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 toolkit.nu; toolkit test stdlib"` 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. --> --------- Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
parent
78c93e5ae0
commit
48bdcc71f4
@ -998,41 +998,54 @@ fn event_from_record(
|
|||||||
) -> Result<ReedlineEvent, ShellError> {
|
) -> Result<ReedlineEvent, ShellError> {
|
||||||
let event = match name {
|
let event = match name {
|
||||||
"none" => ReedlineEvent::None,
|
"none" => ReedlineEvent::None,
|
||||||
"clearscreen" => ReedlineEvent::ClearScreen,
|
|
||||||
"clearscrollback" => ReedlineEvent::ClearScrollback,
|
|
||||||
"historyhintcomplete" => ReedlineEvent::HistoryHintComplete,
|
"historyhintcomplete" => ReedlineEvent::HistoryHintComplete,
|
||||||
"historyhintwordcomplete" => ReedlineEvent::HistoryHintWordComplete,
|
"historyhintwordcomplete" => ReedlineEvent::HistoryHintWordComplete,
|
||||||
"ctrld" => ReedlineEvent::CtrlD,
|
"ctrld" => ReedlineEvent::CtrlD,
|
||||||
"ctrlc" => ReedlineEvent::CtrlC,
|
"ctrlc" => ReedlineEvent::CtrlC,
|
||||||
|
"clearscreen" => ReedlineEvent::ClearScreen,
|
||||||
|
"clearscrollback" => ReedlineEvent::ClearScrollback,
|
||||||
"enter" => ReedlineEvent::Enter,
|
"enter" => ReedlineEvent::Enter,
|
||||||
"submit" => ReedlineEvent::Submit,
|
"submit" => ReedlineEvent::Submit,
|
||||||
"submitornewline" => ReedlineEvent::SubmitOrNewline,
|
"submitornewline" => ReedlineEvent::SubmitOrNewline,
|
||||||
"esc" | "escape" => ReedlineEvent::Esc,
|
"esc" | "escape" => ReedlineEvent::Esc,
|
||||||
|
// Non-sensical for user configuration:
|
||||||
|
//
|
||||||
|
// `ReedlineEvent::Mouse` - itself a no-op
|
||||||
|
// `ReedlineEvent::Resize` - requires size info specifically from the ANSI resize
|
||||||
|
// event
|
||||||
|
//
|
||||||
|
// Handled above in `parse_event`:
|
||||||
|
//
|
||||||
|
// `ReedlineEvent::Edit`
|
||||||
|
"repaint" => ReedlineEvent::Repaint,
|
||||||
|
"previoushistory" => ReedlineEvent::PreviousHistory,
|
||||||
"up" => ReedlineEvent::Up,
|
"up" => ReedlineEvent::Up,
|
||||||
"down" => ReedlineEvent::Down,
|
"down" => ReedlineEvent::Down,
|
||||||
"right" => ReedlineEvent::Right,
|
"right" => ReedlineEvent::Right,
|
||||||
"left" => ReedlineEvent::Left,
|
"left" => ReedlineEvent::Left,
|
||||||
"searchhistory" => ReedlineEvent::SearchHistory,
|
|
||||||
"nexthistory" => ReedlineEvent::NextHistory,
|
"nexthistory" => ReedlineEvent::NextHistory,
|
||||||
"previoushistory" => ReedlineEvent::PreviousHistory,
|
"searchhistory" => ReedlineEvent::SearchHistory,
|
||||||
"repaint" => ReedlineEvent::Repaint,
|
// Handled above in `parse_event`:
|
||||||
"menudown" => ReedlineEvent::MenuDown,
|
//
|
||||||
"menuup" => ReedlineEvent::MenuUp,
|
// `ReedlineEvent::Multiple`
|
||||||
"menuleft" => ReedlineEvent::MenuLeft,
|
// `ReedlineEvent::UntilFound`
|
||||||
"menuright" => ReedlineEvent::MenuRight,
|
|
||||||
"menunext" => ReedlineEvent::MenuNext,
|
|
||||||
"menuprevious" => ReedlineEvent::MenuPrevious,
|
|
||||||
"menupagenext" => ReedlineEvent::MenuPageNext,
|
|
||||||
"menupageprevious" => ReedlineEvent::MenuPagePrevious,
|
|
||||||
"openeditor" => ReedlineEvent::OpenEditor,
|
|
||||||
"menu" => {
|
"menu" => {
|
||||||
let menu = extract_value("name", record, span)?;
|
let menu = extract_value("name", record, span)?;
|
||||||
ReedlineEvent::Menu(menu.to_expanded_string("", config))
|
ReedlineEvent::Menu(menu.to_expanded_string("", config))
|
||||||
}
|
}
|
||||||
|
"menunext" => ReedlineEvent::MenuNext,
|
||||||
|
"menuprevious" => ReedlineEvent::MenuPrevious,
|
||||||
|
"menuup" => ReedlineEvent::MenuUp,
|
||||||
|
"menudown" => ReedlineEvent::MenuDown,
|
||||||
|
"menuleft" => ReedlineEvent::MenuLeft,
|
||||||
|
"menuright" => ReedlineEvent::MenuRight,
|
||||||
|
"menupagenext" => ReedlineEvent::MenuPageNext,
|
||||||
|
"menupageprevious" => ReedlineEvent::MenuPagePrevious,
|
||||||
"executehostcommand" => {
|
"executehostcommand" => {
|
||||||
let cmd = extract_value("cmd", record, span)?;
|
let cmd = extract_value("cmd", record, span)?;
|
||||||
ReedlineEvent::ExecuteHostCommand(cmd.to_expanded_string("", config))
|
ReedlineEvent::ExecuteHostCommand(cmd.to_expanded_string("", config))
|
||||||
}
|
}
|
||||||
|
"openeditor" => ReedlineEvent::OpenEditor,
|
||||||
str => {
|
str => {
|
||||||
return Err(ShellError::InvalidValue {
|
return Err(ShellError::InvalidValue {
|
||||||
valid: "a reedline event".into(),
|
valid: "a reedline event".into(),
|
||||||
@ -1062,7 +1075,6 @@ fn edit_from_record(
|
|||||||
.and_then(|value| value.as_bool())
|
.and_then(|value| value.as_bool())
|
||||||
.unwrap_or(false),
|
.unwrap_or(false),
|
||||||
},
|
},
|
||||||
|
|
||||||
"movetoend" => EditCommand::MoveToEnd {
|
"movetoend" => EditCommand::MoveToEnd {
|
||||||
select: extract_value("select", record, span)
|
select: extract_value("select", record, span)
|
||||||
.and_then(|value| value.as_bool())
|
.and_then(|value| value.as_bool())
|
||||||
@ -1098,16 +1110,6 @@ fn edit_from_record(
|
|||||||
.and_then(|value| value.as_bool())
|
.and_then(|value| value.as_bool())
|
||||||
.unwrap_or(false),
|
.unwrap_or(false),
|
||||||
},
|
},
|
||||||
"movewordrightend" => EditCommand::MoveWordRightEnd {
|
|
||||||
select: extract_value("select", record, span)
|
|
||||||
.and_then(|value| value.as_bool())
|
|
||||||
.unwrap_or(false),
|
|
||||||
},
|
|
||||||
"movebigwordrightend" => EditCommand::MoveBigWordRightEnd {
|
|
||||||
select: extract_value("select", record, span)
|
|
||||||
.and_then(|value| value.as_bool())
|
|
||||||
.unwrap_or(false),
|
|
||||||
},
|
|
||||||
"movewordrightstart" => EditCommand::MoveWordRightStart {
|
"movewordrightstart" => EditCommand::MoveWordRightStart {
|
||||||
select: extract_value("select", record, span)
|
select: extract_value("select", record, span)
|
||||||
.and_then(|value| value.as_bool())
|
.and_then(|value| value.as_bool())
|
||||||
@ -1118,6 +1120,16 @@ fn edit_from_record(
|
|||||||
.and_then(|value| value.as_bool())
|
.and_then(|value| value.as_bool())
|
||||||
.unwrap_or(false),
|
.unwrap_or(false),
|
||||||
},
|
},
|
||||||
|
"movewordrightend" => EditCommand::MoveWordRightEnd {
|
||||||
|
select: extract_value("select", record, span)
|
||||||
|
.and_then(|value| value.as_bool())
|
||||||
|
.unwrap_or(false),
|
||||||
|
},
|
||||||
|
"movebigwordrightend" => EditCommand::MoveBigWordRightEnd {
|
||||||
|
select: extract_value("select", record, span)
|
||||||
|
.and_then(|value| value.as_bool())
|
||||||
|
.unwrap_or(false),
|
||||||
|
},
|
||||||
"movetoposition" => {
|
"movetoposition" => {
|
||||||
let value = extract_value("value", record, span)?;
|
let value = extract_value("value", record, span)?;
|
||||||
let select = extract_value("select", record, span)
|
let select = extract_value("select", record, span)
|
||||||
@ -1139,6 +1151,13 @@ fn edit_from_record(
|
|||||||
EditCommand::InsertString(value.to_expanded_string("", config))
|
EditCommand::InsertString(value.to_expanded_string("", config))
|
||||||
}
|
}
|
||||||
"insertnewline" => EditCommand::InsertNewline,
|
"insertnewline" => EditCommand::InsertNewline,
|
||||||
|
"replacechar" => {
|
||||||
|
let value = extract_value("value", record, span)?;
|
||||||
|
let char = extract_char(value)?;
|
||||||
|
EditCommand::ReplaceChar(char)
|
||||||
|
}
|
||||||
|
// `EditCommand::ReplaceChars` - Internal hack not sanely implementable as a
|
||||||
|
// standalone binding
|
||||||
"backspace" => EditCommand::Backspace,
|
"backspace" => EditCommand::Backspace,
|
||||||
"delete" => EditCommand::Delete,
|
"delete" => EditCommand::Delete,
|
||||||
"cutchar" => EditCommand::CutChar,
|
"cutchar" => EditCommand::CutChar,
|
||||||
@ -1146,6 +1165,7 @@ fn edit_from_record(
|
|||||||
"deleteword" => EditCommand::DeleteWord,
|
"deleteword" => EditCommand::DeleteWord,
|
||||||
"clear" => EditCommand::Clear,
|
"clear" => EditCommand::Clear,
|
||||||
"cleartolineend" => EditCommand::ClearToLineEnd,
|
"cleartolineend" => EditCommand::ClearToLineEnd,
|
||||||
|
"complete" => EditCommand::Complete,
|
||||||
"cutcurrentline" => EditCommand::CutCurrentLine,
|
"cutcurrentline" => EditCommand::CutCurrentLine,
|
||||||
"cutfromstart" => EditCommand::CutFromStart,
|
"cutfromstart" => EditCommand::CutFromStart,
|
||||||
"cutfromlinestart" => EditCommand::CutFromLineStart,
|
"cutfromlinestart" => EditCommand::CutFromLineStart,
|
||||||
@ -1162,6 +1182,7 @@ fn edit_from_record(
|
|||||||
"uppercaseword" => EditCommand::UppercaseWord,
|
"uppercaseword" => EditCommand::UppercaseWord,
|
||||||
"lowercaseword" => EditCommand::LowercaseWord,
|
"lowercaseword" => EditCommand::LowercaseWord,
|
||||||
"capitalizechar" => EditCommand::CapitalizeChar,
|
"capitalizechar" => EditCommand::CapitalizeChar,
|
||||||
|
"switchcasechar" => EditCommand::SwitchcaseChar,
|
||||||
"swapwords" => EditCommand::SwapWords,
|
"swapwords" => EditCommand::SwapWords,
|
||||||
"swapgraphemes" => EditCommand::SwapGraphemes,
|
"swapgraphemes" => EditCommand::SwapGraphemes,
|
||||||
"undo" => EditCommand::Undo,
|
"undo" => EditCommand::Undo,
|
||||||
@ -1218,17 +1239,64 @@ fn edit_from_record(
|
|||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
EditCommand::MoveLeftBefore { c: char, select }
|
EditCommand::MoveLeftBefore { c: char, select }
|
||||||
}
|
}
|
||||||
"complete" => EditCommand::Complete,
|
"selectall" => EditCommand::SelectAll,
|
||||||
"cutselection" => EditCommand::CutSelection,
|
"cutselection" => EditCommand::CutSelection,
|
||||||
|
"copyselection" => EditCommand::CopySelection,
|
||||||
|
"paste" => EditCommand::Paste,
|
||||||
|
"copyfromstart" => EditCommand::CopyFromStart,
|
||||||
|
"copyfromlinestart" => EditCommand::CopyFromLineStart,
|
||||||
|
"copytoend" => EditCommand::CopyToEnd,
|
||||||
|
"copytolineend" => EditCommand::CopyToLineEnd,
|
||||||
|
"copycurrentline" => EditCommand::CopyCurrentLine,
|
||||||
|
"copywordleft" => EditCommand::CopyWordLeft,
|
||||||
|
"copybigwordleft" => EditCommand::CopyBigWordLeft,
|
||||||
|
"copywordright" => EditCommand::CopyWordRight,
|
||||||
|
"copybigwordright" => EditCommand::CopyBigWordRight,
|
||||||
|
"copywordrighttonext" => EditCommand::CopyWordRightToNext,
|
||||||
|
"copybigwordrighttonext" => EditCommand::CopyBigWordRightToNext,
|
||||||
|
"copyleft" => EditCommand::CopyLeft,
|
||||||
|
"copyright" => EditCommand::CopyRight,
|
||||||
|
"copyrightuntil" => {
|
||||||
|
let value = extract_value("value", record, span)?;
|
||||||
|
let char = extract_char(value)?;
|
||||||
|
EditCommand::CopyRightUntil(char)
|
||||||
|
}
|
||||||
|
"copyrightbefore" => {
|
||||||
|
let value = extract_value("value", record, span)?;
|
||||||
|
let char = extract_char(value)?;
|
||||||
|
EditCommand::CopyRightBefore(char)
|
||||||
|
}
|
||||||
|
"copyleftuntil" => {
|
||||||
|
let value = extract_value("value", record, span)?;
|
||||||
|
let char = extract_char(value)?;
|
||||||
|
EditCommand::CopyLeftUntil(char)
|
||||||
|
}
|
||||||
|
"copyleftbefore" => {
|
||||||
|
let value = extract_value("value", record, span)?;
|
||||||
|
let char = extract_char(value)?;
|
||||||
|
EditCommand::CopyLeftBefore(char)
|
||||||
|
}
|
||||||
|
"swapcursorandanchor" => EditCommand::SwapCursorAndAnchor,
|
||||||
#[cfg(feature = "system-clipboard")]
|
#[cfg(feature = "system-clipboard")]
|
||||||
"cutselectionsystem" => EditCommand::CutSelectionSystem,
|
"cutselectionsystem" => EditCommand::CutSelectionSystem,
|
||||||
"copyselection" => EditCommand::CopySelection,
|
|
||||||
#[cfg(feature = "system-clipboard")]
|
#[cfg(feature = "system-clipboard")]
|
||||||
"copyselectionsystem" => EditCommand::CopySelectionSystem,
|
"copyselectionsystem" => EditCommand::CopySelectionSystem,
|
||||||
"paste" => EditCommand::Paste,
|
|
||||||
#[cfg(feature = "system-clipboard")]
|
#[cfg(feature = "system-clipboard")]
|
||||||
"pastesystem" => EditCommand::PasteSystem,
|
"pastesystem" => EditCommand::PasteSystem,
|
||||||
"selectall" => EditCommand::SelectAll,
|
"cutinside" => {
|
||||||
|
let value = extract_value("left", record, span)?;
|
||||||
|
let left = extract_char(value)?;
|
||||||
|
let value = extract_value("right", record, span)?;
|
||||||
|
let right = extract_char(value)?;
|
||||||
|
EditCommand::CutInside { left, right }
|
||||||
|
}
|
||||||
|
"yankinside" => {
|
||||||
|
let value = extract_value("left", record, span)?;
|
||||||
|
let left = extract_char(value)?;
|
||||||
|
let value = extract_value("right", record, span)?;
|
||||||
|
let right = extract_char(value)?;
|
||||||
|
EditCommand::YankInside { left, right }
|
||||||
|
}
|
||||||
str => {
|
str => {
|
||||||
return Err(ShellError::InvalidValue {
|
return Err(ShellError::InvalidValue {
|
||||||
valid: "a reedline EditCommand".into(),
|
valid: "a reedline EditCommand".into(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user