Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dorota Czaplejewicz
squeekboard
Commits
de3bf54d
Commit
de3bf54d
authored
Sep 28, 2020
by
Dorota Czaplejewicz
Browse files
data: Restore testability of action->keysym conversion
parent
2219eb67
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/data.rs
View file @
de3bf54d
...
...
@@ -383,17 +383,7 @@ impl Layout {
)})
.collect
();
let
symbolmap
:
HashMap
<
String
,
u32
>
=
generate_keycodes
(
button_actions
.iter
()
.filter_map
(|(
_name
,
action
)|
{
match
action
{
::
action
::
Action
::
Submit
{
text
:
_
,
keys
,
}
=>
Some
(
keys
),
_
=>
None
,
}
})
.flatten
()
.map
(|
named_keysym
|
named_keysym
.0
.as_str
())
extract_symbol_names
(
&
button_actions
)
);
let
button_states
=
button_actions
.into_iter
()
.map
(|(
name
,
action
)|
{
...
...
@@ -733,6 +723,22 @@ fn create_button<H: logging::Handler>(
}
}
fn
extract_symbol_names
<
'a
>
(
actions
:
&
'a
[(
&
str
,
action
::
Action
)])
->
impl
Iterator
<
Item
=&
'a
str
>
{
actions
.iter
()
.filter_map
(|(
_name
,
act
)|
{
match
act
{
action
::
Action
::
Submit
{
text
:
_
,
keys
,
}
=>
Some
(
keys
),
_
=>
None
,
}
})
.flatten
()
.map
(|
named_keysym
|
named_keysym
.0
.as_str
())
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
...
...
@@ -861,6 +867,23 @@ mod tests {
);
}
/// Test if erase yields a useable keycode
#[test]
fn
test_layout_erase
()
{
let
out
=
Layout
::
from_file
(
path_from_root
(
"tests/layout_erase.yaml"
))
.unwrap
()
.build
(
ProblemPanic
)
.0
.unwrap
();
assert_eq!
(
out
.views
[
"base"
]
.1
.get_rows
()[
0
]
.1
.buttons
[
0
]
.1
.state
.borrow
()
.keycodes
.len
(),
1
);
}
#[test]
fn
parsing_fallback
()
{
assert!
(
Layout
::
from_resource
(
FALLBACK_LAYOUT_NAME
)
...
...
@@ -938,4 +961,35 @@ mod tests {
}
);
}
#[test]
fn
test_extract_symbols
()
{
let
actions
=
[(
"ac"
,
action
::
Action
::
Submit
{
text
:
None
,
keys
:
vec!
[
action
::
KeySym
(
"a"
.into
()),
action
::
KeySym
(
"c"
.into
()),
],
},
)];
assert_eq!
(
extract_symbol_names
(
&
actions
[
..
])
.collect
::
<
Vec
<
_
>>
(),
vec!
[
"a"
,
"c"
],
);
}
#[test]
fn
test_extract_symbols_erase
()
{
let
actions
=
[(
"Erase"
,
action
::
Action
::
Erase
,
)];
assert_eq!
(
extract_symbol_names
(
&
actions
[
..
])
.collect
::
<
Vec
<
_
>>
(),
Vec
::
<&
str
>
::
new
(),
//"BackSpace"], // TODO: centralize handling of BackSpace
);
}
}
src/keyboard.rs
View file @
de3bf54d
...
...
@@ -91,7 +91,7 @@ fn sorted<'a, I: Iterator<Item=&'a str>>(
/// HACK: starting from 9, because 8 results in keycode 0,
/// which the compositor likes to discard
pub
fn
generate_keycodes
<
'a
,
C
:
IntoIterator
<
Item
=&
'a
str
>>
(
key_names
:
C
key_names
:
C
,
)
->
HashMap
<
String
,
u32
>
{
let
special_keysyms
=
[
"BackSpace"
,
"Return"
]
.iter
()
.map
(|
&
s
|
s
);
HashMap
::
from_iter
(
...
...
tests/layout_erase.yaml
0 → 100644
View file @
de3bf54d
---
# Erase only
views
:
base
:
-
"
BackSpace"
outlines
:
default
:
{
width
:
0
,
height
:
0
}
buttons
:
BackSpace
:
action
:
erase
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment