Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some quality patches #1201

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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