-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from kamecha/feature/ddu-column
それっぽいdduのcolumnを追加
- Loading branch information
Showing
3 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters