MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / select

Function select

src/lib/recents.js:79–167  ·  view source on GitHub ↗

* * @param {Array >} [extra] * @param {"file"|"dir"|"all"} [type] * @param {string} [title] * @returns {Promise }

(extra, type = "all", title = strings["open recent"])

Source from the content-addressed store, hash-verified

77 * @returns {Promise<RecentPathData>}
78 */
79 select(extra, type = "all", title = strings["open recent"]) {
80 const all = [];
81 const MAX = 20;
82 const shortName = (name) => {
83 name = helpers.getVirtualPath(name);
84
85 if (name.length > MAX) {
86 return "..." + name.substr(-MAX - 3);
87 }
88 return name;
89 };
90
91 if (type === "dir" || type === "all") {
92 let dirs = this.folders;
93 for (let dir of dirs) {
94 const { url } = dir;
95
96 const dirValue = {
97 type: "dir",
98 val: dir,
99 };
100
101 const tailElement = tag("span", {
102 className: "icon clearclose",
103 dataset: {
104 action: "clear",
105 },
106 });
107
108 all.push({
109 value: dirValue,
110 text: shortName(url),
111 icon: "folder",
112 tailElement: tailElement,
113 ontailclick: (e) => {
114 const $item = e.currentTarget.closest(".tile");
115 if ($item) $item.remove();
116 this.removeFolder(dir.url);
117 },
118 });
119 }
120 }
121
122 if (type === "file" || type === "all") {
123 let files = this.files;
124 for (let file of files) {
125 if (!file) continue;
126 const name = shortName(Url.parse(file).url);
127
128 const fileValue = {
129 type: "file",
130 val: file,
131 };
132 const tailElement = tag("span", {
133 className: "icon clearclose",
134 dataset: {
135 action: "clear",
136 },

Callers 5

checkFunction · 0.70
closeTabsFunction · 0.70
eolFunction · 0.70
selectMethod · 0.70
handleContextmenuFunction · 0.70

Calls 2

shortNameFunction · 0.85
removeMethod · 0.45

Tested by

no test coverage detected