From 588cdcd97a471a21f05016a06747459358a8630b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 7 Aug 2019 00:01:52 -0700 Subject: [PATCH] GUACAMOLE-630: Preserve the original color scheme string if no changes have been made. --- .../main/webapp/app/form/types/ColorScheme.js | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/guacamole/src/main/webapp/app/form/types/ColorScheme.js b/guacamole/src/main/webapp/app/form/types/ColorScheme.js index e25458e04..587642698 100644 --- a/guacamole/src/main/webapp/app/form/types/ColorScheme.js +++ b/guacamole/src/main/webapp/app/form/types/ColorScheme.js @@ -86,6 +86,15 @@ angular.module('form').factory('ColorScheme', [function defineColorScheme() { ]; + /** + * The string which was parsed to produce this ColorScheme instance, if + * ColorScheme.fromString() was used to produce this ColorScheme. + * + * @private + * @type {String} + */ + this._originalString = template._originalString; + }; /** @@ -170,7 +179,7 @@ angular.module('form').factory('ColorScheme', [function defineColorScheme() { */ ColorScheme.fromString = function fromString(str) { - var scheme = new ColorScheme(); + var scheme = new ColorScheme({ _originalString : str }); // For each semicolon-separated statement in the provided color scheme var statements = str.split(/;/); @@ -200,6 +209,25 @@ angular.module('form').factory('ColorScheme', [function defineColorScheme() { }; + /** + * Returns whether the two given color schemes define the exact same + * colors. + * + * @param {ColorScheme} a + * The first ColorScheme to compare. + * + * @param {ColorScheme} b + * The second ColorScheme to compare. + * + * @returns {Boolean} + * true if both color schemes contain the same colors, false otherwise. + */ + ColorScheme.equals = function equals(a, b) { + return a.foreground === b.foreground + && a.background === b.background + && _.isEqual(a.colors, b.colors); + }; + /** * Converts the given ColorScheme to a string representation which is * supported by the Guacamole terminal emulator. @@ -213,6 +241,10 @@ angular.module('form').factory('ColorScheme', [function defineColorScheme() { */ ColorScheme.toString = function toString(scheme) { + // Use originally-provided string if it equates to the exact same color scheme + if (scheme._originalString && ColorScheme.equals(scheme, ColorScheme.fromString(scheme._originalString))) + return scheme._originalString; + // Add background and foreground var str = 'background: ' + fromHexColor(scheme.background) + ';\n' + 'foreground: ' + fromHexColor(scheme.foreground) + ';';