Index: src/wp-admin/css/widgets.css
===================================================================
--- src/wp-admin/css/widgets.css	(revisione 37418)
+++ src/wp-admin/css/widgets.css	(copia locale)
@@ -332,9 +332,13 @@
 }
 
 .editwidget {
-	margin: 0 auto;
+	max-width: 40em; /* about 80 characters, for readability */
 }
 
+.editwidget select {
+    width: 100%;
+}
+
 .editwidget .widget-inside {
 	display: block;
 	padding: 0 15px;
Index: src/wp-admin/widgets.php
===================================================================
--- src/wp-admin/widgets.php	(revisione 37418)
+++ src/wp-admin/widgets.php	(copia locale)
@@ -182,6 +182,25 @@
 
 	// Remove old position.
 	if ( !isset($_POST['delete_widget']) ) {
+                // Detect if the widget is registered, in case remove from the sidebar in editing
+                global $wp_widget_factory;
+                foreach ( $sidebars_widgets[$_POST['sidebar']] as $key => $sb ) {
+                    $notfound = false;
+                    foreach ( $wp_widget_factory->widgets as $widget_obj => $class ) {
+                        // Get the base id of the widget
+                        $widget_base_id = explode('-', $sb);
+                        $widget_base_id = $widget_base_id[0];
+                        // We have found that widget?
+                        if( $widget_base_id === $class->id_base ) {
+                            $notfound = true;
+                        }
+                    }
+                    // Inc ase not found we remove from the db
+                    if( false === $notfound ) {
+                        unset($sidebars_widgets[$_POST['sidebar']][$key]);
+                    }
+                }
+                array_values($sidebars_widgets);
 		foreach ( $sidebars_widgets as $key => $sb ) {
 			if ( is_array($sb) )
 				$sidebars_widgets[$key] = array_diff( $sb, array($widget_id) );
@@ -259,13 +278,12 @@
 	$id_base = isset($control['id_base']) ? $control['id_base'] : $control['id'];
 
 	// Show the widget form.
-	$width = ' style="width:' . max($control['width'], 350) . 'px"';
 	$key = isset($_GET['key']) ? (int) $_GET['key'] : 0;
 
 	require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>
 	<div class="wrap">
 	<h1><?php echo esc_html( $title ); ?></h1>
-	<div class="editwidget"<?php echo $width; ?>>
+	<div class="editwidget">
 	<h2><?php printf( __( 'Widget %s' ), $name ); ?></h2>
 
 	<form action="widgets.php" method="post">
@@ -279,7 +297,7 @@
 
 	<p class="describe"><?php _e('Select both the sidebar for this widget and the position of the widget in that sidebar.'); ?></p>
 	<div class="widget-position">
-	<table class="widefat"><thead><tr><th><?php _e('Sidebar'); ?></th><th><?php _e('Position'); ?></th></tr></thead><tbody>
+	<table class="widefat"><thead><tr><th><?php _e( 'Sidebar' ); ?></th><th><?php _e( 'Widget position' ); ?></th></tr></thead><tbody>
 <?php
 	foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) {
 		echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr($sbname) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>";
@@ -291,16 +309,38 @@
 				$sidebars_widgets[$sbname] = array();
 			} else {
 				$j = count($sidebars_widgets[$sbname]);
-				if ( isset($_GET['addnew']) || !in_array($widget_id, $sidebars_widgets[$sbname], true) )
+				// When adding a new widget or the edited widget is not in this sidebar, add one more cycle to the loop below.
+				if ( isset( $_GET['addnew'] ) || ! in_array( $widget_id, $sidebars_widgets[$sbname], true ) ) {
 					$j++;
+				}
 			}
 			$selected = '';
+			$index = $widget_new_position = 0;
 			echo "\t\t<select name='{$sbname}_position'>\n";
 			echo "\t\t<option value=''>" . __('&mdash; Select &mdash;') . "</option>\n";
+			/*
+			 * When adding a new widget or the edited widget is not in this sidebar, this loop runs
+			 * one cycle more than the actual widgets count to build an empty option in the select.
+			 */
 			for ( $i = 1; $i <= $j; $i++ ) {
-				if ( in_array($widget_id, $sidebars_widgets[$sbname], true) )
-					$selected = selected( $i, $key + 1, false );
-				echo "\t\t<option value='$i'$selected> $i </option>\n";
+				// Get the ID of the widget in the loop. Set it to false when running the additional loop cycle.
+				$sidebar_widget_id = isset( $sidebars_widgets[$sbname][$index] ) ? $sidebars_widgets[$sbname][$index] : false;
+                                // If the widget is not avalaible o not exist add an available position option
+                                if( empty( $sidebar_widget_id ) || isset( $wp_registered_widgets[$sidebar_widget_id]['name'] ) ) {
+                                    $widget_new_position++;
+                                    // If the widget ID is set then get the widget name otherwise set a name for the empty option.
+                                    $select_option_content = $sidebar_widget_id ? sprintf( __( '(currently set to: %s)' ), $wp_registered_widgets[$sidebar_widget_id]['name'] ) : esc_html_x( '(available position)', 'widget' );
+
+                                    if ( in_array( $widget_id, $sidebars_widgets[$sbname], true ) ) {
+                                            $selected = selected( $i, $key + 1, false );
+                                    }
+                                    
+                                    echo "\t\t<option value='$widget_new_position'$selected>$widget_new_position $select_option_content</option>\n";
+                                } else {
+                                    // Add a new option because this code is executed only when the widget is removed from the check above
+                                    $j++;
+                                }
+                                $index++;
 			}
 			echo "\t\t</select>\n";
 		}
