From 2b9c0a63fba2aaf1dcfbde7d396fe9f324557e42 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Tue, 10 Jul 2018 13:58:44 +0100 Subject: [PATCH] Ensure CodeMirror always has a non-zero font size. Fixes #3480 --- web/pgadmin/browser/static/css/browser.css | 5 +---- web/pgadmin/browser/static/js/preferences.js | 5 ++++- web/pgadmin/static/js/sqleditor_utils.js | 9 +++++---- web/regression/javascript/sqleditor_utils_spec.js | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/web/pgadmin/browser/static/css/browser.css b/web/pgadmin/browser/static/css/browser.css index 502812b84..26be9003c 100644 --- a/web/pgadmin/browser/static/css/browser.css +++ b/web/pgadmin/browser/static/css/browser.css @@ -1,6 +1,3 @@ -:root { - --codemirror-font-size : 1em; -} /* Styles for the main browser */ .browser-pane-container { position: absolute; @@ -71,5 +68,5 @@ samp, } .CodeMirror { - font-size: var(--codemirror-font-size, '1em'); + font-size: 1em; } diff --git a/web/pgadmin/browser/static/js/preferences.js b/web/pgadmin/browser/static/js/preferences.js index 1e84bd417..5ca9e3ce7 100644 --- a/web/pgadmin/browser/static/js/preferences.js +++ b/web/pgadmin/browser/static/js/preferences.js @@ -65,12 +65,15 @@ _.extend(pgBrowser, { preferences[preference.name] = preference.value; } ); - return preferences; + if(Object.keys(preferences).length > 0) { + return preferences; + } }, /* Get preference of an id, id is numeric */ get_preference_for_id : function(id) { var self = this; + /* findWhere returns undefined if not found */ return _.findWhere(self.preferences_cache, {'id': id}); }, diff --git a/web/pgadmin/static/js/sqleditor_utils.js b/web/pgadmin/static/js/sqleditor_utils.js index c131e22cc..4610d7aa2 100644 --- a/web/pgadmin/static/js/sqleditor_utils.js +++ b/web/pgadmin/static/js/sqleditor_utils.js @@ -188,11 +188,12 @@ define(['jquery', 'sources/gettext', 'sources/url_for'], calcFontSize: function(fontSize) { if(fontSize) { - return Number((Math.round(fontSize + 'e+2') + 'e-2')) + 'em'; - } - else { - return '0em'; + let rounded = Number((Math.round(fontSize + 'e+2') + 'e-2')); + if(rounded > 0) { + return rounded + 'em'; + } } + return '1em'; }, }; return sqlEditorUtils; diff --git a/web/regression/javascript/sqleditor_utils_spec.js b/web/regression/javascript/sqleditor_utils_spec.js index 75c34afc2..4237bce32 100644 --- a/web/regression/javascript/sqleditor_utils_spec.js +++ b/web/regression/javascript/sqleditor_utils_spec.js @@ -32,7 +32,7 @@ function (SqlEditorUtils) { describe('Calculate font size of input number passed', function () { it('calcFontSize', function () { expect(SqlEditorUtils.calcFontSize(1.456)).toEqual('1.46em'); - expect(SqlEditorUtils.calcFontSize()).toEqual('0em'); + expect(SqlEditorUtils.calcFontSize()).toEqual('1em'); expect(SqlEditorUtils.calcFontSize(2)).toEqual('2em'); }); });