Skip to content

Commit c17f6d7

Browse files
authored
update reedline to the latest commit (nushell#16791)
This PR updates nushell to the latest reedline commit 32e82c27. Notes from @JonLD regarding reedline's new `TextObject`, reedline change author of nushell/reedline#939 and nushell/reedline#957 and nushell#16808 Since EditCommand contains a TextObject and not a string it is not possible for the user to directly there needs to be a bit of work done to construct the relevant text object. Maintains the edit command names, seen under "keybindings list", of CutTextObject and CopyTextObject and using scope: <inner|around> and the object_type: mirrors the Reedline implementation and the informative error messages should help signal to users what are valid inputs. Ideally the "keybindings list" would be a bit mor informative as to how to set up specific keybindings but that's not currently possible, and perhaps not even necessary. The alternative would be to set up edit commands for each text object, this would be a larger Reedline change and add unecessary complexity to Reedline but would expose the commands better to the use. You could just add them in this file and keep Reedline as is but that would not be exposed to the user via "keybindings list" as this command lists the actual enums and not commands set up in the reedline_config.rs. ## Release notes summary - What our users need to know Breaking change since the reedline change renames `cutinside` and `yankinside`. The PR adds these new EditCommands: - cutinsidepair - copyinsidepair - cutaroundpair - copyaroundpair - cuttextobject - copytextobject ## Tasks after submitting N/A
1 parent b4038fe commit c17f6d7

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/nu-cli/src/reedline_config.rs

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use nu_protocol::{
1313
};
1414
use reedline::{
1515
ColumnarMenu, DescriptionMenu, DescriptionMode, EditCommand, IdeMenu, Keybindings, ListMenu,
16-
MenuBuilder, Reedline, ReedlineEvent, ReedlineMenu, TraversalDirection,
17-
default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings,
16+
MenuBuilder, Reedline, ReedlineEvent, ReedlineMenu, TextObject, TextObjectScope,
17+
TextObjectType, TraversalDirection, default_emacs_keybindings, default_vi_insert_keybindings,
18+
default_vi_normal_keybindings,
1819
};
1920
use std::sync::Arc;
2021

@@ -1307,20 +1308,40 @@ fn edit_from_record(
13071308
"copyselectionsystem" => EditCommand::CopySelectionSystem,
13081309
#[cfg(feature = "system-clipboard")]
13091310
"pastesystem" => EditCommand::PasteSystem,
1310-
"cutinside" => {
1311+
"cutinsidepair" => {
13111312
let value = extract_value("left", record, span)?;
13121313
let left = extract_char(value)?;
13131314
let value = extract_value("right", record, span)?;
13141315
let right = extract_char(value)?;
1315-
EditCommand::CutInside { left, right }
1316+
EditCommand::CutInsidePair { left, right }
13161317
}
1317-
"yankinside" => {
1318+
"copyinsidepair" => {
13181319
let value = extract_value("left", record, span)?;
13191320
let left = extract_char(value)?;
13201321
let value = extract_value("right", record, span)?;
13211322
let right = extract_char(value)?;
1322-
EditCommand::YankInside { left, right }
1323+
EditCommand::CopyInsidePair { left, right }
13231324
}
1325+
"cutaroundpair" => {
1326+
let value = extract_value("left", record, span)?;
1327+
let left = extract_char(value)?;
1328+
let value = extract_value("right", record, span)?;
1329+
let right = extract_char(value)?;
1330+
EditCommand::CutAroundPair { left, right }
1331+
}
1332+
"copyaroundpair" => {
1333+
let value = extract_value("left", record, span)?;
1334+
let left = extract_char(value)?;
1335+
let value = extract_value("right", record, span)?;
1336+
let right = extract_char(value)?;
1337+
EditCommand::CopyAroundPair { left, right }
1338+
}
1339+
"copytextobject" => EditCommand::CopyTextObject {
1340+
text_object: parse_text_object(record, config, span)?,
1341+
},
1342+
"cuttextobject" => EditCommand::CutTextObject {
1343+
text_object: parse_text_object(record, config, span)?,
1344+
},
13241345
str => {
13251346
return Err(ShellError::InvalidValue {
13261347
valid: "a reedline EditCommand".into(),
@@ -1353,6 +1374,48 @@ fn extract_char(value: &Value) -> Result<char, ShellError> {
13531374
}
13541375
}
13551376

1377+
fn parse_text_object(
1378+
record: &Record,
1379+
config: &Config,
1380+
span: Span,
1381+
) -> Result<TextObject, ShellError> {
1382+
let scope_value = extract_value("scope", record, span)?;
1383+
let scope_str = scope_value
1384+
.to_expanded_string("", config)
1385+
.to_ascii_lowercase();
1386+
let scope = match scope_str.as_str() {
1387+
"inner" => TextObjectScope::Inner,
1388+
"around" => TextObjectScope::Around,
1389+
str => {
1390+
return Err(ShellError::InvalidValue {
1391+
valid: "'inner' or 'around'".into(),
1392+
actual: format!("'{str}'"),
1393+
span: scope_value.span(),
1394+
});
1395+
}
1396+
};
1397+
1398+
let type_value = extract_value("object_type", record, span)?;
1399+
let type_str = type_value
1400+
.to_expanded_string("", config)
1401+
.to_ascii_lowercase();
1402+
let object_type = match type_str.as_str() {
1403+
"word" => TextObjectType::Word,
1404+
"bigword" => TextObjectType::BigWord,
1405+
"brackets" | "bracket" => TextObjectType::Brackets,
1406+
"quote" | "quotes" => TextObjectType::Quote,
1407+
str => {
1408+
return Err(ShellError::InvalidValue {
1409+
valid: "'word', 'bigword', 'brackets', or 'quote'".into(),
1410+
actual: format!("'{str}'"),
1411+
span: type_value.span(),
1412+
});
1413+
}
1414+
};
1415+
1416+
Ok(TextObject { scope, object_type })
1417+
}
1418+
13561419
#[cfg(test)]
13571420
mod test {
13581421
use super::*;

0 commit comments

Comments
 (0)