rem: top.editorShell.InsertElement(scriptElement,true); 
add: try { top.editorShell.InsertElementAtSelection(scriptElement,true); } catch (e) { dump("Exception occured in InsertElementAtSelection\n"); } 
context: function EditorInsertJSFile(url){    var scriptElement = top.editorShell.CreateElementWithDefaults("script");    // TODO: do some smartass string parsing to find relative file    //       location so we don't need this big chunky URLs..     //       must utilize document dirty flag.    scriptElement.setAttribute("src",url);    scriptElement.setAttribute("language","JavaScript");        top.editorShell.InsertElement(scriptElement,true);}
meta: 10234	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/10234/711c0f72c9655c2558d43bb716847f1a294b8372/sb-FileWidgetFileHandler.js/buggy/editor/ui/composer/content/sb-FileWidgetFileHandler.js