From dece82791f43b5e8d278aba89cf8d6119af1478f Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 9 Apr 2012 13:11:40 -0700 Subject: - Decouple code editor from stage document switching logic - cleaning up Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 79 ++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 js/controllers/code-editor-controller.js (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js new file mode 100644 index 00000000..23bd9279 --- /dev/null +++ b/js/controllers/code-editor-controller.js @@ -0,0 +1,79 @@ +/* +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; + +var CodeEditorController = exports.CodeEditorController = Montage.create(Component, { + hasTemplate: { + value: false + }, + + _codeEditor : { + value:null + }, + + codeEditor:{ + get: function(){return this._codeEditor;}, + set: function(value){this._codeEditor = value;} + }, + + deserializedFromTemplate: { + value: function() { + //TODO:add logic to check some configuration file to load the right code editor + this.codeEditor = CodeMirror; + } + }, + + createEditor : { + value:function(doc, type){ + var self = this; + var editor = self.codeEditor.fromTextArea(doc.textArea, { + lineNumbers: true, + matchBrackets:true, + mode: type, + onChange: function(){ + var historySize = doc.editor.historySize(); + if(historySize.undo>0){ + doc.needsSave = true; + }else if(historySize.undo===0 && historySize.redo>0){ + doc.needsSave = false; + } + }, + onCursorActivity: function() { + doc.editor.matchHighlight("CodeMirror-matchhighlight"); + doc.editor.setLineClass(doc.editor.hline, null, null); + doc.editor.hline = doc.editor.setLineClass(doc.editor.getCursor().line, null, "activeline"); + }, + //extraKeys: {"Ctrl-Space": function(cm) {CodeMirror.simpleHint(cm, CodeMirror.javascriptHint);}} + onKeyEvent: function(cm, keyEvent) { + 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.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 ) + ) + ){ + + self.codeEditor.simpleHint(cm, self.codeEditor.javascriptHint); + } + } + }); + + return editor; + } + } + +}); \ No newline at end of file -- cgit v1.2.3 From 6ffda1a7ebe18adb518eb24a612df22305b050a6 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 9 Apr 2012 17:15:41 -0700 Subject: - added configurability of code completion with the file type - added logic to toggle between automatic code completion and manually triggered code completion [ UI pending ] Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 100 ++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 23 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 23bd9279..0c13958c 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -23,6 +23,18 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone set: function(value){this._codeEditor = value;} }, + codeCompletionSupport : {"javascript": true}, + + _automaticCodeComplete: { + value:true + }, + + automaticCodeComplete:{ + get: function(){return this._automaticCodeComplete;}, + set: function(value){this._automaticCodeComplete = value;} + }, + + deserializedFromTemplate: { value: function() { //TODO:add logic to check some configuration file to load the right code editor @@ -30,10 +42,15 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone } }, + /** + * Public method + * Creates an editor instance + */ createEditor : { value:function(doc, type){ - var self = this; - var editor = self.codeEditor.fromTextArea(doc.textArea, { + var self = this, editorOptions = null; + + editorOptions = { lineNumbers: true, matchBrackets:true, mode: type, @@ -49,31 +66,68 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone doc.editor.matchHighlight("CodeMirror-matchhighlight"); doc.editor.setLineClass(doc.editor.hline, null, null); doc.editor.hline = doc.editor.setLineClass(doc.editor.getCursor().line, null, "activeline"); - }, - //extraKeys: {"Ctrl-Space": function(cm) {CodeMirror.simpleHint(cm, CodeMirror.javascriptHint);}} - onKeyEvent: function(cm, keyEvent) { - 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.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 ) - ) - ){ - - self.codeEditor.simpleHint(cm, self.codeEditor.javascriptHint); - } } - }); + }; + //configure auto code completion if it is supported for that document type + if(true){ + editorOptions.onKeyEvent = function(cm, keyEvent){self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, type)}; + } + + var editor = self.codeEditor.fromTextArea(doc.textArea, editorOptions); return editor; } + }, + + /** + * Private method + * key event handler for showing code completion dropdown + */ + _codeCompletionKeyEventHandler:{ + enumerable:false, + value: function(cm, keyEvent, type) { + //===manually triggered code completion + if((this.automaticCodeComplete === false)){ + if((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 32){//Ctrl-Space + this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint); + } + } + //===automatic auto complete [performance is slower] + else if(this._showAutoComplete(type, keyEvent)){ + this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint); + } + } + }, + + /** + * Private method + * checks for valid keyset to show code completion dropdown + */ + _showAutoComplete : { + enumerable:false, + value:function(type, keyEvent){ + switch(type){ + case "javascript": + 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.keyCode === 219)//open bracket [ + || (keyEvent.ctrlKey || keyEvent.metaKey)//ctrl + || (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 ) + || ((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 83)//ctrl+S + ) + ){return true;} + default : + return false; + } + } } }); \ No newline at end of file -- cgit v1.2.3 From c2ec390d42945d2df1aed3f2b7ff3d1aa722fce8 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 13 Apr 2012 16:51:50 -0700 Subject: - code editor view options bar - Checkbox for user to toggle between manually triggered autocomplete and automatic autocomplete - font zoom hottext Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 45 +++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 0c13958c..534d4645 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -23,17 +23,37 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone set: function(value){this._codeEditor = value;} }, - codeCompletionSupport : {"javascript": true}, + codeCompletionSupport : { + value: {"javascript": true} + }, _automaticCodeComplete: { value:true }, automaticCodeComplete:{ - get: function(){return this._automaticCodeComplete;}, - set: function(value){this._automaticCodeComplete = value;} - }, + get: function(){return this._automaticCodeComplete;}, + set: function(value){ + //console.log("$$$ automaticCodeComplete setter : "+value); + this._automaticCodeComplete = value;} + }, + + originalEditorFont:{ + value:"13"//px + }, + _editorFont:{ + value:null + }, + + editorFont:{ + get: function(){return this._editorFont;}, + set: function(value){//gets a zoom % + this._editorFont = (value/100) * CodeEditorController.originalEditorFont; + //set the font size + document.getElementsByClassName("codeViewContainer")[0].style.fontSize = ""+this._editorFont+"px"; + } + }, deserializedFromTemplate: { value: function() { @@ -70,11 +90,14 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone }; //configure auto code completion if it is supported for that document type - if(true){ + if(this.codeCompletionSupport[type] === true){ editorOptions.onKeyEvent = function(cm, keyEvent){self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, type)}; } var editor = self.codeEditor.fromTextArea(doc.textArea, editorOptions); + + //editor.setOption("theme", "night"); + return editor; } }, @@ -128,6 +151,16 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone return false; } } - } + }, + handleCodeCompletionSupport:{ + value:function(fileType){ + var autoCodeCompleteElem = document.getElementsByClassName("autoCodeComplete")[0]; + if(autoCodeCompleteElem && (this.codeCompletionSupport[fileType] === true)){ + autoCodeCompleteElem.style.visibility = "visible"; + }else if(autoCodeCompleteElem && !this.codeCompletionSupport[fileType]){ + autoCodeCompleteElem.style.visibility = "hidden"; + } + } + } }); \ No newline at end of file -- cgit v1.2.3 From 2449fc403e8a8a22f092c87e3268a69a2be67e43 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 16 Apr 2012 18:19:17 -0700 Subject: Added comment and uncomment control in the editor view options Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 534d4645..52eb47eb 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -162,5 +162,26 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone autoCodeCompleteElem.style.visibility = "hidden"; } } + }, + + getSelectedRange:{ + value:function(editor){ + return { from: editor.getCursor(true), to: editor.getCursor(false) }; + } + }, + + autoFormatSelection:{ + value: function(){ + var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.editor); + this.application.ninja.documentController.activeDocument.editor.autoFormatRange(range.from, range.to); + } + }, + + commentSelection:{ + value: function(isComment){ + var range = this.getSelectedRange(this.application.ninja.documentController.activeDocument.editor); + this.application.ninja.documentController.activeDocument.editor.commentRange(isComment, range.from, range.to); + } } + }); \ No newline at end of file -- cgit v1.2.3 From 1f891c58bad0b7746659aa4138001b5ee76d9a0e Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 17 Apr 2012 18:10:39 -0700 Subject: added theme choices for editor Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 52eb47eb..cf0503a0 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -49,9 +49,13 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone editorFont:{ get: function(){return this._editorFont;}, set: function(value){//gets a zoom % + var codeLineElems = null, i=0; this._editorFont = (value/100) * CodeEditorController.originalEditorFont; //set the font size - document.getElementsByClassName("codeViewContainer")[0].style.fontSize = ""+this._editorFont+"px"; + codeLineElems = document.getElementsByClassName("CodeMirror-lines"); + for(i=0;i --- js/controllers/code-editor-controller.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index cf0503a0..2302730c 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -33,9 +33,16 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone automaticCodeComplete:{ get: function(){return this._automaticCodeComplete;}, - set: function(value){ - //console.log("$$$ automaticCodeComplete setter : "+value); - this._automaticCodeComplete = value;} + set: function(value){this._automaticCodeComplete = value;} + }, + + _editorTheme: { + value:"default" + }, + + editorTheme:{ + get: function(){return this._editorTheme;}, + set: function(value){this._editorTheme = value;} }, originalEditorFont:{ @@ -189,9 +196,8 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone }, handleThemeSelection:{ - value: function(theme){ - this.application.ninja.documentController.activeDocument.editor.setOption("theme", theme); + value: function(){ + this.application.ninja.documentController.activeDocument.editor.setOption("theme", this.editorTheme); } } - }); \ No newline at end of file -- cgit v1.2.3 From 8cd6c76aabb4c75ab63f8d46b7e89bddbcbfe2a7 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 19 Apr 2012 10:38:43 -0700 Subject: - fixed the text cursor - code cleanup Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 2302730c..8757dceb 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -199,5 +199,18 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone value: function(){ this.application.ninja.documentController.activeDocument.editor.setOption("theme", this.editorTheme); } + }, + + applySettings:{ + value:function(){ + var codeLineElem = null, i=0; + //set theme + this.handleThemeSelection(); + //check autocomplete support + this.handleCodeCompletionSupport(this.application.ninja.documentController.activeDocument.editor.getOption("mode")); + //set zoom + codeLineElem = this.application.ninja.documentController.activeDocument.container.getElementsByClassName("CodeMirror-lines")[0]; + codeLineElem.style.fontSize = ""+this._editorFont+"px"; + } } }); \ No newline at end of file -- cgit v1.2.3 From 3bdd4919ee39759ae6f532d7f3494ca3d97b7255 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 19 Apr 2012 17:02:56 -0700 Subject: - disable autocompletion option for unsupported file type Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 8757dceb..5dee4ab2 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -166,11 +166,31 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone handleCodeCompletionSupport:{ value:function(fileType){ - var autoCodeCompleteElem = document.getElementsByClassName("autoCodeComplete")[0]; - if(autoCodeCompleteElem && (this.codeCompletionSupport[fileType] === true)){ - autoCodeCompleteElem.style.visibility = "visible"; - }else if(autoCodeCompleteElem && !this.codeCompletionSupport[fileType]){ - autoCodeCompleteElem.style.visibility = "hidden"; + var autoCodeCompleteElem = document.getElementsByClassName("autoCodeComplete")[0], elems=null, i=0; + if(autoCodeCompleteElem){ + elems = autoCodeCompleteElem.getElementsByTagName("*"); + } + + if(elems && (this.codeCompletionSupport[fileType] === true)){ + //enable elements + for(i=0;i --- js/controllers/code-editor-controller.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 5dee4ab2..08320db7 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -218,6 +218,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone handleThemeSelection:{ value: function(){ this.application.ninja.documentController.activeDocument.editor.setOption("theme", this.editorTheme); + this.application.ninja.stage.stageView.applyTheme("cm-s-"+this.editorTheme); } }, -- cgit v1.2.3 From 78b87d056fd2f43e9e8801c859274a1b00b35c33 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 23 Apr 2012 15:58:33 -0700 Subject: IKNINJA-1529 : zooming to fix font overlap issue Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 08320db7..683cbd94 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -45,24 +45,15 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone set: function(value){this._editorTheme = value;} }, - originalEditorFont:{ - value:"13"//px - }, - - _editorFont:{ + _zoomFactor:{ value:null }, - editorFont:{ - get: function(){return this._editorFont;}, - set: function(value){//gets a zoom % - var codeLineElems = null, i=0; - this._editorFont = (value/100) * CodeEditorController.originalEditorFont; - //set the font size - codeLineElems = document.getElementsByClassName("CodeMirror-lines"); - for(i=0;i --- js/controllers/code-editor-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 683cbd94..8d7e3117 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -28,7 +28,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone }, _automaticCodeComplete: { - value:true + value:false }, automaticCodeComplete:{ -- cgit v1.2.3 From a7548b4c53de8f42cb5e0fb1c054eba6f7c45afb Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 24 Apr 2012 16:45:47 -0700 Subject: IKNINJA-1529 : zooming such that cursor position can be calculated accurately Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 8d7e3117..bce6f410 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -46,14 +46,13 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone }, _zoomFactor:{ - value:null + value:100 }, zoomFactor:{ get: function(){return this._zoomFactor;}, set: function(value){ - this._zoomFactor = value; - this.application.ninja.documentController.activeDocument.container.style.zoom = ""+value+"%"; + this.handleZoom(value); } }, @@ -113,7 +112,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone value: function(cm, keyEvent, type) { //===manually triggered code completion if((this.automaticCodeComplete === false)){ - if((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 32){//Ctrl-Space + if((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 32){//Ctrl+Space this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint); } } @@ -147,6 +146,9 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone || (keyEvent.shiftKey && keyEvent.keyCode === 57)//open bracket ( || (keyEvent.shiftKey && keyEvent.keyCode === 48)//close bracket ) || ((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 83)//ctrl+S + || ((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 90)//ctrl+z + || ((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.shiftKey && keyEvent.keyCode === 90)//ctrl+shift+z + || ((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 89)//ctrl+y ) ){return true;} default : @@ -213,6 +215,17 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone } }, + handleZoom:{ + value:function(value){ + var originalFont=13,originalLineHeight=16; + this._zoomFactor = value; + this.application.ninja.documentController.activeDocument.container.style.fontSize = ""+((value/100)*originalFont)+"px"; + this.application.ninja.documentController.activeDocument.container.style.cursor = "text"; + this.application.ninja.documentController.activeDocument.container.querySelector(".CodeMirror").style.lineHeight = ""+((value/100)*originalLineHeight)+"px"; + this.application.ninja.documentController.activeDocument.editor.refresh();//refresh editor display for xoom + } + }, + applySettings:{ value:function(){ //set theme @@ -220,7 +233,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone //check autocomplete support this.handleCodeCompletionSupport(this.application.ninja.documentController.activeDocument.editor.getOption("mode")); //set zoom - this.application.ninja.documentController.activeDocument.container.style.zoom = ""+this.zoomFactor+"%"; + this.handleZoom(this._zoomFactor); } } }); \ No newline at end of file -- cgit v1.2.3 From 45bddda788afc27094b781d0823f821a421e0934 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 25 Apr 2012 14:18:09 -0700 Subject: - use on ctrl+space for code hinting - use prototype in serialization for montage 0.8 Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index bce6f410..ab0521eb 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -112,7 +112,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone value: function(cm, keyEvent, type) { //===manually triggered code completion if((this.automaticCodeComplete === false)){ - if((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 32){//Ctrl+Space + if(keyEvent.ctrlKey && keyEvent.keyCode === 32){//Ctrl+Space this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint); } } -- cgit v1.2.3 From b680af490b9736d16ed491c999af3f06d78a7d18 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 26 Apr 2012 12:26:31 -0700 Subject: IKNINJA-1551 - added editor support for other file types Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index ab0521eb..d560e721 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -130,6 +130,10 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone _showAutoComplete : { enumerable:false, value:function(type, keyEvent){ + var status=false; + if(((keyEvent.keyCode === 83) && (keyEvent.ctrlKey || keyEvent.metaKey))){ + debugger; + } switch(type){ case "javascript": if((keyEvent.type === "keyup")//need seperate keycode set per mode @@ -145,15 +149,19 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone || (keyEvent.shiftKey && keyEvent.keyCode === 221)//close bracket } || (keyEvent.shiftKey && keyEvent.keyCode === 57)//open bracket ( || (keyEvent.shiftKey && keyEvent.keyCode === 48)//close bracket ) - || ((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 83)//ctrl+S - || ((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 90)//ctrl+z - || ((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.shiftKey && keyEvent.keyCode === 90)//ctrl+shift+z - || ((keyEvent.ctrlKey || keyEvent.metaKey) && keyEvent.keyCode === 89)//ctrl+y + || ((keyEvent.keyCode === 83) && (keyEvent.ctrlKey || keyEvent.metaKey))//ctrl+S + || ((keyEvent.keyCode === 90) && (keyEvent.ctrlKey || keyEvent.metaKey))//ctrl+z + || ((keyEvent.keyCode === 89) && (keyEvent.ctrlKey || keyEvent.metaKey))//ctrl+y ) - ){return true;} + ){ + status = true; + break; + } default : - return false; + status = false; } + + return status; } }, -- cgit v1.2.3 From 07c611323c109aaa2208ebc15a354b81c3f04a0d Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 26 Apr 2012 12:55:33 -0700 Subject: removing debugger Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index d560e721..f4ca6018 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -131,9 +131,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone enumerable:false, value:function(type, keyEvent){ var status=false; - if(((keyEvent.keyCode === 83) && (keyEvent.ctrlKey || keyEvent.metaKey))){ - debugger; - } + switch(type){ case "javascript": if((keyEvent.type === "keyup")//need seperate keycode set per mode -- cgit v1.2.3 From 1314a030f5f883e2222958aa2ba1b8c031be9364 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 27 Apr 2012 17:12:37 -0700 Subject: added key shortcuts' list dropdown in view option bar Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index f4ca6018..0223165f 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -140,16 +140,14 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone || (keyEvent.keyCode === 190)//period || (keyEvent.keyCode === 189)//underscore, dash ) - && !( (keyEvent.keyCode === 219)//open bracket [ - || (keyEvent.ctrlKey || keyEvent.metaKey)//ctrl + && !(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 ) - || ((keyEvent.keyCode === 83) && (keyEvent.ctrlKey || keyEvent.metaKey))//ctrl+S - || ((keyEvent.keyCode === 90) && (keyEvent.ctrlKey || keyEvent.metaKey))//ctrl+z - || ((keyEvent.keyCode === 89) && (keyEvent.ctrlKey || keyEvent.metaKey))//ctrl+y ) ){ status = true; -- cgit v1.2.3 From aa35d31fa94f844586581c770913858bd15af505 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 30 Apr 2012 11:23:33 -0700 Subject: IKNINJA-1537 - don't show code hinting for ctrl+S IKNINJA-1568 - code hinting not supported for son files Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 0223165f..4a08aa32 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -24,7 +24,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone }, codeCompletionSupport : { - value: {"javascript": true} + value: {"js": true} }, _automaticCodeComplete: { @@ -68,7 +68,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone * Creates an editor instance */ createEditor : { - value:function(doc, type){ + value:function(doc, type, documentType){ var self = this, editorOptions = null; editorOptions = { @@ -91,8 +91,8 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone }; //configure auto code completion if it is supported for that document type - if(this.codeCompletionSupport[type] === true){ - editorOptions.onKeyEvent = function(cm, keyEvent){self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, type)}; + if(this.codeCompletionSupport[documentType] === true){ + editorOptions.onKeyEvent = function(cm, keyEvent){self._codeCompletionKeyEventHandler.call(self, cm, keyEvent, documentType)}; } var editor = self.codeEditor.fromTextArea(doc.textArea, editorOptions); @@ -109,7 +109,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone */ _codeCompletionKeyEventHandler:{ enumerable:false, - value: function(cm, keyEvent, type) { + value: function(cm, keyEvent, documentType) { //===manually triggered code completion if((this.automaticCodeComplete === false)){ if(keyEvent.ctrlKey && keyEvent.keyCode === 32){//Ctrl+Space @@ -117,7 +117,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone } } //===automatic auto complete [performance is slower] - else if(this._showAutoComplete(type, keyEvent)){ + else if(this._showAutoComplete(documentType, keyEvent)){ this.codeEditor.simpleHint(cm, this.codeEditor.javascriptHint); } } @@ -129,11 +129,15 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone */ _showAutoComplete : { enumerable:false, - value:function(type, keyEvent){ + value:function(documentType, keyEvent){ var status=false; - switch(type){ - case "javascript": + 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 @@ -235,7 +239,7 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone //set theme this.handleThemeSelection(); //check autocomplete support - this.handleCodeCompletionSupport(this.application.ninja.documentController.activeDocument.editor.getOption("mode")); + this.handleCodeCompletionSupport(this.application.ninja.documentController.activeDocument.documentType); //set zoom this.handleZoom(this._zoomFactor); } -- cgit v1.2.3 From d548103df7dd1015581d30ebf245003443b47d15 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 30 Apr 2012 13:42:01 -0700 Subject: added shortkeys for commenting and uncomment Signed-off-by: Ananya Sen --- js/controllers/code-editor-controller.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'js/controllers/code-editor-controller.js') diff --git a/js/controllers/code-editor-controller.js b/js/controllers/code-editor-controller.js index 4a08aa32..7913cfc1 100644 --- a/js/controllers/code-editor-controller.js +++ b/js/controllers/code-editor-controller.js @@ -110,6 +110,17 @@ var CodeEditorController = exports.CodeEditorController = Montage.create(Compone _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 -- cgit v1.2.3