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

それっぽいdduのcolumnを追加 #74

Merged
merged 6 commits into from
Dec 22, 2023
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
53 changes: 53 additions & 0 deletions denops/@ddu-columns/channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { dduVim, dduVimColumn, fn } from "../traqvim/deps.ts";

export type Params = {
collapsedParentIcon: string;
expandedParentIcon: string;
leafIcon: string;
indentationWidth: number;
};

export class Column extends dduVim.BaseColumn<Params> {
getLength(
args: dduVimColumn.GetLengthArguments<Params>,
): Promise<number> {
const iconWidth = Math.max(
args.columnParams.collapsedParentIcon.length,
args.columnParams.expandedParentIcon.length,
args.columnParams.leafIcon.length,
);
const widths: number[] = args.items.map((item) => {
const length = args.columnParams.indentationWidth * item.__level +
iconWidth +
1 +
item.word.length;
return length;
});
return Promise.resolve(Math.max(...widths));
}
async getText(
args: dduVimColumn.GetTextArguments<Params>,
): Promise<dduVimColumn.GetTextResult> {
const parentIcon = args.item.__expanded
? args.columnParams.expandedParentIcon
: args.columnParams.collapsedParentIcon;
const isParent = args.item.isTree ?? false;
const icon = isParent ? parentIcon : args.columnParams.leafIcon;
const text =
" ".repeat(args.columnParams.indentationWidth * args.item.__level) +
icon + " " + args.item.word;
const width = await fn.strwidth(args.denops, text) as number;
const padding = " ".repeat(args.endCol - args.startCol - width);
return Promise.resolve({
text: text + padding,
});
}
params(): Params {
return {
collapsedParentIcon: "󱅿",
expandedParentIcon: "󰐤",
leafIcon: "󰐣",
indentationWidth: 2,
};
}
}
5 changes: 2 additions & 3 deletions denops/@ddu-sources/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Source extends dduVim.BaseSource<Params> {
});
parentChannels.forEach((channel: Channel) => {
items.push({
word: channel.path + (channel.children.length === 0 ? "" : "/"),
word: channel.name,
action: {
id: channel.id,
},
Expand All @@ -63,8 +63,7 @@ export class Source extends dduVim.BaseSource<Params> {
return;
}
items.push({
word: (childrenChannel.path.split("/").pop() ?? "") +
(childrenChannel.children.length === 0 ? "" : "/"),
word: childrenChannel.name,
action: {
id: childrenChannel.id,
},
Expand Down
1 change: 1 addition & 0 deletions denops/traqvim/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export * as ddcVim from "https://deno.land/x/ddc_vim@v3.4.0/types.ts";
export * as ddcVimSource from "https://deno.land/x/ddc_vim@v3.4.0/base/source.ts";
export * as dduVim from "https://deno.land/x/ddu_vim@v1.13.0/types.ts";
export * as dduVimSource from "https://deno.land/x/ddu_vim@v1.13.0/base/source.ts";
export * as dduVimColumn from "https://deno.land/x/ddu_vim@v1.13.0/base/column.ts";
export * as traq from "https://esm.sh/@traptitech/traq@3.11.0-3";