Example #1
0
    this.createSingleLineAceEditor = function(el) {
        var renderer = new VirtualRenderer(el);

        renderer.screenToTextCoordinates = function(x, y) {
            var pos = this.pixelToScreenCoordinates(x, y);
            return this.session.screenToDocumentPosition(
                Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)),
                Math.max(pos.column, 0)
            );
        };

        renderer.setOption("maxLines", 4);

        renderer.setStyle("ace_one-line");
        var editor = new Editor(renderer);
        new MultiSelect(editor);
        editor.session.setUndoManager(new UndoManager());

        editor.setHighlightActiveLine(false);
        editor.setShowPrintMargin(false);
        editor.renderer.setShowGutter(false);
        editor.renderer.setHighlightGutterLine(false);

        editor.$mouseHandler.$focusWaitTimout = 0;
        
        editor.setReadOnly = function(readOnly) {
            if (this.$readOnly != readOnly) {
                this.codebox.$ext.style.pointerEvents = readOnly ? "none" : "";
            }
            this.setOption("readOnly", readOnly);
        };

        return editor;
    },
Example #2
0
File: layout.js Project: 1ec5/ace
exports.singleLineEditor = function(el) {
    var renderer = new Renderer(el);
    el.style.overflow = "hidden";

    renderer.screenToTextCoordinates = function(x, y) {
        var pos = this.pixelToScreenCoordinates(x, y);
        return this.session.screenToDocumentPosition(
            Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)),
            Math.max(pos.column, 0)
        );
    };

    renderer.$maxLines = 4;

    renderer.setStyle("ace_one-line");
    var editor = new Editor(renderer);
    new MultiSelect(editor);
    editor.session.setUndoManager(new UndoManager());

    editor.setShowPrintMargin(false);
    editor.renderer.setShowGutter(false);
    editor.renderer.setHighlightGutterLine(false);
    editor.$mouseHandler.$focusWaitTimout = 0;

    return editor;
};
Example #3
0
 buildAce: function buildAce() {
   var doc, editor, env, self = this,
   target = this.pre[0];
   
   // set up ace editor
   this.doc = doc = new EditSession(Dom.getInnerText(target));
   doc.setUndoManager(new UndoManager());
   this.pre.html('');
   
   // textmate theme by default
   this.editor = editor = new Editor(new Renderer(target, "ace/theme/textmate"));
   editor.setSession(doc);
   
   env = Env.create();
   
   catalog.startupPlugins({ env: env }).then(function() {
     env.document = doc;
     env.editor = editor;
     editor.resize();
     Event.addListener(window, "resize", function() {
       editor.resize();
     });
     self.dom.env = env;
   });
   
   // Store env on editor such that it can be accessed later on from
   // the returned object.
   editor.env = env;
   
   return this;
 },
Example #4
0
File: ace.js Project: chone/ace
    exports.edit = function(el) {
        if (typeof(el) == "string") {
            el = document.getElementById(el);
        }

        var doc = new EditSession(Dom.getInnerText(el));
        doc.setUndoManager(new UndoManager());
        el.innerHTML = '';

        var editor = new Editor(new Renderer(el, require("ace/theme/textmate")));
        editor.setSession(doc);

        var env = require("pilot/environment").create();
        catalog.startupPlugins({ env: env }).then(function() {
            env.document = doc;
            env.editor = editor;
            editor.resize();
            Event.addListener(window, "resize", function() {
                editor.resize();
            });
            el.env = env;
        });
        // Store env on editor such that it can be accessed later on from
        // the returned object.
        editor.env = env;
        return editor;
    };
Example #5
0
    "test: delete line from the middle" : function() {
        var session = new EditSession(["a", "b", "c", "d"].join("\n"));
        var editor = new Editor(new MockRenderer(), session);

        editor.moveCursorTo(1, 1);
        editor.removeLines();

        assert.equal(session.toString(), "a\nc\nd");
        assert.position(editor.getCursorPosition(), 1, 0);

        editor.removeLines();

        assert.equal(session.toString(), "a\nd");
        assert.position(editor.getCursorPosition(), 1, 0);

        editor.removeLines();

        assert.equal(session.toString(), "a\n");
        assert.position(editor.getCursorPosition(), 1, 0);

        editor.removeLines();

        assert.equal(session.toString(), "a\n");
        assert.position(editor.getCursorPosition(), 1, 0);
    },
