mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	fix #223 plus some refactorings
This commit is contained in:
		
							parent
							
								
									25e68762fe
								
							
						
					
					
						commit
						295800881b
					
				@ -204,7 +204,7 @@ async function createPromotedAttributeRow(definitionAttr, valueAttr) {
 | 
			
		||||
            promotedAttributeChanged(event);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $input.prop("data-selected-path", valueAttr.value);
 | 
			
		||||
        $input.setSelectedPath(valueAttr.value);
 | 
			
		||||
 | 
			
		||||
        // ideally we'd use link instead of button which would allow tooltip preview, but
 | 
			
		||||
        // we can't guarantee updating the link in the a element
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,8 @@
 | 
			
		||||
import server from "./server.js";
 | 
			
		||||
import noteDetailService from "./note_detail.js";
 | 
			
		||||
 | 
			
		||||
const SELECTED_PATH_KEY = "selected-path";
 | 
			
		||||
 | 
			
		||||
async function autocompleteSource(term, cb) {
 | 
			
		||||
    const result = await server.get('autocomplete'
 | 
			
		||||
        + '?query=' + encodeURIComponent(term)
 | 
			
		||||
@ -17,7 +19,7 @@ async function autocompleteSource(term, cb) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function clearText($el) {
 | 
			
		||||
    $el.val('').change();
 | 
			
		||||
    $el.autocomplete("val", "").change();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function showRecentNotes($el) {
 | 
			
		||||
@ -62,12 +64,11 @@ function initNoteAutocomplete($el) {
 | 
			
		||||
            }
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $el.on('autocomplete:selected', function(event, suggestion, dataset) {
 | 
			
		||||
            $el.prop("data-selected-path", suggestion.path);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $el.on('autocomplete:selected', (event, suggestion) => $el.setSelectedPath(suggestion.path));
 | 
			
		||||
        $el.on('autocomplete:closed', () => {
 | 
			
		||||
            $el.prop("data-selected-path", "");
 | 
			
		||||
            if (!$el.val().trim()) {
 | 
			
		||||
                $el.setSelectedPath("");
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -79,10 +80,14 @@ $.fn.getSelectedPath = function() {
 | 
			
		||||
        return "";
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        return $(this).prop("data-selected-path");
 | 
			
		||||
        return $(this).data(SELECTED_PATH_KEY);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
$.fn.setSelectedPath = function(path) {
 | 
			
		||||
    $(this).data(SELECTED_PATH_KEY, path);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
ko.bindingHandlers.noteAutocomplete = {
 | 
			
		||||
    init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
 | 
			
		||||
        initNoteAutocomplete($(element));
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user