Skip to content

Commit b44fca3

Browse files
committed
FEAT: use default key event type when doing: make event! [key: #"A"]
related to: Oldes/Rebol-issues#1526
1 parent 38f5167 commit b44fca3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/core/t-event.c

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
case SYM_KEY:
134134
//VAL_EVENT_TYPE(value) != EVT_KEY && VAL_EVENT_TYPE(value) != EVT_KEY_UP)
135135
VAL_EVENT_MODEL(value) = EVM_GUI;
136+
if(!VAL_EVENT_TYPE(value)) VAL_EVENT_TYPE(value) = EVT_KEY;
136137
if (IS_CHAR(val)) {
137138
VAL_EVENT_DATA(value) = VAL_CHAR(val);
138139
CLR_FLAG(VAL_EVENT_FLAGS(value), EVF_HAS_XY);

src/tests/units/event-test.r3

+24
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,30 @@ Rebol [
2929
event? e: try [make event! [offset: 1x2]]
3030
e/offset = 1x2
3131
]
32+
--test-- "key event"
33+
;@@ https://github.com/Oldes/Rebol-issues/issues/1526
34+
--assert all [
35+
event? e: try [make event! [type: 'key key: #"A"]]
36+
e/key == #"A"
37+
none? e/offset
38+
]
39+
--assert all [
40+
event? e: try [make event! [key: #"B"]]
41+
e/key == #"B"
42+
e/type = 'key ; added automaticaly if no type is specified
43+
]
44+
--assert all [
45+
event? e: try [make event! [type: 'custom key: #"C"]]
46+
none? e/key ; only key and key-up types will provide it
47+
e/type = 'custom
48+
e/code = 67
49+
]
50+
--assert all [
51+
event? e: try [make event! [type: 'key-up key: #"C"]]
52+
e/key == #"C"
53+
e/type = 'key-up
54+
e/code = 67
55+
]
3256

3357
===end-group===
3458

0 commit comments

Comments
 (0)