From 6075916ef18dc4a8cbea41c941d2d0b519360262 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 26 Jun 2012 13:04:04 -0700 Subject: fixed code hinting and autocompletion bug Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index f3c19b92..4572d69a 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -32,7 +32,7 @@ exports.CodeEditorController = Montage.create(Component, { if(!value) { } else if(this._currentDocument.currentView === "code") { - this.autocomplete = !this.codeCompletionSupport[this._currentDocument.model.file.extension]; + this.autocomplete = this.codeCompletionSupport[this._currentDocument.model.file.extension]; this._currentDocument.model.views.code.editor.focus(); this.applySettings(); } @@ -132,6 +132,9 @@ exports.CodeEditorController = Montage.create(Component, { }; //configure auto code completion if it is supported for that document type + + this.autocomplete = this.codeCompletionSupport[documentType]; + if(this.autocomplete) { editorOptions.onKeyEvent = function(cm, keyEvent){ -- cgit v1.2.3 From 3391a8e6fd5df0d464edaffd98c2b3fde23acf5a Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 26 Jun 2012 16:03:56 -0700 Subject: refactored to move bindings to template Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 262 ------------------------------- 1 file changed, 262 deletions(-) delete mode 100644 js/controllers/code-editor-controller.js (limited to 'js/controllers') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js deleted file mode 100644 index 4572d69a..00000000 --- a/js/controllers/code-editor-controller.js +++ /dev/null @@ -1,262 +0,0 @@ -/* -This file contains proprietary software owned by Motorola Mobility, Inc.
-No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
-(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. -
*/ - -//////////////////////////////////////////////////////////////////////// -// -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component; - -exports.CodeEditorController = Montage.create(Component, { - hasTemplate: { - value: false - }, - - _currentDocument: { - value : null - }, - - currentDocument : { - get : function() { - return this._currentDocument; - }, - set : function(value) { - if (value === this._currentDocument) { - return; - } - - this._currentDocument = value; - - if(!value) { - - } else if(this._currentDocument.currentView === "code") { - this.autocomplete = this.codeCompletionSupport[this._currentDocument.model.file.extension]; - this._currentDocument.model.views.code.editor.focus(); - this.applySettings(); - } - } - }, - - _codeEditor : { - value:null - }, - - codeEditor:{ - get: function(){return this._codeEditor;}, - set: function(value){this._codeEditor = value;} - }, - - codeCompletionSupport : { - value: {"js": true} - }, - - autocomplete: { - value: false - }, - - _automaticCodeComplete: { - value:false - }, - - automaticCodeComplete:{ - get: function(){ - return this._automaticCodeComplete; - }, - set: function(value) { - if(this._automaticCodeComplete !== value) { - this._automaticCodeComplete = value; - } - } - }, - - _editorTheme: { - value:"default" - }, - - editorTheme:{ - get: function(){ - return this._editorTheme; - }, - set: function(value){ - this._editorTheme = value; - } - }, - - _zoomFactor: { - value:100 - }, - - zoomFactor:{ - get: function() { - return this._zoomFactor; - }, - set: function(value) { - this.handleZoom(value); - } - }, - - deserializedFromTemplate: { - value: function() { - //TODO:add logic to check some configuration file to load the right code editor - this.codeEditor = CodeMirror; - } - }, - - /** - * Public method - * Creates an editor instance - */ - createEditor : { - value:function(codeDocumentView, type, documentType, textDocument){ - var self = this, editorOptions = null; - - editorOptions = { - lineNumbers: true, - matchBrackets:true, - mode: type, - onChange: function(){ - var historySize = codeDocumentView.editor.historySize(); - if(historySize.undo>0){ - textDocument.model.needsSave = true; - }else if(historySize.undo===0 && historySize.redo>0){ - textDocument.model.needsSave = false; - } - }, - onCursorActivity: function() { - codeDocumentView.editor.matchHighlight("CodeMirror-matchhighlight"); - codeDocumentView.editor.setLineClass(codeDocumentView.editor.hline, null, null); - codeDocumentView.editor.hline = codeDocumentView.editor.setLineClass(codeDocumentView.editor.getCursor().line, null, "activeline"); - } - }; - - //configure auto code completion if it is supported for that document type - - this.autocomplete = this.codeCompletionSupport[documentType]; - - if(this.autocomplete) { - - editorOptions.onKeyEvent = function(cm, keyEvent){ - self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType) - }; - - } - - return self.codeEditor.fromTextArea(codeDocumentView.textArea, editorOptions); - } - }, - - /** - * Private method - * key event handler for showing code completion dropdown - */ - _codeCompletionKeyEventHandler:{ - enumerable:false, - value: function(cm, keyEvent, documentType) { - //comment shortkeys - if((keyEvent.metaKey || keyEvent.ctrlKey) && !keyEvent.shiftKey && keyEvent.keyCode === 191){//ctrl+/ - this.commentSelection(true); - return; - } - //uncomment shortkeys - if((keyEvent.metaKey || keyEvent.ctrlKey) && keyEvent.shiftKey && keyEvent.keyCode === 191){//ctrl+shift+/ - this.commentSelection(false); - return; - } - - //===manually triggered code completion - if((this.automaticCodeComplete === false)){ - if(keyEvent.ctrlKey && keyEvent.keyCode === 32){//Ctrl+Space - this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint); - } - } - //===automatic auto complete [performance is slower] - else if(this._showAutoComplete(documentType, keyEvent)){ - this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint); - } - } - }, - - /** - * Private method - * checks for valid keyset to show code completion dropdown - */ - _showAutoComplete : { - enumerable:false, - value:function(documentType, keyEvent){ - var status=false; - - if((keyEvent.metaKey || keyEvent.ctrlKey) && (keyEvent.keyCode === 83)){//ctrl+s - return false; - } - - switch(documentType){ - case "js": - if((keyEvent.type === "keyup")//need seperate keycode set per mode - && ((keyEvent.keyCode > 47 && keyEvent.keyCode < 57)//numbers - || (keyEvent.keyCode > 64 && keyEvent.keyCode <91)//letters - || (keyEvent.keyCode === 190)//period - || (keyEvent.keyCode === 189)//underscore, dash - ) - && !(keyEvent.ctrlKey //ctrl - || keyEvent.metaKey//cmd - || (keyEvent.keyCode === 219)//open bracket [ - || (keyEvent.keyCode === 221)//close bracket ] - || (keyEvent.shiftKey && keyEvent.keyCode === 219)//open bracket { - || (keyEvent.shiftKey && keyEvent.keyCode === 221)//close bracket } - || (keyEvent.shiftKey && keyEvent.keyCode === 57)//open bracket ( - || (keyEvent.shiftKey && keyEvent.keyCode === 48)//close bracket ) - ) - ){ - status = true; - break; - } - default : - status = false; - } - - return status; - } - }, - - getSelectedRange:{ - value:function(editor){ - return { from: editor.getCursor(true), to: editor.getCursor(false) }; - } - }, - - commentSelection:{ - value: function(isComment){ - var range = this.getSelectedRange(this.currentDocument.model.views.code.editor); - this.currentDocument.model.views.code.editor.commentRange(isComment, range.from, range.to); - } - }, - - handleThemeSelection:{ - value: function(){ - this.currentDocument.model.views.code.editor.setOption("theme", this.editorTheme); - this.currentDocument.model.views.code.applyTheme("cm-s-"+this.editorTheme); - } - }, - - handleZoom:{ - value:function(value){ - var originalFont=13,originalLineHeight=16; - this._zoomFactor = value; - this.currentDocument.model.views.code.textViewContainer.style.fontSize = ""+((value/100)*originalFont)+"px"; - this.currentDocument.model.views.code.textViewContainer.style.cursor = "text"; - this.currentDocument.model.views.code.textViewContainer.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px"; - this.currentDocument.model.views.code.editor.refresh();//refresh editor display for xoom - } - }, - - applySettings:{ - value:function(){ - //set theme - this.handleThemeSelection(); - //set zoom - this.handleZoom(this._zoomFactor); - } - } -}); \ No newline at end of file -- cgit v1.2.3 From 2be81997e1ecd14ae43cf7fb243ef7ced2696bd2 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Tue, 26 Jun 2012 19:19:31 -0700 Subject: Styles Controller - Chrome 20 Fix --- js/controllers/styles-controller.js | 81 ++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 28 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 1c1e75ed..1eb7bc7f 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -604,51 +604,76 @@ var stylesController = exports.StylesController = Montage.create(Component, { getRuleIndex : { value : function(rule) { - var rules = nj.toArray(rule.parentStyleSheet.rules), - i; + var rules = nj.toArray(rule.parentStyleSheet.rules); return rules.indexOf(rule); } }, - + + _getRuleWithCSSText : { + value: function(cssText, doc) { + var _doc = doc || this.currentDocument.model.views.design._document, + ruleIndex, rule; + + for(var i = 0; i < _doc.styleSheets.length; i++) { + ruleIndex = nj.toArray(_doc.styleSheets[i].rules).map(function(rule) { + return rule.cssText; + }).indexOf(cssText); + + if(ruleIndex !== -1) { + rule = _doc.styleSheets[i].rules[ruleIndex]; + break; + } + } + + if(!rule) { + ///// This should never be hit if providing cssText from existing rule (like those + ///// returned from getMatchedCSSRules() + console.warn('StylesController::_getRuleWithCSSText - No rule found with given cssText.'); + } + + return rule; + } + }, + ///// Get All Matching Rules ///// Returns an array of css rules for an element ///// Optionally sorted by specificity, and can omit pseudo elements - getMatchingRules : { + getMatchingRules : { //TODO: Remove omitPseudos from here and usages value: function(element, omitPseudos, useStageStyleSheet) { - var pseudos = [null], - rules = [], - win = element.ownerDocument.defaultView, - self = this; - - if(!omitPseudos) { - pseudos.concat(['link', 'visited', 'active', 'hover', 'focus', 'first-letter', - 'first-line', 'first-child', 'before', 'after', 'lang', 'target']); - } + var rules, + mappedRules, + doc = element.ownerDocument, + win = doc.defaultView; try { - pseudos.forEach(function(pseudo) { - rules = rules.concat(nj.toArray(win.getMatchedCSSRules(element, pseudo)).filter(function(rule) { - //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, - //// or only use rules for other stylesheets + debugger; + + mappedRules = nj.toArray(win.getMatchedCSSRules(element)).map(function(rule) { + return this._getRuleWithCSSText(rule.cssText, doc); + }, this); - var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, - isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; + rules = mappedRules.filter(function(rule) { + //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, + //// or only use rules for other stylesheets - ///// filter out (return false) depending on flag - if(useStageStyleSheet && !isStageStyleSheet) { return false; } - if(!useStageStyleSheet && isStageStyleSheet) { return false; } + var sheetId = (rule.parentStyleSheet) ? rule.parentStyleSheet.ownerNode.id : null, + isStageStyleSheet = sheetId === this.CONST.STAGE_SHEET_ID; - ///// Non-filter code - just assigning specificity to the rule - if(!rule[this.CONST.SPECIFICITY_KEY]) { - rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); - } + ///// filter out (return false) depending on flag + if(useStageStyleSheet && !isStageStyleSheet) { return false; } + if(!useStageStyleSheet && isStageStyleSheet) { return false; } - return true; + ///// Non-filter code - just assigning specificity to the rule + if(!rule[this.CONST.SPECIFICITY_KEY]) { + rule[this.CONST.SPECIFICITY_KEY] = this.getSpecificity(rule.selectorText); + } + + return true; - }, this)); }, this); + } catch(ERROR) { console.warn('StylesController::getMatchingRules - Un-attached element queried.'); } -- cgit v1.2.3 From 31a164700e95fb9bf37169eccdb009895452b8bf Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Tue, 26 Jun 2012 20:19:32 -0700 Subject: Styles Controller - Remove debugger --- js/controllers/styles-controller.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index 1eb7bc7f..0f847653 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -648,8 +648,6 @@ var stylesController = exports.StylesController = Montage.create(Component, { win = doc.defaultView; try { - debugger; - mappedRules = nj.toArray(win.getMatchedCSSRules(element)).map(function(rule) { return this._getRuleWithCSSText(rule.cssText, doc); }, this); -- cgit v1.2.3