Skip to content

Commit

Permalink
some quality patches (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
bajrangCoder authored Feb 25, 2025
1 parent 9c06c59 commit fe8cf0d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 34 deletions.
43 changes: 11 additions & 32 deletions src/components/palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,9 @@ This shows that using keyboardHideStart event is faster than not using it.
* @param {()=>string} onsSelectCb Callback to call when a hint is selected
* @param {string} placeholder Placeholder for input
* @param {function} onremove Callback to call when palette is removed
* @param {function} onHighlight Callback to call when hint is highlighted
* @returns {void}
*/
export default function palette(
getList,
onsSelectCb,
placeholder,
onremove,
onHighlight,
) {
let isRemoving = false;

export default function palette(getList, onsSelectCb, placeholder, onremove) {
/**@type {HTMLInputElement} */
const $input = (
<input
Expand All @@ -72,16 +63,16 @@ export default function palette(
const $palette = <div id="palette">{$input}</div>;

// Create a palette with input and hints
inputhints($input, generateHints, onSelect, onHighlight);
inputhints($input, generateHints, onSelect);

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

// Remove palette when input is blurred
$input.addEventListener("blur", handleBlur);
$input.addEventListener("blur", remove);
// Don't wait for input to blur when keyboard hides, remove is
// as soon as keyboard starts to hide
keyboardHandler.on("keyboardHideStart", handleKeyboardHide);
keyboardHandler.on("keyboardHideStart", remove);

// Add to DOM
app.append($palette, $mask);
Expand All @@ -100,25 +91,12 @@ export default function palette(
* @param {string} value
*/
function onSelect(value) {
isRemoving = true;
remove();
setTimeout(() => {
onsSelectCb(value);
}, 0);
}

function handleBlur() {
if (!isRemoving) {
remove();
}
}

function handleKeyboardHide() {
if (!isRemoving) {
remove();
}
}

/**
* Keydown event handler for input
* @param {KeyboardEvent} e
Expand All @@ -143,12 +121,9 @@ export default function palette(
* Removes the palette
*/
function remove() {
if (isRemoving) return;
isRemoving = true;

actionStack.remove("palette");
keyboardHandler.off("keyboardHideStart", handleKeyboardHide);
$input.removeEventListener("blur", handleBlur);
keyboardHandler.off("keyboardHideStart", remove);
$input.removeEventListener("blur", remove);

restoreTheme();
$palette.remove();
Expand All @@ -160,8 +135,12 @@ export default function palette(
}

const { activeFile, editor } = editorManager;
if (activeFile?.wasFocused) {
if (activeFile.wasFocused) {
editor.focus();
}

remove = () => {
window.log("warn", "Palette already removed.");
};
}
}
11 changes: 9 additions & 2 deletions src/pages/plugin/plugin.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export default (props) => {
author,
downloads,
license,
keywords,
contributors,
changelogs,
keywords: keywordsRaw,
contributors: contributorsRaw,
votes_up: votesUp,
votes_down: votesDown,
author_verified: authorVerified,
Expand All @@ -30,6 +30,13 @@ export default (props) => {

let rating = "unrated";

const keywords =
typeof keywordsRaw === "string" ? JSON.parse(keywordsRaw) : keywordsRaw;
const contributors =
typeof contributorsRaw === "string"
? JSON.parse(contributorsRaw)
: contributorsRaw;

if (votesUp || votesDown) {
rating = `${Math.round((votesUp / (votesUp + votesDown)) * 100)}%`;
}
Expand Down

0 comments on commit fe8cf0d

Please sign in to comment.