Example #6
0
        edit: function(el) {
            if (typeof(el) == "string") {
                el = document.getElementById(el);
            }
            
            var doc = new EditSession(Dom.getInnerText(el));
            doc.setMode(new JavaScriptMode());
            doc.setUndoManager(new UndoManager());
            el.innerHTML = '';

            var editor = new Editor(new Renderer(el, "ace/theme/textmate"));
            editor.setSession(doc);
            
            var env = require("pilot/environment").create();
            catalog.startupPlugins({ env: env }).then(function() {
                env.document = doc;
                env.editor = env;
                editor.resize();
                Event.addListener(window, "resize", function() {
                    editor.resize();
                });
                el.env = env;
            });
            return editor;
        }
Example #7
0
    "test: remove left should remove character left of the cursor" : function() {
        var session = new EditSession(["123", "456"]);

        var editor = new Editor(new MockRenderer(), session);
        editor.moveCursorTo(1, 1);
        editor.removeLeft();
        assert.equal(session.toString(), "123\n56");
    },
Example #8
0
    "test: remove left should remove line break if cursor is at line start" : function() {
        var session = new EditSession(["123", "456"]);

        var editor = new Editor(new MockRenderer(), session);
        editor.moveCursorTo(1, 0);
        editor.removeLeft();
        assert.equal(session.toString(), "123456");
    },
Example #9
0
 "test: transpose should move the cursor behind the last swapped character": function() {
     var session = new EditSession(["123", "4567", "89"]);
     
     var editor = new Editor(new MockRenderer(), session);
     editor.moveCursorTo(1, 2);
     editor.transposeLetters();
     assert.position(editor.getCursorPosition(), 1, 3);        
 }
Example #10
0
 "test: remove to line end": function() {
     var session = new EditSession(["123", "4567", "89"]);
     
     var editor = new Editor(new MockRenderer(), session);
     editor.moveCursorTo(1, 2);
     editor.removeToLineEnd();
     assert.equal(session.getValue(), ["123", "45", "89"].join("\n"));
 },
Example #11
0
    "test: no auto indent if cursor is before the {" : function() {
        var session = new EditSession("{", new JavaScriptMode());
        var editor = new Editor(new MockRenderer(), session);

        editor.moveCursorTo(0, 0);
        editor.onTextInput("\n");
        assert.equal(["", "{"].join("\n"), session.toString());
    },
Example #12
0
    "test: navigate to start of file should scroll the first row into view" : function() {
        var doc = this.createEditSession(200, 10);
        var editor = new Editor(new MockRenderer(), doc);

        editor.moveCursorTo(editor.getLastVisibleRow() + 20);
        editor.navigateFileStart();

        assert.equal(editor.getFirstVisibleRow(), 0);
    },
Example #13
0
 "test: remove to line end at line end should remove the new line": function() {
     var session = new EditSession(["123", "4567", "89"]);
     
     var editor = new Editor(new MockRenderer(), session);
     editor.moveCursorTo(1, 4);
     editor.removeToLineEnd();
     assert.position(editor.getCursorPosition(), 1, 4);
     assert.equal(session.getValue(), ["123", "456789"].join("\n"));
 }
Example #14
0
    "test: typing text should update the desired column": function() {
        var editor = new Editor(new MockRenderer(), new EditSession(["1234", "1234567890"]));

        editor.navigateTo(0, 3);
        editor.insert("juhu");
        
        editor.navigateDown();
        assert.position(editor.getCursorPosition(), 1, 7);
    }
Example #15
0
    "test: delete first line" : function() {
        var session = new EditSession(["a", "b", "c"].join("\n"));
        var editor = new Editor(new MockRenderer(), session);

        editor.removeLines();

        assert.equal(session.toString(), "b\nc");
        assert.position(editor.getCursorPosition(), 0, 0);
    },
Example #16
0
 "test: transpose at line end should swap the last two characters": function() {
     var session = new EditSession(["123", "4567", "89"]);
     
     var editor = new Editor(new MockRenderer(), session);
     editor.moveCursorTo(1, 4);
     editor.transposeLetters();
     
     assert.equal(session.getValue(), ["123", "4576", "89"].join("\n"));
 },
