Skip to content

Commit

Permalink
client: apply grouping to the MIME type list
Browse files Browse the repository at this point in the history
  • Loading branch information
adoriandoran committed Nov 3, 2024
1 parent 4f5d874 commit dd7c208
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ export default class CodeMimeTypesOptions extends OptionsWidget {

async optionsLoaded(options) {
this.$mimeTypes.empty();
let index = -1;
let prevInitial = "";

for (const mimeType of mimeTypesService.getMimeTypes()) {
const id = "code-mime-type-" + (idCtr++);
index++;

// Append a heading to group items by the first letter, excepting for the
// first item ("Plain Text"). Note: this code assumes the items are already
// in alphabetical ordered.
if (index > 0) {
const initial = mimeType.title.charAt(0).toUpperCase();

if (initial !== prevInitial) {
this.$mimeTypes.append($("<h5>").text(initial));
prevInitial = initial;
}
}

this.$mimeTypes.append($("<li>")
.append($('<input type="checkbox" class="form-check-input">')
Expand Down

0 comments on commit dd7c208

Please sign in to comment.