Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parse) allow direct use of 1-"char" unicode symbols in layers #840

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,12 @@ will do nothing as opposed to typing a letter.
=== Unicode
<<table-of-contents,Back to ToC>>

The `+unicode+` (or `+πŸ”£+`) action accepts a single unicode character. The character will
not be repeatedly typed if you hold the key down.
The `+unicode+` (or `+πŸ”£+`) action accepts a single unicode character (but not
a composed character, so 🀲, but not 🀲🏿). The character will not be repeatedly
typed if you hold the key down.

You may use a unicode character as an alias if desired.
You may use a unicode character as an alias if desired or in its simplified form `+πŸ”£πŸ˜€+`
(vs the usual `+(πŸ”£ πŸ˜€)+`).

NOTE: The unicode action may not be correctly accepted by the active
application.
Expand All @@ -567,7 +569,7 @@ NOTE: If using Linux, make sure to look at the
πŸ™ (unicode πŸ™)
)
(deflayer has-happy-sad
@sml @πŸ™ @πŸ˜€ s d f
@sml @πŸ™ @πŸ˜€ πŸ”£πŸ˜€ d f
)
----

Expand Down
9 changes: 7 additions & 2 deletions parser/src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,12 @@ fn parse_action_atom(ac_span: &Spanned<String>, s: &ParsedState) -> Result<&'sta
),
};
}

if let Some(unisym) = ac.strip_prefix('πŸ”£') {
// TODO: when unicode accepts multiple chars, change this to feed the whole string, not just the first char
return Ok(s.a.sref(Action::Custom(s.a.sref(s.a.sref_slice(
CustomAction::Unicode(unisym.chars().next().expect("1 char")),
)))));
}
// Parse a sequence like `C-S-v` or `C-A-del`
let (mut keys, unparsed_str) = parse_mod_prefix(ac)?;
keys.push(
Expand Down Expand Up @@ -1817,7 +1822,7 @@ pub fn parse_mod_prefix(mods: &str) -> Result<(Vec<KeyCode>, &str)> {
}

fn parse_unicode(ac_params: &[SExpr], s: &ParsedState) -> Result<&'static KanataAction> {
const ERR_STR: &str = "unicode expects exactly one unicode character as an argument";
const ERR_STR: &str = "unicode expects exactly one (not combos looking like one) unicode character as an argument";
if ac_params.len() != 1 {
bail!(ERR_STR)
}
Expand Down
Loading