RangeSelect/MultiSelect: Added IMGUI_HAS_MULTI_SELECT define. Fixed right-click toggling selection without clearing active id, could lead to MarkItemEdited() asserting. Fixed demo.
diff --git a/imgui.h b/imgui.h
index f34a01d..7fdb2da 100644
--- a/imgui.h
+++ b/imgui.h
@@ -1770,6 +1770,7 @@
 //   5) Call EndMultiSelect(). Save the value of ->RangeSrc for the next frame (you may convert the value in a format that is safe for persistance)
 //   6) Honor Clear/SelectAll/SetRange requests by updating your selection data. Always process them in this order (as you will receive Clear+SetRange request simultaneously)
 // If you submit all items (no clipper), Step 2 and 3 and will be handled by Selectable() on a per-item basis.
+#define IMGUI_HAS_MULTI_SELECT      1 // Multi-Select/Range-Select WIP branch // <-- This is currently _not_ in the top of imgui.h to prevent merge conflicts.
 struct ImGuiMultiSelectData
 {
     bool    RequestClear;           // Begin, End   // Request user to clear selection
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 005ebf8..2a1c0e3 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -921,34 +921,35 @@
             HelpMarker("Hold CTRL and click to select multiple items. Hold SHIFT to select a range.");
             ImGui::CheckboxFlags("io.ConfigFlags: NavEnableKeyboard", (unsigned int *)&ImGui::GetIO().ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard);
 
-            ImGui::ListBoxHeader("##Basket", ImVec2(-1, ImGui::GetFontSize() * 20));
-
-            ImGuiMultiSelectData* multi_select_data = ImGui::BeginMultiSelect(0, (void*)(intptr_t)selection_ref, selection.GetSelected((int)selection_ref));
-            if (multi_select_data->RequestClear)     { selection.Clear(); }
-            if (multi_select_data->RequestSelectAll) { selection.SelectAll(COUNT); }
-            ImGuiListClipper clipper(COUNT);
-            while (clipper.Step())
+            if (ImGui::ListBoxHeader("##Basket", ImVec2(-1, ImGui::GetFontSize() * 20)))
             {
-                if (clipper.DisplayStart > (int)selection_ref)
-                    multi_select_data->RangeSrcPassedBy = true;
-                for (int n = clipper.DisplayStart; n < clipper.DisplayEnd; n++)
+                ImGuiMultiSelectData* multi_select_data = ImGui::BeginMultiSelect(0, (void*)(intptr_t)selection_ref, selection.GetSelected((int)selection_ref));
+                if (multi_select_data->RequestClear) { selection.Clear(); }
+                if (multi_select_data->RequestSelectAll) { selection.SelectAll(COUNT); }
+                ImGuiListClipper clipper(COUNT);
+                while (clipper.Step())
                 {
-                    ImGui::PushID(n);
-                    char label[64];
-                    sprintf(label, "Object %05d (category: %s)", n, random_names[n % IM_ARRAYSIZE(random_names)]);
-                    bool item_is_selected = selection.GetSelected(n);
-                    ImGui::SetNextItemMultiSelectData((void*)(intptr_t)n);
-                    if (ImGui::Selectable(label, item_is_selected))
-                        selection.SetSelected(n, !item_is_selected);
-                    ImGui::PopID();
+                    if (clipper.DisplayStart > (int)selection_ref)
+                        multi_select_data->RangeSrcPassedBy = true;
+                    for (int n = clipper.DisplayStart; n < clipper.DisplayEnd; n++)
+                    {
+                        ImGui::PushID(n);
+                        char label[64];
+                        sprintf(label, "Object %05d (category: %s)", n, random_names[n % IM_ARRAYSIZE(random_names)]);
+                        bool item_is_selected = selection.GetSelected(n);
+                        ImGui::SetNextItemMultiSelectData((void*)(intptr_t)n);
+                        if (ImGui::Selectable(label, item_is_selected))
+                            selection.SetSelected(n, !item_is_selected);
+                        ImGui::PopID();
+                    }
                 }
+                multi_select_data = ImGui::EndMultiSelect();
+                selection_ref = (int)(intptr_t)multi_select_data->RangeSrc;
+                ImGui::ListBoxFooter();
+                if (multi_select_data->RequestClear)     { selection.Clear(); }
+                if (multi_select_data->RequestSelectAll) { selection.SelectAll(COUNT); }
+                if (multi_select_data->RequestSetRange)  { selection.SetRange((int)(intptr_t)multi_select_data->RangeSrc, (int)(intptr_t)multi_select_data->RangeDst, multi_select_data->RangeValue ? 1 : 0); }
             }
-            multi_select_data = ImGui::EndMultiSelect();
-            selection_ref = (int)(intptr_t)multi_select_data->RangeSrc;
-            ImGui::ListBoxFooter();
-            if (multi_select_data->RequestClear)     { selection.Clear(); }
-            if (multi_select_data->RequestSelectAll) { selection.SelectAll(COUNT); }
-            if (multi_select_data->RequestSetRange)  { selection.SetRange((int)(intptr_t)multi_select_data->RangeSrc, (int)(intptr_t)multi_select_data->RangeDst, multi_select_data->RangeValue ? 1 : 0); }
             ImGui::TreePop();
         }
         if (ImGui::TreeNode("Rendering more text into the same line"))
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index 393eda6..907b1d8 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -5770,7 +5770,9 @@
     bool hovered = IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);
     if (hovered && IsMouseClicked(1))
     {
-        SetFocusID(window->DC.LastItemId, window);
+        if (g.ActiveId != 0 && g.ActiveId != id)
+            ClearActiveID();
+        SetFocusID(id, window);
         if (!pressed && !selected)
         {
             pressed = true;