mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 13:21:38 +03:00
wezterm: allow using {}
(an empty table) to represent None in lua
`wezterm.action{ExtendSelectionToMouseCursor=nil}` doesn't produce an `ExtendSelectionToMouseCursor(None)` value because a table value of `nil` is equivalent to that key not being present and lua sees just an empty table. Instead we need to accept `ExtendSelectionToMouseCursor={}` a valid way to indicate an `Option::None` which is what this commit does. Due to weirdness that I haven't had a chance to run down, passing that value through `wezterm.action` doesn't produce the intended value, so I'm adjusting the docs to show to specify an alternative syntax for this as part of this commit. refs: https://github.com/wez/wezterm/issues/282
This commit is contained in:
parent
85dddc0ef1
commit
957cc592a6
@ -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
|
||||
|
@ -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::<String, Value>();
|
||||
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<MyEnum>),
|
||||
};
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user