Skip to content

Commit fe8cf0d

Browse files
authored
some quality patches (#1201)
1 parent 9c06c59 commit fe8cf0d

File tree

2 files changed

+20
-34
lines changed

2 files changed

+20
-34
lines changed

src/components/palette/index.js

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,9 @@ This shows that using keyboardHideStart event is faster than not using it.
4545
* @param {()=>string} onsSelectCb Callback to call when a hint is selected
4646
* @param {string} placeholder Placeholder for input
4747
* @param {function} onremove Callback to call when palette is removed
48-
* @param {function} onHighlight Callback to call when hint is highlighted
4948
* @returns {void}
5049
*/
51-
export default function palette(
52-
getList,
53-
onsSelectCb,
54-
placeholder,
55-
onremove,
56-
onHighlight,
57-
) {
58-
let isRemoving = false;
59-
50+
export default function palette(getList, onsSelectCb, placeholder, onremove) {
6051
/**@type {HTMLInputElement} */
6152
const $input = (
6253
<input
@@ -72,16 +63,16 @@ export default function palette(
7263
const $palette = <div id="palette">{$input}</div>;
7364

7465
// Create a palette with input and hints
75-
inputhints($input, generateHints, onSelect, onHighlight);
66+
inputhints($input, generateHints, onSelect);
7667

7768
// Removes the darkened color from status bar and navigation bar
7869
restoreTheme(true);
7970

8071
// Remove palette when input is blurred
81-
$input.addEventListener("blur", handleBlur);
72+
$input.addEventListener("blur", remove);
8273
// Don't wait for input to blur when keyboard hides, remove is
8374
// as soon as keyboard starts to hide
84-
keyboardHandler.on("keyboardHideStart", handleKeyboardHide);
75+
keyboardHandler.on("keyboardHideStart", remove);
8576

8677
// Add to DOM
8778
app.append($palette, $mask);
@@ -100,25 +91,12 @@ export default function palette(
10091
* @param {string} value
10192
*/
10293
function onSelect(value) {
103-
isRemoving = true;
10494
remove();
10595
setTimeout(() => {
10696
onsSelectCb(value);
10797
}, 0);
10898
}
10999

110-
function handleBlur() {
111-
if (!isRemoving) {
112-
remove();
113-
}
114-
}
115-
116-
function handleKeyboardHide() {
117-
if (!isRemoving) {
118-
remove();
119-
}
120-
}
121-
122100
/**
123101
* Keydown event handler for input
124102
* @param {KeyboardEvent} e
@@ -143,12 +121,9 @@ export default function palette(
143121
* Removes the palette
144122
*/
145123
function remove() {
146-
if (isRemoving) return;
147-
isRemoving = true;
148-
149124
actionStack.remove("palette");
150-
keyboardHandler.off("keyboardHideStart", handleKeyboardHide);
151-
$input.removeEventListener("blur", handleBlur);
125+
keyboardHandler.off("keyboardHideStart", remove);
126+
$input.removeEventListener("blur", remove);
152127

153128
restoreTheme();
154129
$palette.remove();
@@ -160,8 +135,12 @@ export default function palette(
160135
}
161136

162137
const { activeFile, editor } = editorManager;
163-
if (activeFile?.wasFocused) {
138+
if (activeFile.wasFocused) {
164139
editor.focus();
165140
}
141+
142+
remove = () => {
143+
window.log("warn", "Palette already removed.");
144+
};
166145
}
167146
}

src/pages/plugin/plugin.view.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export default (props) => {
1818
author,
1919
downloads,
2020
license,
21-
keywords,
22-
contributors,
2321
changelogs,
22+
keywords: keywordsRaw,
23+
contributors: contributorsRaw,
2424
votes_up: votesUp,
2525
votes_down: votesDown,
2626
author_verified: authorVerified,
@@ -30,6 +30,13 @@ export default (props) => {
3030

3131
let rating = "unrated";
3232

33+
const keywords =
34+
typeof keywordsRaw === "string" ? JSON.parse(keywordsRaw) : keywordsRaw;
35+
const contributors =
36+
typeof contributorsRaw === "string"
37+
? JSON.parse(contributorsRaw)
38+
: contributorsRaw;
39+
3340
if (votesUp || votesDown) {
3441
rating = `${Math.round((votesUp / (votesUp + votesDown)) * 100)}%`;
3542
}

0 commit comments

Comments
 (0)