diff --git a/denops/@ddu-columns/channel.ts b/denops/@ddu-columns/channel.ts new file mode 100644 index 0000000..90b2859 --- /dev/null +++ b/denops/@ddu-columns/channel.ts @@ -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 { + getLength( + args: dduVimColumn.GetLengthArguments, + ): Promise { + 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, + ): Promise { + 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, + }; + } +} diff --git a/denops/@ddu-sources/channel.ts b/denops/@ddu-sources/channel.ts index 7a6b763..805f43a 100644 --- a/denops/@ddu-sources/channel.ts +++ b/denops/@ddu-sources/channel.ts @@ -38,7 +38,7 @@ export class Source extends dduVim.BaseSource { }); parentChannels.forEach((channel: Channel) => { items.push({ - word: channel.path + (channel.children.length === 0 ? "" : "/"), + word: channel.name, action: { id: channel.id, }, @@ -63,8 +63,7 @@ export class Source extends dduVim.BaseSource { return; } items.push({ - word: (childrenChannel.path.split("/").pop() ?? "") + - (childrenChannel.children.length === 0 ? "" : "/"), + word: childrenChannel.name, action: { id: childrenChannel.id, }, diff --git a/denops/traqvim/deps.ts b/denops/traqvim/deps.ts index e7f2989..f9b3f41 100644 --- a/denops/traqvim/deps.ts +++ b/denops/traqvim/deps.ts @@ -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";