filtering placeholders by type in autocomplete. see #157
This commit is contained in:
parent
871d7746a6
commit
c5b1d44fe0
2 changed files with 12 additions and 7 deletions
|
|
@ -42,7 +42,7 @@
|
|||
<td class="w19">
|
||||
<label for="selectTypeNew">__MSG_customPrompts_add_to_menu__:</label>
|
||||
<br>
|
||||
<select id="selectTypeNew" name="type" tabindex="4" class="type_selector">
|
||||
<select id="selectTypeNew" name="type" tabindex="4" class="type_output">
|
||||
<option value="0">__MSG_customPrompts_add_to_menu_always__</option>
|
||||
<option value="1">__MSG_customPrompts_add_to_menu_reading__</option>
|
||||
<option value="2">__MSG_customPrompts_add_to_menu_composing__</option>
|
||||
|
|
|
|||
|
|
@ -114,11 +114,11 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
}
|
||||
|
||||
const textareas = document.querySelectorAll('.editor');
|
||||
autocompleteSuggestions = (await getPlaceholders(true)).map(p => '{%'+p.id+'%}');
|
||||
autocompleteSuggestions = (await getPlaceholders(true)).map(p => ({command: '{%'+p.id+'%}', type: p.type}));
|
||||
|
||||
// console.log('>>>>>>>>>>> suggestions: ' + JSON.stringify(suggestions));
|
||||
|
||||
textareas.forEach(textarea => textareaAutocomplete(textarea, autocompleteSuggestions, textarea.closest('.type_selector')?.value));
|
||||
textareas.forEach(textarea => textareaAutocomplete(textarea, autocompleteSuggestions));
|
||||
|
||||
// document.addEventListener('click', (e) => {
|
||||
// // Check if the click was outside the textarea or suggestion list
|
||||
|
|
@ -299,7 +299,7 @@ function showItemRowEditor(tr) {
|
|||
tr.querySelector('.name_show').style.display = 'none';
|
||||
const text_output = tr.querySelector('.text_output');
|
||||
text_output.style.display = 'inline';
|
||||
textareaAutocomplete(text_output, autocompleteSuggestions, tr.closest('.type_selector').value)
|
||||
textareaAutocomplete(text_output, autocompleteSuggestions)
|
||||
tr.querySelector('.text_show').style.display = 'none';
|
||||
tr.querySelector('.type_output').style.display = 'inline';
|
||||
tr.querySelector('.type_show').style.display = 'none';
|
||||
|
|
@ -425,7 +425,7 @@ function loadPromptsList(values){
|
|||
<td class="w08"><span class="id id_show"></span><input type="text" class="hiddendata id_output" value="` + values.id + `" /></td>
|
||||
<td class="w08"><span class="name name_show"></span><input type="text" class="hiddendata name_output" value="` + values.name + `" /></td>
|
||||
<td class="w40"><span class="text text_show"></span><div class="autocomplete-container"><textarea class="hiddendata text_output editor">` + values.text + `</textarea><ul class="autocomplete-list hidden"></ul></div></td>
|
||||
<td class="w08"><span class="type_show" class="type_selector">` + type_output + `</span>
|
||||
<td class="w08"><span class="type_show">` + type_output + `</span>
|
||||
<select class="type_output hiddendata">
|
||||
<option value="0"` + ((values.type == "0") ? ' selected':'') + `>__MSG_customPrompts_add_to_menu_always__</option>
|
||||
<option value="1"` + ((values.type == "1") ? ' selected':'') + `>__MSG_customPrompts_add_to_menu_reading__</option>
|
||||
|
|
@ -668,7 +668,7 @@ if(await isThunderbird128OrGreater()){
|
|||
});
|
||||
}
|
||||
|
||||
function textareaAutocomplete(textarea, suggestions, type) { console.log(">>>>>>>>> textareaAutocomplete type: " + type);
|
||||
function textareaAutocomplete(textarea, suggestions) {
|
||||
const container = textarea.closest('.autocomplete-container');
|
||||
const autocompleteList = container.querySelector('.autocomplete-list');
|
||||
let activeIndex = -1;
|
||||
|
|
@ -680,7 +680,12 @@ function textareaAutocomplete(textarea, suggestions, type) { console.log(">>>>>>
|
|||
|
||||
if (match) {
|
||||
const lastWord = match[0];
|
||||
const matches = suggestions.filter(s => s.startsWith(lastWord) && s.type === type);
|
||||
const tr = textarea.parentNode.parentNode.parentNode;
|
||||
let type = tr.querySelector('.type_output').value
|
||||
console.log(">>>>>>>>> type: " + type);
|
||||
const matches = suggestions.filter(s => s.command.startsWith(lastWord) && (String(s.type) == String(type) || String(s.type) == '0' )).map(s => s.command);
|
||||
// const matches = suggestions.filter(s => s.startsWith(lastWord));
|
||||
console.log(">>>>>>>>> matches: " + JSON.stringify(matches));
|
||||
showSuggestions(matches, autocompleteList);
|
||||
} else {
|
||||
hideSuggestions(autocompleteList);
|
||||
|
|
|
|||
Loading…
Reference in a new issue