Repository: godotengine/godot
File: editor/docks/editor_dock_manager.cpp (C++)

Code before:
			p_window_dump.get("window_screen", -1),
			p_window_dump.get("window_screen_rect", Rect2i()));
}

void EditorDockManager::_move_dock(EditorDock *p_dock, Control *p_target, int p_tab_index, bool p_set_current) {
	ERR_FAIL_NULL(p_dock);
	ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot move unknown dock '%s'.", p_dock->get_display_title()));

	Node *parent = p_dock->get_parent();
	if (parent == p_target) {
		if (parent && p_tab_index >= 0) {
			// Only change the tab index.
			p_dock->set_tab_index(p_tab_index, p_set_current);
		}
		return;
	}

	// Remove dock from its existing parent.
	if (parent) {
		if (p_dock->dock_window) {
			_close_window(p_dock->dock_window);
		} else {
			DockTabContainer *parent_tabs = Object::cast_to<DockTabContainer>(parent);
			if (parent_tabs) {
				p_dock->previous_tab_index = parent_tabs->get_tab_idx_from_control(p_dock);
			}
			parent->set_block_signals(true);
			parent->remove_child(p_dock);
			parent->set_block_signals(false);
			if (parent_tabs) {
				parent_tabs->update_visibility();
			}
		}
	}

	if (!p_target) {
		p_dock->is_open = false;
		return;
	}

	DockTabContainer *dock_tab_container = Object::cast_to<DockTabContainer>(p_target);
	if (p_target != closed_dock_parent) {
		if (dock_tab_container->layout != p_dock->current_layout) {
			p_dock->update_layout(dock_tab_container->layout);
			p_dock->current_layout = dock_tab_container->layout;
		}
		p_dock->dock_slot_index = dock_tab_container->dock_slot;
	}

	// Add dock to its new parent, at the given tab index.
	p_target->set_block_signals(true);

Review comment (suggestion):
`parent_tabs->get_previous_tab()` can be `-1`, so this will error `  ERROR: Cannot deselect tabs, deselection is not enabled.` in some cases.
It happens when the editor opens and using an addon dock that opens in an unused slot and it is closed.

Code after:

void EditorDockManager::_move_dock(EditorDock *p_dock, Control *p_target, int p_tab_index, bool p_set_current) {
	ERR_FAIL_NULL(p_dock);
	ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot move unknown dock '%s'.", p_dock->get_display_title()));

	Node *parent = p_dock->get_parent();
	if (parent == p_target) {
		if (parent && p_tab_index >= 0) {
			// Only change the tab index.
			p_dock->set_tab_index(p_tab_index, p_set_current);
		}
		return;
	}

	// Remove dock from its existing parent.
	if (parent) {
		if (p_dock->dock_window) {
			_close_window(p_dock->dock_window);
		} else {
			DockTabContainer *parent_tabs = Object::cast_to<DockTabContainer>(parent);
			if (parent_tabs) {
				p_dock->previous_tab_index = parent_tabs->get_tab_idx_from_control(p_dock);

				// Swap to previous tab when closing current tab.
				if (parent_tabs->get_current_tab() == p_dock->previous_tab_index) {
					parent_tabs->set_current_tab(parent_tabs->get_previous_tab());
				}
			}
			parent->set_block_signals(true);
			parent->remove_child(p_dock);
			parent->set_block_signals(false);
			if (parent_tabs) {
				parent_tabs->update_visibility();
			}
		}
	}

	if (!p_target) {
		p_dock->is_open = false;
		return;
	}

	// Prevent extra visibility signals from firing.
	p_dock->hide();

	DockTabContainer *dock_tab_container = Object::cast_to<DockTabContainer>(p_target);
	if (p_target != closed_dock_parent) {
		if (dock_tab_container->layout != p_dock->current_layout) {
			p_dock->update_layout(dock_tab_container->layout);
			p_dock->current_layout = dock_tab_container->layout;
		}