Example #17
0
 "test: transpose at line start should be a noop": function() {
     var session = new EditSession(["123", "4567", "89"]);
     
     var editor = new Editor(new MockRenderer(), session);
     editor.moveCursorTo(1, 0);
     editor.transposeLetters();
     
     assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
 },
Example #18
0
 "test: transpose in line should swap the charaters before and after the cursor": function() {
     var session = new EditSession(["123", "4567", "89"]);
     
     var editor = new Editor(new MockRenderer(), session);
     editor.moveCursorTo(1, 2);
     editor.transposeLetters();
     
     assert.equal(session.getValue(), ["123", "4657", "89"].join("\n"));
 },
Example #19
0
    "test: input tab without soft tabs should keep the tab character" : function() {
        var session = new EditSession("");
        var editor = new Editor(new MockRenderer(), session);

        session.setUseSoftTabs(false);

        editor.onTextInput("\t");
        assert.equal(session.toString(), "\t");
    },
Example #20
0
    "test: indent selected lines" : function() {
        var session = new EditSession(["a12345", "b12345", "c12345"].join("\n"));
        var editor = new Editor(new MockRenderer(), session);

        editor.moveCursorTo(1, 0);
        editor.getSelection().selectDown();

        editor.indent();
        assert.equal(["a12345", "    b12345", "c12345"].join("\n"), session.toString());
    },
Example #21
0
    "test: navigate to end of file should scroll the last line into view" : function() {
        var doc = this.createEditSession(200, 10);
        var editor = new Editor(new MockRenderer(), doc);

        editor.navigateFileEnd();
        var cursor = editor.getCursorPosition();

        assert.ok(editor.getFirstVisibleRow() <= cursor.row);
        assert.ok(editor.getLastVisibleRow() >= cursor.row);
    },
Example #22
0
 "test: transpose with non empty selection should be a noop": function() {
     var session = new EditSession(["123", "4567", "89"]);
     
     var editor = new Editor(new MockRenderer(), session);
     editor.moveCursorTo(1, 1);
     editor.getSelection().selectRight();
     editor.transposeLetters();
     
     assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
 },
Example #23
0
    "test: remove left should remove tabsize spaces if cursor is on a tab stop and preceeded by spaces" : function() {
        var session = new EditSession(["123", "        456"]);
        session.setUseSoftTabs(true);
        session.setTabSize(4);

        var editor = new Editor(new MockRenderer(), session);
        editor.moveCursorTo(1, 8);
        editor.removeLeft();
        assert.equal(session.toString(), "123\n    456");
    },
Example #24
0
    "test: outent without a selection should update cursor" : function() {
        var session = new EditSession("        12");
        var editor = new Editor(new MockRenderer(), session);

        editor.moveCursorTo(0, 3);
        editor.blockOutdent("  ");

        assert.equal(session.toString(), "    12");
        assert.position(editor.getCursorPosition(), 0, 0);
    },
Example #25
0
    "test: delete last" : function() {
        var session = new EditSession(["a", "b", "c"].join("\n"));
        var editor = new Editor(new MockRenderer(), session);

        editor.moveCursorTo(2, 1);
        editor.removeLines();

        assert.equal(session.toString(), "a\nb\n");
        assert.position(editor.getCursorPosition(), 2, 0);
    },
Example #26
0
 exec: function() {
     if (main.status.terminal_is_open) {
         main.$.hide_output.click();
         editor.focus();
     } else {
         main.$.show_output.click();
         editor.blur();
         main.terminal.focus();
     }
 }
