From c7d126e32169f542e3170681574965376309ea10 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Fri, 20 Jan 2012 10:40:14 +0900 Subject: [PATCH] user can now change the color manually in the codemirror editor and their changes will be reflected in the colorpicker widget. --- static-files/scripts/editor.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/static-files/scripts/editor.js b/static-files/scripts/editor.js index df1dc55..ae228e5 100644 --- a/static-files/scripts/editor.js +++ b/static-files/scripts/editor.js @@ -60,6 +60,7 @@ var Editor = (function() { var picker = null; var pickerPos = null; var inCursorActivity = false; + var inManualColorChange = false; function removePicker() { if (picker) { @@ -128,17 +129,28 @@ var Editor = (function() { return t.string }).join("").trim(); if (pickerPos && pickerPos.line == pos.line && - pickerPos.ch == tokensStart) + pickerPos.ch == tokensStart) { + if (pickerPos.lastValue != cssValue) { + inManualColorChange = true; + picker.colorpicker("setColor", cssValue); + inManualColorChange = false; + pickerPos.lastValue = cssValue; + } return; + } removePicker(); - pickerPos = {line: pos.line, ch: tokensStart}; + pickerPos = { + line: pos.line, + ch: tokensStart, + lastValue: cssValue + }; //console.log("cssValue is", cssValue); picker = $('
').appendTo(document.body); picker.colorpicker({ alpha: true, color: cssValue, onSelect: function(hex, rgba, inst) { - if (!pickerPos) + if (!pickerPos || inManualColorChange) return; var value; if (rgba.a == 1) {