<commit_before>'use strict';

const {BufferView} = require('./bufferView.js'); 
const {CursorView} = require('./cursorView.js');
const {GutterView} = require('./gutterView.js');
const {viewHelpers} = require('./viewHelpers.js');

function EditorPane(rootElem) {

    this.domNode = document.createElement('div');
    this.domNode.className = 'editor-pane';
    this.domNode.tabIndex = 1;
    
    const sharedViewConfig = viewHelpers.getSharedViewConfig(rootElem);

    this.bufferView = new BufferView(this.domNode, sharedViewConfig);
    this.cursorView = new CursorView(this.domNode, sharedViewConfig);
    this.gutterView = new GutterView(this.domNode, sharedViewConfig);

    this._initComponents();
    
    rootElem.appendChild(this.domNode);
}

EditorPane.prototype._initComponents = function() {

    this.cursorView.setLeftOffset(this.gutterView.getWidth());
    this.bufferView.setLeftOffset(this.gutterView.getWidth()); 
    
    this.gutterView.onWidthChanged((width) => {
        this.cursorView.setLeftOffset(width);
        this.bufferView.setLeftOffset(width); 
    });
};

EditorPane.prototype.setFocused = function() {
    this.domNode.focus();
};

EditorPane.prototype.insertText = function(text) {
    this.bufferView.setLine(this.cursorView.row,
                               this.bufferView.getLine(this.cursorView.row).slice(0, this.cursorView.col - 1) +
                               text +
                               this.bufferView.getLine(this.cursorView.row).slice(this.cursorView.col - 1));
    
    this.cursorView.moveRight(text.length);
};

EditorPane.prototype.insertNewLine = function() {
    const line = this.bufferView.getLine(this.cursorView.row);
    const toRemain = line.substr(0, this.cursorView.col - 1);
    const toGo = line.substr(this.cursorView.col - 1);

    this.bufferView.setLine(this.cursorView.row, toRemain);
    this.bufferView.insertLine(this.cursorView.row + 1, toGo);
    this.cursorView.moveTo(1, this.cursorView.row + 1);
    this.gutterView.appendRow();
    this.gutterView.setActiveRow(this.cursorView.row);  
};

EditorPane.prototype.deleteBackChar = function() {
    if (this.cursorView.row > 1) {
        const prevLine = this.bufferView.getLine(this.cursorView.row - 1);
        this.bufferView.setLine(this.cursorView.row - 1,
                                prevLine + this.bufferView.getLine(this.cursorView.row));
        this.bufferView.removeLine(this.cursorView.row);<commit_msg>Fix bug with deleteBackChar.<commit_after>'use strict';

const {BufferView} = require('./bufferView.js'); 
const {CursorView} = require('./cursorView.js');
const {GutterView} = require('./gutterView.js');
const {viewHelpers} = require('./viewHelpers.js');

function EditorPane(rootElem) {

    this.domNode = document.createElement('div');
    this.domNode.className = 'editor-pane';
    this.domNode.tabIndex = 1;
    
    const sharedViewConfig = viewHelpers.getSharedViewConfig(this.domNode);

    this.bufferView = new BufferView(this.domNode, sharedViewConfig);
    this.cursorView = new CursorView(this.domNode, sharedViewConfig);
    this.gutterView = new GutterView(this.domNode, sharedViewConfig);

    this._initComponents();
    
    rootElem.appendChild(this.domNode);
}

EditorPane.prototype._initComponents = function() {

    this.cursorView.setLeftOffset(this.gutterView.getWidth());
    this.bufferView.setLeftOffset(this.gutterView.getWidth()); 
    
    this.gutterView.onWidthChanged((width) => {
        this.cursorView.setLeftOffset(width);
        this.bufferView.setLeftOffset(width); 
    });
};

EditorPane.prototype.setFocused = function() {
    this.domNode.focus();
};

EditorPane.prototype.insertText = function(text) {
    this.bufferView.setLine(this.cursorView.row,
                               this.bufferView.getLine(this.cursorView.row).slice(0, this.cursorView.col - 1) +
                               text +
                               this.bufferView.getLine(this.cursorView.row).slice(this.cursorView.col - 1));
    
    this.cursorView.moveRight(text.length);
};

EditorPane.prototype.insertNewLine = function() {
    const line = this.bufferView.getLine(this.cursorView.row);
    const toRemain = line.substr(0, this.cursorView.col - 1);
    const toGo = line.substr(this.cursorView.col - 1);

    this.bufferView.setLine(this.cursorView.row, toRemain);
    this.bufferView.insertLine(this.cursorView.row + 1, toGo);
    this.cursorView.moveTo(1, this.cursorView.row + 1);
    this.gutterView.appendRow();
    this.gutterView.setActiveRow(this.cursorView.row);  
};

EditorPane.prototype.deleteBackChar = function() {
    if (this.cursorView.col === 1) {
        const prevLine = this.bufferView.getLine(this.cursorView.row - 1);
        this.bufferView.setLine(this.cursorView.row - 1,
                                prevLine + this.bufferView.getLine(this.cursorView.row));
        this.bufferView.removeLine(this.cursorView.row);
{'fraction_non_alphanumeric': 0.1351953045942117, 'fraction_numerical': 0.005262092693786683, 'mean_word_length': 3.2899305555555554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7273636', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1513, 'n_words': 196}