Index: /FCKeditor/trunk/_whatsnew.html
===================================================================
--- /FCKeditor/trunk/_whatsnew.html	(revision 2905)
+++ /FCKeditor/trunk/_whatsnew.html	(revision 2906)
@@ -131,4 +131,7 @@
 			[<a target="_blank" href="http://dev.fckeditor.net/ticket/2733">#2733</a>] Enable undo of changes to 
 			tables and table cells.</li>
+		<li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1865">#1865</a>] The context
+			menu is now working properly over the last row in a table with thead. Thanks to
+			Koen Willems.</li>
 	</ul>
 	<p>
Index: /FCKeditor/trunk/editor/_source/internals/fcktablehandler.js
===================================================================
--- /FCKeditor/trunk/editor/_source/internals/fcktablehandler.js	(revision 2905)
+++ /FCKeditor/trunk/editor/_source/internals/fcktablehandler.js	(revision 2906)
@@ -383,5 +383,5 @@
 	this._ReplaceCellsByMarker( tableMap, '_SelectedCells', refCell ) ;
 	this._UnmarkCells( cells, '_SelectedCells' ) ;
-	this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
+	this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ;
 	refCell.appendChild( cellContents ) ;
 
@@ -409,5 +409,5 @@
 	this._MarkCells( [nextCell], '_Replace' ) ;
 	this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ;
-	this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
+	this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ;
 
 	this._MoveCaretToCell( refCell, false ) ;
@@ -431,5 +431,5 @@
 	this._MarkCells( [nextCell], '_Replace' ) ;
 	this._ReplaceCellsByMarker( tableMap, '_Replace', refCell ) ;
-	this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
+	this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ;
 
 	this._MoveCaretToCell( refCell, false ) ;
@@ -497,5 +497,5 @@
 	}
 
-	this._InstallTableMap( tableMap, refCell.parentNode.parentNode ) ;
+	this._InstallTableMap( tableMap, refCell.parentNode.parentNode.parentNode ) ;
 }
 
@@ -541,16 +541,16 @@
 		if ( FCKBrowserInfo.IsGeckoLike )
 			FCKTools.AppendBogusBr( newCell ) ;
-		currentCell.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ;
+		currentCell.parentNode.parentNode.parentNode.rows[newCellRowIndex].insertBefore( newCell, insertMarker ) ;
 	}
 	else
 	{
 		// 1. Insert a new row.
-		var newCellRowIndex = currentRowIndex + 1 ;
+		var newSectionRowIdx = currentCell.parentNode.sectionRowIndex + 1 ;
 		var newRow = FCK.EditorDocument.createElement( 'tr' ) ;
-		var tBody = currentCell.parentNode.parentNode ;
-		if ( tBody.rows.length > newCellRowIndex )
-			tBody.insertBefore( newRow, tBody.rows[newCellRowIndex] ) ;
+		var tSection = currentCell.parentNode.parentNode ;
+		if ( tSection.rows.length > newSectionRowIdx )
+			tSection.insertBefore( newRow, tSection.rows[newSectionRowIdx] ) ;
 		else
-			tBody.appendChild( newRow ) ;
+			tSection.appendChild( newRow ) ;
 
 		// 2. +1 to rowSpan for all cells crossing currentCell's row.
@@ -616,10 +616,10 @@
 // cells that are "spanned". For example, a row with 3 cells where the second cell has colSpan=2 and rowSpan=3
 // will produce a bi-dimensional matrix with the following values (representing the cells):
-//		Cell1, Cell2, Cell2, Cell2, Cell 3
-//		Cell4, Cell2, Cell2, Cell2, Cell 5
+//		Cell1, Cell2, Cell2, Cell3
+//		Cell4, Cell2, Cell2, Cell5
+//		Cell6, Cell2, Cell2, Cell7
 FCKTableHandler._CreateTableMap = function( refCell )
 {
-	// It's really a tbody, thead or tfoot. This is only temporary.
-	var table = (refCell.nodeName == 'TABLE' ? refCell : refCell.parentNode.parentNode ) ;
+	var table = (refCell.nodeName == 'TABLE' ? refCell : refCell.parentNode.parentNode.parentNode ) ;
 
 	var aRows = table.rows ;
@@ -673,11 +673,4 @@
 	// for storing the calculated rowSpan in IE.
 	var rowSpanAttr = FCKBrowserInfo.IsIE ? "_fckrowspan" : "rowSpan" ;
-
-	// Clear the table of all rows first.
-	while ( table.rows.length > 0 )
-	{
-		var row = table.rows[0] ;
-		row.parentNode.removeChild( row ) ;
-	}
 
 	// Disconnect all the cells in tableMap from their parents, set all colSpan and rowSpan attributes to 1.
@@ -765,5 +758,13 @@
 				cell.removeAttribute( 'rowspan' ) ;
 		}
-		table.appendChild( rowObj ) ;
+		if ( FCKBrowserInfo.IsIE )
+		{
+			table.rows[i].replaceNode( rowObj ) ;
+		}
+		else
+		{
+			table.rows[i].innerHTML = '' ;
+			FCKDomTools.MoveChildren( rowObj, table.rows[i] ) ;
+		}
 	}
 }
