From 0a85469b2fc7aa5a90de302a8bd99e1b72543746 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Thu, 5 Jul 2018 15:50:40 -0500 Subject: [PATCH] Editor debouncer --- app/assets/javascripts/app/controllers/editor.js | 3 ++- app/assets/javascripts/app/controllers/notes.js | 9 +++------ app/assets/javascripts/app/filters/sortBy.js | 3 ++- app/assets/templates/editor.html.haml | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/app/controllers/editor.js b/app/assets/javascripts/app/controllers/editor.js index 382440504..b54e52449 100644 --- a/app/assets/javascripts/app/controllers/editor.js +++ b/app/assets/javascripts/app/controllers/editor.js @@ -323,7 +323,8 @@ angular.module('app') } this.contentChanged = function() { - this.changesMade(); + // content changes should bypass manual debouncer as we use the built in ng-model-options debouncer + this.changesMade(true); } this.nameChanged = function() { diff --git a/app/assets/javascripts/app/controllers/notes.js b/app/assets/javascripts/app/controllers/notes.js index e90be9064..74ff16204 100644 --- a/app/assets/javascripts/app/controllers/notes.js +++ b/app/assets/javascripts/app/controllers/notes.js @@ -174,11 +174,12 @@ angular.module('app') } this.setNotes = function(notes) { + notes.forEach(function(note){ note.visible = true; }) - var createNew = notes.length == 0; + var createNew = this.visibleNotes().length == 0; this.selectFirstNote(createNew); } @@ -218,7 +219,7 @@ angular.module('app') } this.createNewNote = function() { - var title = "New Note" + (this.tag.notes ? (" " + (this.tag.notes.length + 1)) : ""); + var title = "New Note" + (this.tag.notes ? (" " + (this.visibleNotes().length + 1)) : ""); let newNote = modelManager.createItem({content_type: "Note", content: {text: "", title: title}}); newNote.dummy = true; this.newNote = newNote; @@ -253,10 +254,6 @@ angular.module('app') note.visible = matchesTitle || matchesBody; } - // if(this.tag.archiveTag) { - // note.visible = note.visible && note.archived; - // } - return note.visible; }.bind(this) diff --git a/app/assets/javascripts/app/filters/sortBy.js b/app/assets/javascripts/app/filters/sortBy.js index 2f19d3769..e182b19a5 100644 --- a/app/assets/javascripts/app/filters/sortBy.js +++ b/app/assets/javascripts/app/filters/sortBy.js @@ -35,8 +35,9 @@ angular.module('app') } items = items || []; - return items.sort(function(a, b){ + var result = items.sort(function(a, b){ return sortValueFn(a, b); }) + return result; }; }); diff --git a/app/assets/templates/editor.html.haml b/app/assets/templates/editor.html.haml index 512134f93..9d8bb27e2 100644 --- a/app/assets/templates/editor.html.haml +++ b/app/assets/templates/editor.html.haml @@ -58,7 +58,7 @@ %textarea.editable#note-text-editor{"ng-if" => "!ctrl.selectedEditor", "ng-model" => "ctrl.note.text", "ng-readonly" => "ctrl.note.locked", "ng-change" => "ctrl.contentChanged()", "ng-trim" => "false", "ng-click" => "ctrl.clickedTextArea()", - "ng-focus" => "ctrl.onContentFocus()", "dir" => "auto", "ng-attr-spellcheck" => "{{ctrl.spellcheck}}"} + "ng-focus" => "ctrl.onContentFocus()", "dir" => "auto", "ng-attr-spellcheck" => "{{ctrl.spellcheck}}", "ng-model-options"=>"{ debounce: 200 }"} {{ctrl.onSystemEditorLoad()}} %panel-resizer{"panel-id" => "'editor-content'", "on-resize-finish" => "ctrl.onPanelResizeFinish","control" => "ctrl.resizeControl", "min-width" => 300, "hoverable" => "true", "property" => "'right'"}