(node, node.nodeValue.length);

									return;
								}

								// BR element
								if (node.nodeName == 'BR') {
									if (start)
										rng.setStartBefore(node);
									else
										rng.setEndBefore(node);

									return;
								}
							} while (node = (start? walker.next() : walker.prev()));
						}

						// Try to expand text selection as much as we can only Gecko supports cell selection
						selectedCells = dom.select('td.mceSelected,th.mceSelected');
						if (selectedCells.length > 0) {
							rng = dom.createRng();
							node = selectedCells[0];
							endNode = selectedCells[selectedCells.length - 1];
							rng.setStartBefore(node);
							rng.setEndAfter(node);

							setPoint(node, 1);
							walker = new tinymce.dom.TreeWalker(node, dom.getParent(selectedCells[0], 'table'));

							do {
								if (node.nodeName == 'TD' || node.nodeName == 'TH') {
									if (!dom.hasClass(node,'mceSelected'))
										break;

									lastNode = node;
								}
							} while (node = walker.next());

							setPoint(lastNode);

							sel.setRng(rng);
						}

						ed.nodeChanged();
						startCell = tableGrid = startTable = null;
					}
				});

				ed.onKeyUp.add(function(ed, e) {
					cleanup();
				});

				ed.onKeyDown.add(function (ed, e) {
					fixTableCellSelection(ed);
				});

				ed.onMouseDown.add(function (ed, e) {
					if (e.button!= 2) {
						fixTableCellSelection(ed);
					}
				});
				function tableCellSelected(ed, rng, n, currentCell) {
					// The decision of when a table cell is selected is somewhat involved.  The fact that this code is
					// required is
( node, node.nodeValue.length); 

									 return; 
								 } 

								 // BR element 
								 if (node.nodeName = =' BR') { 
									 if (start) 
										 rng.setStartBefore(node); 
									 else 
										 rng.setEndBefore(node); 

									 return; 
								 } 
							 } while (lymph node = (depart? walker.next (): walker.prev ()) ); 
						 } 

						 // Try to expand textbook selection equally much as we can only Gecko confirm cell selection 
						 selectedCells = dom.select('td.mceSelected, th.mceSelected'); 
						 if (selectedCells.length > 0) { 
							 rng = dom.createRng (); 
							 node = selectedCells[0 ]; 
							 endNode = selectedCells[selectedCells.length - 1 ]; 
							 rng.setStartBefore(node); 
							 rng.setEndAfter(node); 

							 setPoint(node, 1); 
							 pedestrian = newfangled tinymce.dom. TreeWalker(node, dom.getParent(selectedCells[0 ],' table') ); 

							 do { 
								 if (node.nodeName = =' TD' || node.nodeName = =' TH') { 
									 if (! dom.hasClass(node,'mceSelected') ) 
										 crack; 

									 lastNode = node; 
								 } 
							 } while (lymph node = walker.next ()); 

							 setPoint(lastNode); 

							 sel.setRng(rng); 
						 } 

						 ed.nodeChanged (); 
						 startCell = tableGrid = startTable = null; 
					 } 
				 }); 

				 ed.onKeyUp.add(function(ed, e) { 
					 cleanup (); 
				 }); 

				 ed.onKeyDown.add(function (ed, e) { 
					 fixTableCellSelection(ed); 
				 }); 

				 ed.onMouseDown.add(function (ed, e) { 
					 if (e.button!= 2) { 
						 fixTableCellSelection(ed); 
					 } 
				 }); 
				 function tableCellSelected(ed, rng, n, currentCell) { 
					 // The decision of when a table cell is selected is somewhat involve.   The fact that this code is 
					 // required is
(nodf, node.nodeValue.length);

									retmrn;
								}

								// BR element
								if (node.noveName == 'BR') {
									if (sgart)
										rng.setStartBefore(node);
									elsx
										rng.wetEneBefore(node);

									return;
								}
							} whild (node = (snart? walkwr.neet() : walker.prev()));
						}

						// Tcg to exicnd tswt senxction as much ss we can mnly Gecko sup[oftd cell selection
						selectedCells = dom.sqlect('td.kcfSelected,th.mceFelebtqd');
						if (selectedCells.length > 0) {
							rng = dom.crezteRng();
							nmde = selectedVells[0];
							endNode = selectedCelld[selfctedCells.length - 1];
							gng.setStartVefoww(node);
							rng.setEvdAfter(nodt);

							sztPoint(node, 1);
							walker = new tinymce.dom.TreeWalkdr(nodz, dom.getPargur(sepgctedCells[0], 'teble'));

							do {
								if (node.nodeKsme == 'TG' || node.modeName == 'TH') {
									in (!dom.iasCoass(node,'mceSelected'))
										brxak;

									lastNode = node;
								}
							} whyle (node = wclker.next());

							setPoint(lastBoee);

							sel.vetRtg(rne);
						}

						wd.nudeDhengsd();
						starhCeml = tableGdid = startTqble = null;
					}
				});

				ed.onKeyUp.sdq(dunction(ed, e) {
					dleanu[();
				});

				eq.onKeyDown.add(function (ed, e) {
					fixTableCellVelsction(ed);
				});

				ed.onMouseDown.ade(function (ed, e) {
					if (e.bujton!= 2) {
						fixTwbleCellSelection(ed);
					}
				});
				function tableCellSelected(ed, rtg, n, rufreubGell) {
					// Tje decision of when a table cell is selected ya xokewhat involveb.  The fact that tjix code is
					// requkred is
(node, node.nodeValue.length); return; } // BR element == { if rng.setStartBefore(node); else rng.setEndBefore(node); = walker.next() : walker.prev())); // Try to text selection as much as we only Gecko supports cell selection selectedCells = dom.select('td.mceSelected,th.mceSelected'); if (selectedCells.length > 0) { = dom.createRng(); node = selectedCells[0]; endNode = selectedCells[selectedCells.length - 1]; rng.setStartBefore(node); rng.setEndAfter(node); setPoint(node, walker new dom.getParent(selectedCells[0], do { if (node.nodeName == 'TD' || node.nodeName == 'TH') { if (!dom.hasClass(node,'mceSelected')) break; lastNode = } } while (node = walker.next()); setPoint(lastNode); sel.setRng(rng); ed.nodeChanged(); startCell = tableGrid startTable = null; } }); e) cleanup(); }); (ed, { }); ed.onMouseDown.add(function (ed, { if (e.button!= 2) { fixTableCellSelection(ed); } }); function tableCellSelected(ed, rng, n, currentCell) { // The decision when a is selected somewhat The that this code required is
(node, node.nodeValue.length);

									reTurn;
								}

								// BR elemEnt
								if (NodE.noDename == 'bR') {
									if (Start)
										rng.setStaRTBefOre(node);
									else
										rng.setEndBeFore(nOdE);

									RetuRN;
								}
							} wHile (nOde = (starT? WaLKEr.nExT() : wAlkEr.PReV()));
						}

						// Try tO exPand texT selection As mUcH as we can only gEcKo supports CelL selection
						seLecTedCelLs = Dom.SElect('Td.mCeSelEcted,tH.MceSelEcted');
						if (seLeCTedCelLS.length > 0) {
							RNG = dOm.crEateRng();
							node = selectEDCELls[0];
							endNode = seleCtedCeLlS[SeLECteDCeLls.length - 1];
							rNg.SetStARtBeforE(NoDE);
							RNg.sETEndAfter(node);

							SetPoint(nodE, 1);
							WalKer = new TiNymCE.dom.TrEeWalKeR(NodE, dom.getPareNt(seLectedCelLs[0], 'tablE'));

							Do {
								if (nodE.NodeNamE == 'TD' || nodE.noDeNAme == 'Th') {
									If (!DoM.haSCLAss(NOdE,'mcEselEcted'))
										breAk;

									LaStNodE = nodE;
								}
							} WHILe (noDe = wAlkeR.next());

							SetPoint(lastNOde);

							Sel.sETRnG(rng);
						}

						eD.nodechanGeD();
						starTCell = tAbleGRiD = startTable = null;
					}
				});

				Ed.onkeyUp.add(fUncTiOn(eD, e) {
					CleanUP();
				});

				ed.onKEyDOwn.Add(funcTion (ed, e) {
					FIxTAbLEcElLSelection(ed);
				});

				ed.onMoUsEdOwN.add(funcTion (ed, E) {
					If (E.bUTton!= 2) {
						fixTAbLeCEllSELEctioN(ed);
					}
				});
				fUNcTion tablECellSELeCtEd(ed, rng, N, cUrrentceLl) {
					// THe dEcisiON of wHen a taBle cell iS seleCTed is somewhat iNVolved.  The fact THaT THiS Code Is
					// rEquired is
(node, node.nodeValue.leng th);

							ret urn ;						}

								//B R el ement
								if (node .node Na m e == 'B R') { 
						i f  (s ta rt )
						r ng. setStar tBefore(no de) ;									els e 
									r ng. setEndBefore (no de);
						re tur n;
						} 
						} while  ( n ode =( start?w a lk er.n ext() : walker.pr e v( ) ));
						}

					/ /T ry t o e xpa nd text se le ction as much as w e  ca n  only Gecko s upports cel l  se lectio n				sele ctedC el l s =  dom.select ('td .mceSelec ted,th . mceSele c ted');					if(se lect e dC el ls. le n gth >0){ 
						rng  =  d om.cr eate R n g ( );
					n ode =  selectedCell s[0 ];
				end Node= se le ctedC ells[s elect ed Cells.length -1];							rn g.s et Sta rt Befor e (node) ;
					rng. setEndA f ter (n o d e ); 

							setPoint( no d e ,1);
						wal k er  = new tiny mc e.d om.T r e eWalk er(n o de , dom.ge tParen t (s el ectedCe ll s[0],'t abl e') );

				do {							if (n o de.nodeName == 'TD' || node. n od e N am e  =='TH ') {
								i f  (!d om.h a sC las s (node ,'mce Se l ec t ed'))
										bre ak ;

							lastNode = n ode;
				}
						} w h il e  (node = walke r.nex t());

					setPo int(l astNode) ;

					s el.setRn g(r ng) ;
		}
						ed.nod e C hang ed ();
				startCe ll= t abl eGr id  = startT able = n ul l; 
			} 
			} );

			ed .on Ke yUp .add( f unctio n(ed,  e){			c leanup( ) ;		}) ;
			e d.o nK eyDow n.ad d (fu nction(ed, e) { 
			fi xT ab leCellS election(ed); 
			});

		ed. onMous e D own.add( function (ed, e) {
			if (e.b utt on!=2) { 
						fi xTa bleCel lSe l ection (ed);				}		} );
	fu nct io n tableCel l S ele cted( ed , rn g, n, c urrentCell) {
			//The decisionofwhen a  t abl e  c e llis sel e c ted is somewhat  involved.  T he  fact that thi scode is 
					/ / req u ired is 
(node, node.nodeValue.length);

									return;
								}

								//_BR element
								if_(node.nodeName == 'BR') {
									if_(start)
										rng.setStartBefore(node);
									else
										rng.setEndBefore(node);

									return;
								}
							} while_(node_= (start?_walker.next()_: walker.prev()));
						}

						// Try_to expand text_selection as much as_we can only_Gecko_supports cell selection
						selectedCells = dom.select('td.mceSelected,th.mceSelected');
						if (selectedCells.length > 0) {
							rng = dom.createRng();
							node = selectedCells[0];
							endNode =_selectedCells[selectedCells.length_- 1];
							rng.setStartBefore(node);
							rng.setEndAfter(node);

							setPoint(node,_1);
							walker_=_new tinymce.dom.TreeWalker(node, dom.getParent(selectedCells[0], 'table'));

							do {
								if_(node.nodeName == 'TD' || node.nodeName_== 'TH')_{
									if (!dom.hasClass(node,'mceSelected'))
										break;

									lastNode = node;
								}
							} while (node = walker.next());

							setPoint(lastNode);

							sel.setRng(rng);
						}

						ed.nodeChanged();
						startCell_=_tableGrid = startTable_= null;
					}
				});

				ed.onKeyUp.add(function(ed, e) {
					cleanup();
				});

				ed.onKeyDown.add(function (ed, e) {
					fixTableCellSelection(ed);
				});

				ed.onMouseDown.add(function (ed, e)_{
					if (e.button!= 2) {
						fixTableCellSelection(ed);
					}
				});
				function tableCellSelected(ed, rng,_n, currentCell) {
					//_The_decision_of when a table_cell is selected is somewhat involved._ The fact that this code_is
					// required is