aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2022-05-04 11:27:42 +0000
committerShin'ya Ueoka <ueokande@i-beam.org>2022-05-05 07:27:42 +0000
commit823bad63384de90c11653f0afa253cc5d0e19239 (patch)
tree8c4af9c3cdf74d32264d693f081266b650fede03
parent65ddd365e407989f3c1722a3ba811492b32e692f (diff)
Rename completion fields
-rw-r--r--src/console/Completions.ts6
-rw-r--r--src/console/completion/hooks.ts50
-rw-r--r--src/console/components/console/Completion.tsx8
-rw-r--r--src/console/components/console/CompletionItem.tsx14
-rw-r--r--test/console/components/console/Completion.test.tsx14
-rw-r--r--test/console/components/console/CompletionItem.test.tsx4
6 files changed, 48 insertions, 48 deletions
diff --git a/src/console/Completions.ts b/src/console/Completions.ts
index a18f160..b04e480 100644
--- a/src/console/Completions.ts
+++ b/src/console/Completions.ts
@@ -1,9 +1,9 @@
type Completions = {
readonly name: string;
readonly items: {
- readonly caption?: string;
- readonly content?: string;
- readonly url?: string;
+ readonly primary?: string;
+ readonly secondary?: string;
+ readonly value?: string;
readonly icon?: string;
}[];
}[];
diff --git a/src/console/completion/hooks.ts b/src/console/completion/hooks.ts
index 4402b70..ad315e6 100644
--- a/src/console/completion/hooks.ts
+++ b/src/console/completion/hooks.ts
@@ -74,9 +74,9 @@ const getCommandCompletions = async (query: string): Promise<Completions> => {
const items = Object.entries(commandDocs)
.filter(([name]) => name.startsWith(query))
.map(([name, doc]) => ({
- caption: name,
- content: name,
- url: doc,
+ primary: name,
+ secondary: doc,
+ value: name,
}));
return [
{
@@ -102,8 +102,8 @@ const getOpenCompletions = async (
completions.push({
name: "Search Engines",
items: items.map((key) => ({
- caption: key.title,
- content: command + " " + key.title,
+ primary: key.title,
+ value: command + " " + key.title,
})),
});
break;
@@ -116,9 +116,9 @@ const getOpenCompletions = async (
completions.push({
name: "History",
items: items.map((item) => ({
- caption: item.title,
- content: command + " " + item.url,
- url: item.url,
+ primary: item.title,
+ secondary: item.url,
+ value: command + " " + item.url,
})),
});
break;
@@ -131,9 +131,9 @@ const getOpenCompletions = async (
completions.push({
name: "Bookmarks",
items: items.map((item) => ({
- caption: item.title,
- content: command + " " + item.url,
- url: item.url,
+ primary: item.title,
+ secondary: item.url,
+ value: command + " " + item.url,
})),
});
break;
@@ -157,11 +157,11 @@ export const getTabCompletions = async (
{
name: "Buffers",
items: items.map((item) => ({
- content: command + " " + item.url,
- caption: `${item.index}: ${
+ primary: `${item.index}: ${
item.flag != TabFlag.None ? item.flag : " "
} ${item.title}`,
- url: item.url,
+ secondary: item.url,
+ value: command + " " + item.url,
icon: item.faviconUrl,
})),
},
@@ -179,28 +179,28 @@ export const getPropertyCompletions = async (
if (item.type === "boolean") {
return [
{
- caption: item.name,
- content: command + " " + item.name,
- url: "Enable " + desc,
+ primary: item.name,
+ secondary: "Enable " + desc,
+ value: command + " " + item.name,
},
{
- caption: "no" + item.name,
- content: command + " no" + item.name,
- url: "Disable " + desc,
+ primary: "no" + item.name,
+ secondary: "Disable " + desc,
+ value: command + " no" + item.name,
},
];
} else {
return [
{
- caption: item.name,
- content: command + " " + item.name,
- url: "Set " + desc,
+ primary: item.name,
+ secondary: "Set " + desc,
+ value: command + " " + item.name,
},
];
}
})
.reduce((acc, val) => acc.concat(val), [])
- .filter((item) => item.caption.startsWith(query));
+ .filter((item) => item.primary.startsWith(query));
return [{ name: "Properties", items }];
};
@@ -308,7 +308,7 @@ export const useSelectCompletion = () => {
return state.completionSource;
}
const items = state.completions.map((g) => g.items).flat();
- return items[state.select]?.content || "";
+ return items[state.select]?.value || "";
}, [state.completionSource, state.select]);
return {
diff --git a/src/console/components/console/Completion.tsx b/src/console/components/console/Completion.tsx
index ed271aa..6a58a40 100644
--- a/src/console/components/console/Completion.tsx
+++ b/src/console/components/console/Completion.tsx
@@ -4,8 +4,8 @@ import CompletionTitle from "./CompletionTitle";
interface Item {
icon?: string;
- caption?: string;
- url?: string;
+ primary?: string;
+ secondary?: string;
}
interface Group {
@@ -75,8 +75,8 @@ const Completion: React.FC<Props> = ({ select, size, completions }) => {
shown={viewOffset <= viewIndex && viewIndex < viewOffset + size}
key={`item-${itemIndex}`}
icon={item.icon}
- caption={item.caption}
- url={item.url}
+ primary={item.primary}
+ secondary={item.secondary}
highlight={itemIndex === select}
aria-selected={itemIndex === select}
role="menuitem"
diff --git a/src/console/components/console/CompletionItem.tsx b/src/console/components/console/CompletionItem.tsx
index 2de1375..394af04 100644
--- a/src/console/components/console/CompletionItem.tsx
+++ b/src/console/components/console/CompletionItem.tsx
@@ -23,14 +23,14 @@ const Container = styled.li<{
white-space: pre;
`;
-const Caption = styled.span`
+const Primary = styled.span`
display: inline-block;
width: 40%;
text-overflow: ellipsis;
overflow: hidden;
`;
-const Description = styled.span`
+const Secondary = styled.span`
display: inline-block;
color: ${({ theme }) => theme.completionItemDescriptionForeground};
width: 60%;
@@ -41,19 +41,19 @@ const Description = styled.span`
interface Props extends React.HTMLAttributes<HTMLElement> {
shown: boolean;
highlight: boolean;
- caption?: string;
- url?: string;
+ primary?: string;
+ secondary?: string;
icon?: string;
}
const CompletionItem: React.FC<Props> = (props) => (
<Container
icon={props.icon || ""}
- aria-labelledby={`completion-item-${props.caption}`}
+ aria-labelledby={`completion-item-${props.primary}`}
{...props}
>
- <Caption id={`completion-item-${props.caption}`}>{props.caption}</Caption>
- <Description>{props.url}</Description>
+ <Primary id={`completion-item-${props.primary}`}>{props.primary}</Primary>
+ <Secondary>{props.secondary}</Secondary>
</Container>
);
diff --git a/test/console/components/console/Completion.test.tsx b/test/console/components/console/Completion.test.tsx
index 7dd634f..dee0e80 100644
--- a/test/console/components/console/Completion.test.tsx
+++ b/test/console/components/console/Completion.test.tsx
@@ -9,17 +9,17 @@ describe("console/components/console/completion/Completion", () => {
{
name: "Fruit",
items: [
- { caption: "apple" },
- { caption: "banana" },
- { caption: "cherry" },
+ { primary: "apple" },
+ { primary: "banana" },
+ { primary: "cherry" },
],
},
{
name: "Element",
items: [
- { caption: "argon" },
- { caption: "boron" },
- { caption: "carbon" },
+ { primary: "argon" },
+ { primary: "boron" },
+ { primary: "carbon" },
],
},
];
@@ -39,7 +39,7 @@ describe("console/components/console/completion/Completion", () => {
const items = group.findAllByType(CompletionItem);
expect(items).toHaveLength(completions[i].items.length);
items.forEach((item, j) => {
- expect(item.props.caption).toEqual(completions[i].items[j].caption);
+ expect(item.props.primary).toEqual(completions[i].items[j].primary);
});
});
});
diff --git a/test/console/components/console/CompletionItem.test.tsx b/test/console/components/console/CompletionItem.test.tsx
index ae73b21..6e89bc8 100644
--- a/test/console/components/console/CompletionItem.test.tsx
+++ b/test/console/components/console/CompletionItem.test.tsx
@@ -8,8 +8,8 @@ describe("console/components/console/completion/CompletionItem", () => {
<CompletionItem
shown={true}
highlight={false}
- caption="twitter"
- url="https://twitter.com/"
+ primary="twitter"
+ secondary="https://twitter.com/"
/>
).root;
const spans = root.findAllByType("span");