diff --git a/docs/config/keys.markdown b/docs/config/keys.markdown index 7c313d67c..badd9c2cf 100644 --- a/docs/config/keys.markdown +++ b/docs/config/keys.markdown @@ -158,7 +158,7 @@ that order. | Triple Left Down | `NONE` | `SelectTextAtMouseCursor="Line"` | | Double Left Down | `NONE` | `SelectTextAtMouseCursor="Word"` | | Single Left Down | `NONE` | `SelectTextAtMouseCursor="Cell"` | -| Single Left Down | `SHIFT` | `ExtendSelectionToMouseCursor=nil` | +| Single Left Down | `SHIFT` | `ExtendSelectionToMouseCursor={}` | | Single Left Up | `NONE` | `CompleteSelectionOrOpenLinkAtMouseCursor` | | Double Left Up | `NONE` | `CompleteSelection` | | Triple Left Up | `NONE` | `CompleteSelection` | @@ -735,6 +735,25 @@ Extends the current text selection to the current mouse cursor position. The mode argument can be one of `Cell`, `Word` or `Line` to control the scope of the selection. +It is also possible to leave the mode unspecified like this: + +```lua +return { + mouse_bindings = { + { + event={Up={streak=1, button="Left"}}, + mods="SHIFT", + -- Note that there is no `wezterm.action` here + action=ExtendSelectionToMouseCursor={}, + }, + } +} +``` + +when unspecified, wezterm will use a default mode which at the time +of writing is `Cell`, but in a future release may be context sensitive +based on recent actions. + ## OpenLinkAtMouseCursor If the current mouse cursor position is over a cell that contains diff --git a/src/scripting/serde_lua/mod.rs b/src/scripting/serde_lua/mod.rs index e0a751b60..6b5875ee1 100644 --- a/src/scripting/serde_lua/mod.rs +++ b/src/scripting/serde_lua/mod.rs @@ -403,8 +403,16 @@ impl<'de, 'lua> Deserializer<'de> for ValueWrapper<'lua> { where V: Visitor<'de>, { - match self.0 { + match &self.0 { Value::Nil => v.visit_none(), + Value::Table(t) => { + let mut iter = t.clone().pairs::(); + if iter.next().is_none() { + v.visit_none() + } else { + v.visit_some(self) + } + } _ => v.visit_some(self), } } @@ -962,4 +970,26 @@ mod test { unknown variant `Invalid`, expected `Foo` or `Bar`", ); } + + #[test] + fn test_option_mode() { + #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] + enum MyEnum { + Foo, + Bar, + }; + #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] + enum AnotherEnum { + ThisOne(Option), + }; + + let lua = Lua::new(); + let res: AnotherEnum = + from_lua_value(lua.load("{ThisOne=\"Foo\"}").eval().unwrap()).unwrap(); + assert_eq!(res, AnotherEnum::ThisOne(Some(MyEnum::Foo))); + round_trip(res); + + let res: AnotherEnum = from_lua_value(lua.load("{ThisOne={}}").eval().unwrap()).unwrap(); + assert_eq!(res, AnotherEnum::ThisOne(None)); + } }