diff --git a/src/js/1p-filters.js b/src/js/1p-filters.js index 358f0238b..ac6ac2d22 100644 --- a/src/js/1p-filters.js +++ b/src/js/1p-filters.js @@ -143,17 +143,22 @@ var exportUserFiltersToFile = function() { /******************************************************************************/ var applyChanges = function() { + var textarea = uDom.nodeFromId('userFilters'); + var onWritten = function(details) { if ( details.error ) { return; } + textarea.value = details.content; cachedUserFilters = details.content.trim(); userFiltersChanged(); allFiltersApplyHandler(); + textarea.focus(); }; + var request = { what: 'writeUserFilters', - content: uDom('#userFilters').val() + content: textarea.value }; messager.send(request, onWritten); }; diff --git a/src/js/messaging.js b/src/js/messaging.js index 102a279cf..66cb45f21 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -862,10 +862,10 @@ var onMessage = function(request, sender, callback) { // Async switch ( request.what ) { case 'readUserFilters': - return µb.assets.get(µb.userFiltersPath, callback); + return µb.loadUserFilters(callback); case 'writeUserFilters': - return µb.assets.put(µb.userFiltersPath, request.content, callback); + return µb.saveUserFilters(request.content, callback); default: break; diff --git a/src/js/storage.js b/src/js/storage.js index 65ba5026e..343802d05 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -151,6 +151,12 @@ /******************************************************************************/ µBlock.saveUserFilters = function(content, callback) { + // https://github.com/gorhill/uBlock/issues/1022 + // Be sure to end with an empty line. + content = content.trim(); + if ( content !== '' ) { + content += '\n'; + } this.assets.put(this.userFiltersPath, content, callback); };