Skip to content

Commit

Permalink
Merge pull request #74 from kamecha/feature/ddu-column
Browse files Browse the repository at this point in the history
それっぽいdduのcolumnを追加
  • Loading branch information
kamecha authored Dec 22, 2023
2 parents 8d444b9 + 8c22248 commit ba97280
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
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";

0 comments on commit ba97280

Please sign in to comment.