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"
}
],
"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": {
"build": "vici build",
"dev": "vici develop",
+28 -5
View File
@@ -1,5 +1,12 @@
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 = {
emoji: string;
@@ -9,9 +16,25 @@ type Gitmoji = {
name: string;
};
type CopyFormat = "emoji" | "code";
type GitmojiPreferences = {
copyFormat?: CopyFormat;
};
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() {
const { copyFormat } = getPreferenceValues<GitmojiPreferences>();
const primaryFormat: CopyFormat = copyFormat === "code" ? "code" : "emoji";
const secondaryFormat: CopyFormat =
primaryFormat === "code" ? "emoji" : "code";
return (
<List searchBarPlaceholder="Search gitmojis...">
{gitmojis.map((gitmoji) => (
@@ -25,8 +48,8 @@ export default function GitmojiList() {
actions={
<ActionPanel>
<Action.CopyToClipboard
title="Copy Emoji"
content={gitmoji.emoji}
title={`Copy ${labelFor(primaryFormat)}`}
content={contentFor(gitmoji, primaryFormat)}
onCopy={(content) =>
showToast(
Toast.Style.Success,
@@ -36,8 +59,8 @@ export default function GitmojiList() {
}
/>
<Action.CopyToClipboard
title="Copy Code"
content={gitmoji.code}
title={`Copy ${labelFor(secondaryFormat)}`}
content={contentFor(gitmoji, secondaryFormat)}
/>
</ActionPanel>
}