Add ability to configure copy mode

This commit is contained in:
2026-06-29 20:34:59 +02:00
parent 9d4406ee54
commit 6e5e40e111
2 changed files with 42 additions and 6 deletions
+14 -1
View File
@@ -18,7 +18,20 @@
"mode": "view" "mode": "view"
} }
], ],
"preferences": [], "preferences": [
{
"name": "copyFormat",
"title": "Copy Format",
"description": "What to copy to the clipboard when selecting a gitmoji.",
"required": false,
"type": "dropdown",
"data": [
{ "title": "Unicode Emoji", "value": "emoji" },
{ "title": "Gitmoji Code", "value": "code" }
],
"default": "emoji"
}
],
"scripts": { "scripts": {
"build": "vici build", "build": "vici build",
"dev": "vici develop", "dev": "vici develop",
+28 -5
View File
@@ -1,5 +1,12 @@
import gitmojisData from "./gitmojis.json"; import gitmojisData from "./gitmojis.json";
import { Action, ActionPanel, List, showToast, Toast } from "@vicinae/api"; import {
Action,
ActionPanel,
List,
showToast,
Toast,
getPreferenceValues,
} from "@vicinae/api";
type Gitmoji = { type Gitmoji = {
emoji: string; emoji: string;
@@ -9,9 +16,25 @@ type Gitmoji = {
name: string; name: string;
}; };
type CopyFormat = "emoji" | "code";
type GitmojiPreferences = {
copyFormat?: CopyFormat;
};
const gitmojis = gitmojisData.gitmojis as Gitmoji[]; const gitmojis = gitmojisData.gitmojis as Gitmoji[];
const labelFor = (format: CopyFormat) => (format === "code" ? "Code" : "Emoji");
const contentFor = (gitmoji: Gitmoji, format: CopyFormat) =>
format === "code" ? gitmoji.code : gitmoji.emoji;
export default function GitmojiList() { export default function GitmojiList() {
const { copyFormat } = getPreferenceValues<GitmojiPreferences>();
const primaryFormat: CopyFormat = copyFormat === "code" ? "code" : "emoji";
const secondaryFormat: CopyFormat =
primaryFormat === "code" ? "emoji" : "code";
return ( return (
<List searchBarPlaceholder="Search gitmojis..."> <List searchBarPlaceholder="Search gitmojis...">
{gitmojis.map((gitmoji) => ( {gitmojis.map((gitmoji) => (
@@ -25,8 +48,8 @@ export default function GitmojiList() {
actions={ actions={
<ActionPanel> <ActionPanel>
<Action.CopyToClipboard <Action.CopyToClipboard
title="Copy Emoji" title={`Copy ${labelFor(primaryFormat)}`}
content={gitmoji.emoji} content={contentFor(gitmoji, primaryFormat)}
onCopy={(content) => onCopy={(content) =>
showToast( showToast(
Toast.Style.Success, Toast.Style.Success,
@@ -36,8 +59,8 @@ export default function GitmojiList() {
} }
/> />
<Action.CopyToClipboard <Action.CopyToClipboard
title="Copy Code" title={`Copy ${labelFor(secondaryFormat)}`}
content={gitmoji.code} content={contentFor(gitmoji, secondaryFormat)}
/> />
</ActionPanel> </ActionPanel>
} }