Example #27
0
  function resize() {
    var width = $( win ).width();
    var widthHalf = width / 2;
    var widthFourth = widthHalf / 2;
    var height = $( win ).height();
    var heightHalf = height / 2;

    // height minus 50 so the end of document text doesn't flow off the page.
    // + 15 for scroll bar
    var editorContainerStyle = 'width:' + (widthHalf + 15) + 'px;' +
      'height:' + (height - 50) + 'px;' +
      'left:' + (leftRight === false ? widthHalf + 'px;' : '0px;') +
      'top:' + '40px;'; // use 40px for tool menu
    cssSet( editorContainer, editorContainerStyle );
    editor.resize();

    // width -2 for scroll bar & -10 for left offset
    var previewStyle = 'width:' + (widthHalf - 2 - 10) + 'px;' +
      'height:' + height + 'px;' +
      'left:' + (leftRight === false ? '10px;' : widthHalf + 'px;') +
       // preview panel top is equal to height of comment tool panel (40px) + 1
      'top:41px;';
    cssSet( preview, previewStyle );

     // Resize tool panel
    var toolPanelStyle = 'width:50%;';
    cssSet( toolPanel, toolPanelStyle );

    // Resize comment related elements.
    var commentHidden = 'visibility:' + ( isCommentHidden === true ? 'hidden;' : 'visible;' );

    // Adjust comment editor
    var commentEditorContainerStyle = 'height:' + heightHalf + 'px;' +
      'width:' + widthHalf + 'px;' +
      'left:' + widthFourth + 'px;' +
      'top:' + (heightHalf / 2) + 'px;' +
      commentHidden;
    cssSet( commentEditorContainer, commentEditorContainerStyle );
    commentEditor.resize();

    var commentToolPanelHeight = height / 4 - 40;

    // In top subtract height (40px) of comment tool panel.
    var commentToolPanelStyle = 'width:' + widthHalf + 'px;' +
      'left:' + widthFourth + 'px;' +
      'top:' + commentToolPanelHeight + 'px;' +
      commentHidden;
    cssSet( commentToolPanel, commentToolPanelStyle );

    // Resize dimmer.
    var darknessStyle = 'width:' + width + 'px;' +
      'height:' + height + 'px;' +
      commentHidden;
    cssSet( darkness, darknessStyle );
  }
Example #28
0
    "test: delete multiple selected lines" : function() {
        var session = new EditSession(["a", "b", "c", "d"].join("\n"));
        var editor = new Editor(new MockRenderer(), session);

        editor.moveCursorTo(1, 1);
        editor.getSelection().selectDown();

        editor.removeLines();
        assert.equal(session.toString(), "a\nd");
        assert.position(editor.getCursorPosition(), 1, 0);
    },
Example #29
0
File: layout.js Project: 1ec5/ace
exports.edit = function(el) {
    if (typeof(el) == "string")
        el = document.getElementById(el);

    var editor = new Editor(new Renderer(el, require("ace/theme/textmate")));

    editor.resize();
    event.addListener(window, "resize", function() {
        editor.resize();
    });
    return editor;
};
Example #30
0
function singleLineEditor(el) {
    var renderer = new Renderer(el);
    renderer.scrollBar.element.style.display = "none";
    renderer.scrollBar.width = 0;
    renderer.content.style.height = "auto";

    renderer.screenToTextCoordinates = function(x, y) {
        var pos = this.pixelToScreenCoordinates(x, y);
        return this.session.screenToDocumentPosition(
            Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)),
            Math.max(pos.column, 0)
        );
    };
    // todo size change event
    renderer.$computeLayerConfig = function() {
        var longestLine = this.$getLongestLine();
        var firstRow = 0;
        var lastRow = this.session.getLength();
        var height = this.session.getScreenLength() * this.lineHeight;

        this.scrollTop = 0;
        var config = this.layerConfig;
        config.width = longestLine;
        config.padding = this.$padding;
        config.firstRow = 0;
        config.firstRowScreen = 0;
        config.lastRow = lastRow;
        config.lineHeight = this.lineHeight;
        config.characterWidth = this.characterWidth;
        config.minHeight = height;
        config.maxHeight = height;
        config.offset = 0;
        config.height = height;

        this.$gutterLayer.element.style.marginTop = 0 + "px";
        this.content.style.marginTop = 0 + "px";
        this.content.style.width = longestLine + 2 * this.$padding + "px";
        this.content.style.height = height + "px";
        this.scroller.style.height = height + "px";
        this.container.style.height = height + "px";
    };
    renderer.isScrollableBy=function(){return false};

    var editor = new Editor(renderer);
    new MultiSelect(editor);
    editor.session.setUndoManager(new UndoManager());

    editor.setHighlightActiveLine(false);
    editor.setShowPrintMargin(false);
    editor.renderer.setShowGutter(false);
    editor.renderer.setHighlightGutterLine(false);
    return editor;
};