(w io.Writer, m list.Model, index int, item list.Item)
| 55 | } |
| 56 | |
| 57 | func (d itemDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) { |
| 58 | model, ok := item.(Model) |
| 59 | if !ok { |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | // If StripString is set in the config, strip it from the model name |
| 64 | if d.appModel.cfg.StripString != "" { |
| 65 | model.Name = strings.Replace(model.Name, d.appModel.cfg.StripString, "", 1) |
| 66 | } |
| 67 | |
| 68 | nameStyle := styles.ItemNameStyle(index) |
| 69 | dateStyle := styles.ItemDateStyle() |
| 70 | shaStyle := styles.ItemShaStyle() |
| 71 | sizeStyle := styles.SizeStyle(model.Size) |
| 72 | familyStyle := styles.FamilyStyle(model.Family) |
| 73 | quantStyle := styles.QuantStyle(model.QuantizationLevel) |
| 74 | modifiedStyle := styles.ItemDateStyle() // Use date style for modified date |
| 75 | |
| 76 | if index == m.Index() { |
| 77 | // Apply border and highlight styles for selected item |
| 78 | nameStyle = nameStyle.Bold(true).BorderLeft(true).BorderStyle(lipgloss.InnerHalfBlockBorder()).BorderForeground(styles.GetTheme().GetColour(styles.GetTheme().Colours.ItemBorder)).PaddingLeft(1) |
| 79 | sizeStyle = sizeStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2) |
| 80 | quantStyle = quantStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2) |
| 81 | familyStyle = familyStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2) |
| 82 | modifiedStyle = modifiedStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2) |
| 83 | shaStyle = shaStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2) |
| 84 | dateStyle = dateStyle.Bold(true).BorderLeft(true).PaddingLeft(-2).PaddingRight(-2) |
| 85 | } |
| 86 | |
| 87 | // Check if the model is selected in both filtered and unfiltered states |
| 88 | isSelected := model.Selected |
| 89 | if d.appModel.list.FilterState() == list.Filtering || d.appModel.list.FilterState() == list.FilterApplied { |
| 90 | // When filtering, also check the main models list to ensure selection state is accurate |
| 91 | for _, m := range d.appModel.models { |
| 92 | if m.Name == model.Name && m.Selected { |
| 93 | isSelected = true |
| 94 | break |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if isSelected { |
| 100 | selectedStyle := styles.SelectedItemStyle() |
| 101 | // Create new styles that inherit from selected style first |
| 102 | // Keep the foreground colour but add the background highlight |
| 103 | nameStyle = selectedStyle.Bold(true). |
| 104 | Italic(true) |
| 105 | shaStyle = selectedStyle.Inherit(shaStyle) |
| 106 | dateStyle = selectedStyle.Inherit(dateStyle) |
| 107 | sizeStyle = selectedStyle.Inherit(sizeStyle) |
| 108 | familyStyle = selectedStyle.Inherit(familyStyle) |
| 109 | quantStyle = selectedStyle.Inherit(quantStyle) |
| 110 | } |
| 111 | |
| 112 | nameWidth, sizeWidth, quantWidth, modifiedWidth, idWidth, familyWidth, paramSizeWidth := calculateColumnWidths(m.Width()) |
| 113 | |
| 114 | // Ensure the text fits within the terminal width |
no test coverage detected