Skip to content

Commit 4465738

Browse files
committed
Improve size column in dialogs
- Remove size from directories (often always 4K and not very useful). - Format file sizes to be more human-readable.
1 parent 5ad9398 commit 4465738

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/vscode/src/dialog.scss

+9-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@
7979
.dialog-entry {
8080
cursor: pointer;
8181
font-size: 1.02em;
82-
padding: 0px;
83-
padding-left: 8px;
84-
padding-right: 8px;
82+
padding: 0px 8px;
8583

8684
.dialog-entry-info {
8785
display: flex;
@@ -94,6 +92,14 @@
9492
margin-right: 5px;
9593
}
9694

95+
.dialog-entry-size {
96+
text-align: right;
97+
}
98+
99+
.dialog-entry-mtime {
100+
padding-left: 8px;
101+
}
102+
97103
&:hover {
98104
background-color: var(--list-hover-background);
99105
}

packages/vscode/src/dialog.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ class DialogEntryRenderer implements ITreeRenderer<DialogEntry, string, DialogEn
480480
start: 0,
481481
end: node.filterData.length,
482482
}] : []);
483-
templateData.size.innerText = node.element.size.toString();
483+
templateData.size.innerText = !node.element.isDirectory ? this.humanReadableSize(node.element.size) : "";
484484
templateData.lastModified.innerText = node.element.lastModified;
485485

486486
// We know this exists because we created the template.
@@ -498,4 +498,16 @@ class DialogEntryRenderer implements ITreeRenderer<DialogEntry, string, DialogEn
498498
public disposeTemplate(_templateData: DialogEntryData): void {
499499
// throw new Error("Method not implemented.");
500500
}
501+
502+
/**
503+
* Given a positive size in bytes, return a string that is more readable for
504+
* humans.
505+
*/
506+
private humanReadableSize(bytes: number): string {
507+
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
508+
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1000)), units.length - 1);
509+
510+
return (bytes / Math.pow(1000, i)).toFixed(2)
511+
+ " " + units[i];
512+
}
501513
}

0 commit comments

Comments
 (0)