Skip to content

Commit f79f873

Browse files
committed
add key shortcut
1 parent 9aba6d3 commit f79f873

File tree

3 files changed

+80
-18
lines changed

3 files changed

+80
-18
lines changed

client/modules/IDE/components/Editor.jsx

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class Editor extends React.Component {
136136
}
137137
});
138138
this.hinter = new Fuse(hinter.p5Hinter, {
139-
threshold: 0.2,
139+
threshold: 0.05,
140140
keys: ['text']
141141
});
142142

@@ -345,19 +345,62 @@ class Editor extends React.Component {
345345
}
346346

347347
showHint(_cm) {
348+
let focusedLinkElement = null;
349+
const setFocusedLinkElement = (set) => {
350+
if (set && !focusedLinkElement) {
351+
const activeItemLink = document.querySelector(
352+
`.CodeMirror-hint-active a`
353+
);
354+
if (activeItemLink) {
355+
focusedLinkElement = activeItemLink;
356+
focusedLinkElement.classList.add('focused-hint-link');
357+
focusedLinkElement.parentElement.parentElement.classList.add(
358+
'unfocused'
359+
);
360+
}
361+
}
362+
};
363+
const removeFocusedLinkElement = () => {
364+
if (focusedLinkElement) {
365+
focusedLinkElement.classList.remove('focused-hint-link');
366+
focusedLinkElement.parentElement.parentElement.classList.remove(
367+
'unfocused'
368+
);
369+
focusedLinkElement = null;
370+
return true;
371+
}
372+
return false;
373+
};
374+
348375
const hintOptions = {
349376
_fontSize: this.props.fontSize,
350377
completeSingle: false,
351378
extraKeys: {
352-
Tab: (cm, e) => {
353-
const activeItem = document.querySelector(
379+
'Shift-Right': (cm, e) => {
380+
const activeItemLink = document.querySelector(
354381
`.CodeMirror-hint-active a`
355382
);
356-
if (activeItem) {
357-
activeItem.focus();
358-
} else {
359-
e.pick();
360-
}
383+
if (activeItemLink) activeItemLink.click();
384+
},
385+
Right: (cm, e) => {
386+
setFocusedLinkElement(true);
387+
},
388+
Left: (cm, e) => {
389+
removeFocusedLinkElement();
390+
},
391+
Up: (cm, e) => {
392+
const onLink = removeFocusedLinkElement();
393+
e.moveFocus(-1);
394+
setFocusedLinkElement(onLink);
395+
},
396+
Down: (cm, e) => {
397+
const onLink = removeFocusedLinkElement();
398+
e.moveFocus(1);
399+
setFocusedLinkElement(onLink);
400+
},
401+
Enter: (cm, e) => {
402+
if (focusedLinkElement) focusedLinkElement.click();
403+
else e.pick();
361404
}
362405
},
363406
closeOnUnfocus: false

client/styles/abstracts/_variables.scss

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ $themes: (
125125
hint-var-text-color: #D52889,
126126
hint-type-text-color: $middle-dark,
127127
hint-arrow-color: $lightest,
128-
hint-arrow-background-color: $p5js-pink,
128+
hint-arrow-background-color: #ed225dcc,
129+
hint-arrow-background-active-color: $p5js-pink,
130+
hint-arrow-focus-outline-color: #cfcfcf,
129131
hint-item-hover-background-color: #f4f4f4,
130132
hint-item-active-text-color: unset,
131133
hint-item-active-background-color: #cfcfcf,
@@ -220,11 +222,13 @@ $themes: (
220222
hint-var-text-color: #DE4A9B,
221223
hint-type-text-color: #E0D7D1,
222224
hint-arrow-color: #FDFDFD,
223-
hint-arrow-background-color: $p5js-pink,
225+
hint-arrow-background-color: #ed225dcc,
226+
hint-arrow-background-active-color: $p5js-pink,
227+
hint-arrow-focus-outline-color: #cfcfcf,
224228
hint-item-hover-background-color: $middle-dark,
225229
hint-item-active-text-color: $darker,
226230
hint-item-active-background-color: #cfcfcf,
227-
hint-item-active-type-text-color: $middle-dark,
231+
hint-item-active-type-text-color: $darker,
228232
hint-item-active-outline: none,
229233
hint-item-active-outline-offset: 0
230234
),
@@ -315,7 +319,9 @@ $themes: (
315319
hint-var-text-color: #FFA9D9,
316320
hint-type-text-color: #c1c1c1,
317321
hint-arrow-color: #333,
318-
hint-arrow-background-color: #F5DC23,
322+
hint-arrow-background-color: #F5DC23CC,
323+
hint-arrow-background-active-color: #F5DC23,
324+
hint-arrow-focus-outline-color: #FDFDFD,
319325
hint-item-hover-background-color: #454545,
320326
hint-item-active-text-color: #FDFDFD,
321327
hint-item-active-background-color: unset,

client/styles/components/_hints.scss

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
a {
4343
color: getThemifyVariable('hint-arrow-color');
4444
background: getThemifyVariable('hint-arrow-background-color');
45+
46+
&:hover, &:active {
47+
background: getThemifyVariable('hint-arrow-background-active-color');
48+
}
49+
50+
&.focused-hint-link {
51+
outline: 2px solid getThemifyVariable('hint-arrow-focus-outline-color');
52+
outline-offset: -2px;
53+
}
4554
}
4655

4756
li.CodeMirror-hint-active {
@@ -51,7 +60,16 @@
5160
outline-offset: getThemifyVariable('hint-item-active-outline-offset');
5261

5362
.hint-type {
54-
color: getThemifyVariable('hint-item-active-type-text-color:');
63+
color: getThemifyVariable('hint-item-active-type-text-color');
64+
}
65+
66+
&.unfocused {
67+
background: getThemifyVariable('hint-background-color') !important;
68+
outline: unset !important;
69+
70+
.hint-type {
71+
color: getThemifyVariable('hint-type-text-color') !important;
72+
}
5573
}
5674
}
5775

@@ -92,17 +110,12 @@
92110
margin: 0;
93111
padding-top: 0.4rem;
94112
text-align: center;
95-
opacity: 0.75;
96113
outline: none;
97114
z-index: 1;
98115
}
99116

100117
a:focus, a:active {
101118
outline: 0;
102119
}
103-
104-
a:hover, a:active {
105-
opacity: 1;
106-
}
107120
}
108121
}

0 commit comments

Comments
 (0)