Merge pull request #62 from lospec/fix-crash-when-deselecting-a-color-with-no-colors

changed all color deselections to use optional chaining
This commit is contained in:
Nicola 2021-10-23 18:00:05 +02:00 committed by GitHub
commit bc34208d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 7 deletions

View File

@ -39,7 +39,7 @@ on('click', 'add-color-button', function(){
while (colorIsUnique == false);
//remove current color selection
document.querySelector('#colors-menu li.selected').classList.remove('selected');
document.querySelector('#colors-menu li.selected')?.classList.remove('selected');
//add new color and make it selected
var addedColor = addColor(newColor);

View File

@ -4,8 +4,7 @@ function clickedColor (e){
//left clicked color
if (e.which == 1) {
// remove current color selection
var selectedColor = document.querySelector('#colors-menu li.selected');
if (selectedColor) selectedColor.classList.remove('selected');
document.querySelector('#colors-menu li.selected')?.classList.remove('selected');
//set current color
for (let i=1; i<layers.length - nAppLayers; i++) {

View File

@ -32,8 +32,7 @@ function createColorPalette(paletteColors, deletePreviousPalette = true) {
if (newColorHex.r + newColorHex.g + newColorHex.b < darkestColorHex.r + darkestColorHex.g + darkestColorHex.b) {
//remove current color selection
var selectedColor = document.querySelector('#colors-menu li.selected');
if (selectedColor) selectedColor.classList.remove('selected');
document.querySelector('#colors-menu li.selected')?.classList.remove('selected');
//set as current color
newColorElement.classList.add('selected');

View File

@ -105,8 +105,7 @@ window.addEventListener("mouseup", function (mouseEvent) {
//if picked color matches this color
if (newColor == colors[i].jscolor.toString()) {
//remove current color selection
var selectedColor = document.querySelector("#colors-menu li.selected")
if (selectedColor) selectedColor.classList.remove("selected");
document.querySelector("#colors-menu li.selected")?.classList.remove("selected");
//set current color