Add a header with pre-filled key and value
(
&mut self,
key: &str,
value: &str,
window: &mut Window,
cx: &mut Context<Self>,
)
| 122 | } |
| 123 | |
| 124 | fn rows_as_bulk_entries(&self, cx: &App) -> Vec<BulkKvEntry> { |
| 125 | self.header_rows |
| 126 | .iter() |
| 127 | .map(|row| BulkKvEntry { |
| 128 | key: row.key_input.read(cx).text().to_string(), |
| 129 | value: row.value_input.read(cx).text().to_string(), |
| 130 | enabled: row.enabled, |
| 131 | }) |
| 132 | .collect() |
| 133 | } |
| 134 | |
| 135 | fn replace_from_bulk_entries( |
| 136 | &mut self, |
| 137 | entries: Vec<BulkKvEntry>, |
| 138 | window: &mut Window, |
| 139 | cx: &mut Context<Self>, |
| 140 | ) { |
| 141 | // Preserve descriptions across bulk round-trips by matching keys |
| 142 | // (headers are case-insensitive). |
| 143 | let mut descriptions: HashMap<String, String> = HashMap::new(); |
| 144 | for row in &self.header_rows { |
| 145 | let key = row.key_input.read(cx).text().to_string(); |
| 146 | let description = row.description_input.read(cx).text().to_string(); |
| 147 | if !key.is_empty() && !description.is_empty() { |
| 148 | descriptions.insert(key.to_ascii_lowercase(), description); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | self.header_rows.clear(); |
| 153 | for entry in entries { |
| 154 | let description = descriptions |
| 155 | .get(&entry.key.to_ascii_lowercase()) |
| 156 | .cloned() |
| 157 | .unwrap_or_default(); |
| 158 | let completion_engine = self.completion_engine.clone(); |
| 159 | let key_input = cx.new(|cx| { |
| 160 | configure_completion( |
| 161 | InputState::new(window, cx) |
| 162 | .placeholder("Header name") |
| 163 | .default_value(&entry.key), |
| 164 | completion_engine.as_ref(), |
| 165 | CompletionContext::HeaderName, |
| 166 | ) |
| 167 | }); |
no test coverage detected