<commit_before>//----------------------------------------------------------------------------
//  Copyright (C) 2008-2011  The IPython Development Team
//
//  Distributed under the terms of the BSD License.  The full license is in
//  the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------

//============================================================================
// CodeCell
//============================================================================

var IPython = (function (IPython) {

    var utils = IPython.utils;

    var CodeCell = function (notebook) {
        this.code_mirror = null;
        this.input_prompt_number = null;
        this.is_completing = false;
        this.completion_cursor = null;
        this.outputs = [];
        this.collapsed = false;
        this.showInput = true;
        this.tooltip_timeout = null;
        this.clear_out_timeout = null;
        this.tooltip = null;
        this.hideInputOnResult = true;
        this.notebook = notebook;
        IPython.Cell.apply(this, arguments);
    };


    CodeCell.prototype = new IPython.Cell();


    CodeCell.prototype.create_element = function () {
        var cell =  $('<div></div>').addClass('cell code_cell hbox');
        cell.attr('tabindex','2');

        var content = $('<div></div>').addClass('content box-flex1');

        var optionBar = this.create_option_bar();
        cell.append(optionBar);

        var input = $('<div></div>').addClass('input');

        var input_area = $('<div/>').addClass('input_area');
        this.code_mirror = CodeMirror(input_area.get(0), {
            // indentUnit : 4,
            matchBrackets: true,
            mode: 'text/x-scala',
            theme: 'ipython',
            readOnly: this.read_only,
            onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this),
            onChange: $.proxy(function() {this.notebook.set_dirty();},this) // Mark notebook dirty for auto-save.
        });
        input.append(input_area);
        var output = $('<div></div>').addClass('output');
        content.append(input).append(output);
        cell.append(content);
        this.element = cell;
        this.collapse();
    };

    CodeCell.prototype.create_option_bar = function () {
    	var that = this;
        var $run = $('<a href="#"></a>').click(function () {
            that.notebook.execute_selected_cell();
        }).append('<i class="icon-play"></i>');

        var $delete = $('<a href="#"></a>').click(function () {
           that.notebook.delete_cell();
        }).append('<i class="icon-remove"></i>');


        var optionBar = $('<div></div>').addClass('option_bar vbox')
                    .append($('<div></div>').append($run)) 
                    .append($('<div></div>').append($delete));

        optionBar.dblclick(function (event) {
            that.show_sections(!that.showInput, true);
        });

        return optionBar;
    };

    //TODO, try to diminish the number of parameters.
    CodeCell.prototype.request_tooltip_after_time = function (pre_cursor,time){
        var that = this;
        if (pre_cursor !== "" && pre_cursor !== "(" ) {
            // Will set a timer to request tooltip in `time`
            that.remove_and_cancel_tooltip();
            that.tooltip_timeout = setTimeout(function(){
                    that.tooltip_msg_id = IPython.notebook.request_tool_tip(that, pre_cursor)
                },time);
        }
    };

    CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
        // This method gets called in CodeMirror's onKeyDown/onKeyPress
        // handlers and is used to provide custom key handling. Its return
        // value is used to determine if CodeMirror should ignore the event:
        // true = ignore, false = don't ignore.
        
        if (this.read_only){
            return false;
        }
        
        // note that we are comparing and setting the time to wait at each key press.
        // a better wqy might be to generate a new function on each time change and
        // assign it to CodeCell.prototype.request_tooltip_after_time
        tooltip_wait_time = this.notebook.time_before_tooltip;
        tooltip_on_tab    = this.notebook.tooltip_on_tab;
        var that = this;
        // whatever key is pressed, first, cancel the tooltip request before
        // they are sent, and remove tooltip if any
        if(event.type === 'keydown' ) {
            that.remove_and_cancel_tooltip();
        };


        if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
            // Always ignore shift-enter in CodeMirror as we handle it.
            return true;
        } else if (event.which === 40 && event.type === 'keypress' && tooltip_wait_time >= 0) {
            // triger aon keypress (!) otherwise inconsistent event.which depending on plateform
            // browser and keyboard layout !
            // Pressing '(' , request tooltip, don't forget to reappend it
            var cursor = editor.getCursor();
            var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'(';
            that.request_tooltip_after_time(pre_cursor,tooltip_wait_time);
        } else if (event.which === 38) {
            // If we are not at the top, let CM handle the up arrow and
            // prevent the global keydown handler from handling it.
            if (!that.at_top() && !(event.metatKey || event.ctrlKey || event.altKey)) {
                event.stop();
                return false;
            } else {
                return true; 
            };
        } else if (event.which === 40) {
            // If we are not at the bottom, let CM handle the down arrow and
            // prevent the global keydown handler from handling it.
            if (!that.at_bottom() && !(event.metatKey || event.ctrlKey || event.altKey)) {
                event.stop();
                return false;<commit_msg>#31, Fixed - Confusing arrow keys and ampersand<commit_after>//----------------------------------------------------------------------------
//  Copyright (C) 2008-2011  The IPython Development Team
//
//  Distributed under the terms of the BSD License.  The full license is in
//  the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------

//============================================================================
// CodeCell
//============================================================================

var IPython = (function (IPython) {

    var utils = IPython.utils;

    var CodeCell = function (notebook) {
        this.code_mirror = null;
        this.input_prompt_number = null;
        this.is_completing = false;
        this.completion_cursor = null;
        this.outputs = [];
        this.collapsed = false;
        this.showInput = true;
        this.tooltip_timeout = null;
        this.clear_out_timeout = null;
        this.tooltip = null;
        this.hideInputOnResult = true;
        this.notebook = notebook;
        IPython.Cell.apply(this, arguments);
    };


    CodeCell.prototype = new IPython.Cell();


    CodeCell.prototype.create_element = function () {
        var cell =  $('<div></div>').addClass('cell code_cell hbox');
        cell.attr('tabindex','2');

        var content = $('<div></div>').addClass('content box-flex1');

        var optionBar = this.create_option_bar();
        cell.append(optionBar);

        var input = $('<div></div>').addClass('input');

        var input_area = $('<div/>').addClass('input_area');
        this.code_mirror = CodeMirror(input_area.get(0), {
            // indentUnit : 4,
            matchBrackets: true,
            mode: 'text/x-scala',
            theme: 'ipython',
            readOnly: this.read_only,
            onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this),
            onChange: $.proxy(function() {this.notebook.set_dirty();},this) // Mark notebook dirty for auto-save.
        });
        input.append(input_area);
        var output = $('<div></div>').addClass('output');
        content.append(input).append(output);
        cell.append(content);
        this.element = cell;
        this.collapse();
    };

    CodeCell.prototype.create_option_bar = function () {
    	var that = this;
        var $run = $('<a href="#"></a>').click(function () {
            that.notebook.execute_selected_cell();
        }).append('<i class="icon-play"></i>');

        var $delete = $('<a href="#"></a>').click(function () {
           that.notebook.delete_cell();
        }).append('<i class="icon-remove"></i>');


        var optionBar = $('<div></div>').addClass('option_bar vbox')
                    .append($('<div></div>').append($run)) 
                    .append($('<div></div>').append($delete));

        optionBar.dblclick(function (event) {
            that.show_sections(!that.showInput, true);
        });

        return optionBar;
    };

    //TODO, try to diminish the number of parameters.
    CodeCell.prototype.request_tooltip_after_time = function (pre_cursor,time){
        var that = this;
        if (pre_cursor !== "" && pre_cursor !== "(" ) {
            // Will set a timer to request tooltip in `time`
            that.remove_and_cancel_tooltip();
            that.tooltip_timeout = setTimeout(function(){
                    that.tooltip_msg_id = IPython.notebook.request_tool_tip(that, pre_cursor)
                },time);
        }
    };

    CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
        // This method gets called in CodeMirror's onKeyDown/onKeyPress
        // handlers and is used to provide custom key handling. Its return
        // value is used to determine if CodeMirror should ignore the event:
        // true = ignore, false = don't ignore.
        
        if (this.read_only){
            return false;
        }
        
        // note that we are comparing and setting the time to wait at each key press.
        // a better wqy might be to generate a new function on each time change and
        // assign it to CodeCell.prototype.request_tooltip_after_time
        tooltip_wait_time = this.notebook.time_before_tooltip;
        tooltip_on_tab    = this.notebook.tooltip_on_tab;
        var that = this;
        // whatever key is pressed, first, cancel the tooltip request before
        // they are sent, and remove tooltip if any
        if(event.type === 'keydown' ) {
            that.remove_and_cancel_tooltip();
        };


        if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
            // Always ignore shift-enter in CodeMirror as we handle it.
            return true;
        } else if (event.which === 40 && event.type === 'keypress' && tooltip_wait_time >= 0) {
            // triger aon keypress (!) otherwise inconsistent event.which depending on plateform
            // browser and keyboard layout !
            // Pressing '(' , request tooltip, don't forget to reappend it
            var cursor = editor.getCursor();
            var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'(';
            that.request_tooltip_after_time(pre_cursor,tooltip_wait_time);
        } else if (event.which === 38 && event.metaKey) {
            // If we are not at the top, let CM handle the up arrow and
            // prevent the global keydown handler from handling it.
            if (!that.at_top() && !(event.ctrlKey || event.altKey)) {
                event.stop();
                return false;
            } else {
                return true; 
            };
        } else if (event.which === 40 && event.metaKey) {
            // If we are not at the bottom, let CM handle the down arrow and
            // prevent the global keydown handler from handling it.
            if (!that.at_bottom() && !(event.ctrlKey || event.altKey)) {
                event.stop();
                return false;
{'fraction_non_alphanumeric': 0.1737140003329449, 'fraction_numerical': 0.003828866322623606, 'mean_word_length': 2.0045011252813203, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6886225', 'n_tokens_mistral': 3281, 'n_tokens_neox': 3147, 'n_words': 833}