From 4d7bb3c6e3ed1fdbeadc1c9ce8ed796c53504542 Mon Sep 17 00:00:00 2001 From: Meir Rotstein Date: Mon, 8 Oct 2018 20:52:47 +0300 Subject: [PATCH] refresh annotations with error type only (#587) * Fix #582: parse error annotations not always up to date in code editor * refresh annotations with error type only --- HISTORY.md | 5 +++++ src/js/textmode.js | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 6689cda..5f670df 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,11 @@ https://github.com/josdejong/jsoneditor +## not yet released, version 5.24.7 + +- Fix #582: parse error annotations not always up to date in + code editor. + ## 2018-09-12, version 5.24.6 diff --git a/src/js/textmode.js b/src/js/textmode.js index b91ffca..721bbf4 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -530,8 +530,19 @@ textmode._emitSelectionChange = function () { } } -textmode._refreshAnnotations = function () { - this.aceEditor && this.aceEditor.getSession().setAnnotations(); +/** + * refresh ERROR annotations state + * error annotations are handled by the ace json mode (ace/mode/json) + * validation annotations are handled by this mode + * therefore in order to refresh we send only the annotations of error type in order to maintain its state + * @private + */ +textmode._refreshAnnotations = function () { + var session = this.aceEditor && this.aceEditor.getSession(); + if (session) { + var errEnnotations = session.getAnnotations().filter(function(annotation) {return annotation.type === 'error' }); + session.setAnnotations(errEnnotations); + } } /**