From b5521a81d4c6a144a004f67320d9553099019340 Mon Sep 17 00:00:00 2001
From: ocornut <omarcornut@gmail.com>
Date: Sat, 28 May 2016 14:18:46 +0200
Subject: [PATCH] Demo: fixed multi-selection tree nodes demo to not replace
 selection when clicking on single-item that's already part of selection
 (#581)

---
 imgui_demo.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index a38e836f7..6fb75a9cd 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -275,9 +275,9 @@ void ImGui::ShowTestWindow(bool* p_open)
                 {
                     // Update selection state. Process outside of tree loop to avoid visual inconsistencies during the clicking-frame.
                     if (ImGui::GetIO().KeyCtrl)
-                        selection_mask ^= (1 << node_clicked);  // CTRL+click to toggle
-                    else
-                        selection_mask = (1 << node_clicked);   // Click to single-select
+                        selection_mask ^= (1 << node_clicked);          // CTRL+click to toggle
+                    else if (!(selection_mask & (1 << node_clicked)))   // If there is already a selection don't replace we clicked node is part of it
+                        selection_mask = (1 << node_clicked);           // Click to single-select
                 }
                 ImGui::TreePop();
             }