Edge case changing on item existance

Only look to update hints if we have at least 1 open file
We can also only determine the type of fileName for code folding if we
have a filename
The same is true for the previewWindow, can only look to do this if we
have a file open
These are all edge cases highlighted through unit testing
This commit is contained in:
Matt Pass
2013-06-10 09:53:07 +01:00
parent 13e1b933e1
commit b0dc96c888

View File

@@ -211,18 +211,20 @@ function createNewCMInstance(num) {
top.document.getElementById('results').innerHTML = top.ICEcoder.results.length + " results";
top.ICEcoder.findMode = false;
}
if (top.ICEcoder.codeAssist) {
if (top.ICEcoder.codeAssist && top.ICEcoder.openFiles.length>0) {
clearTimeout(window['cM'+num+'waiting']);
window['cM'+num+'waiting'] = setTimeout(top.ICEcoder.updateHints, 100);
}
var filepath = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
var filename = filepath.substr(filepath.lastIndexOf("/")+1);
var fileExt = filename.substr(filename.lastIndexOf(".")+1);
for (var i=changeObj.from.line; i<changeObj.from.line+changeObj.text.length; i++) {
top.ICEcoder.content.contentWindow.CodeMirror.newFoldFunction(top.ICEcoder.content.contentWindow.CodeMirror[["coffee","css","js","less","php","py","rb","ruby"].indexOf(fileExt) > -1 ? "braceRangeFinder" : "tagRangeFinder"],null,"+","-",true)(thisCM, i);
if (filepath) {
var filename = filepath.substr(filepath.lastIndexOf("/")+1);
var fileExt = filename.substr(filename.lastIndexOf(".")+1);
for (var i=changeObj.from.line; i<changeObj.from.line+changeObj.text.length; i++) {
top.ICEcoder.content.contentWindow.CodeMirror.newFoldFunction(top.ICEcoder.content.contentWindow.CodeMirror[["coffee","css","js","less","php","py","rb","ruby"].indexOf(fileExt) > -1 ? "braceRangeFinder" : "tagRangeFinder"],null,"+","-",true)(thisCM, i);
}
}
// Update HTML edited files live
if (top.ICEcoder.previewWindow.location) {
if (filepath && top.ICEcoder.previewWindow.location) {
if (top.ICEcoder.previewWindow.location.pathname==filepath) {
if (["htm","html","txt"].indexOf(fileExt) > -1) {
top.ICEcoder.previewWindow.document.documentElement.innerHTML = window['cM'+num].getValue();