<commit_before>var paintr = paintr || {};

paintr.pen_color = "#EEEEE";

paintr.drawRect = function() {
  paintr.toggleMode();
  var is_drawing = false;
  var line;

  paintr.canvas.on('mouse:down', function(e) {
    var mouse_pos = paintr.canvas.getPointer(e.e);
    is_drawing = true;
    line = new fabric.Line([mouse_pos.x, mouse_pos.y, mouse_pos.x, mouse_pos.y], {
      strokeWidth: 5,
      fill: paintr.pen_color,
      stroke: paintr.pen_color,
      originX: 'center',
      originY: 'center'
    });
    paintr.canvas.add(line);
  });

  paintr.canvas.on('mouse:move', function(e) {
    if (!is_drawing) return;
    var mouse_pos = paintr.canvas.getPointer(e.e);
    line.set({ x2: mouse_pos.x, y2: mouse_pos.y });
    paintr.canvas.renderAll();
  });

  paintr.canvas.on('mouse:up', function(e) {
    is_drawing = false;
  });
}

paintr.toggleMode = function() {
  paintr.canvas.off('mouse:down');
  paintr.canvas.off('mouse:up');
  paintr.canvas.off('mouse:move');
}

paintr.drawFreehand = function() {
  paintr.toggleMode();
}

window.onload = function() {
  paintr.canvas = new fabric.Canvas('canvas');
  document.getElementById('line').addEventListener('click', paintr.drawRect);
  document.getElementById('freehand').addEventListener('click', paintr.drawFreehand);
}<commit_msg>Added freehand and select modes<commit_after>var paintr = paintr || {};

paintr.pen_color = "#EEEEE";

paintr.drawRect = function() {
  paintr.toggleMode();
  var is_drawing = false;
  var line;

  paintr.canvas.on('mouse:down', function(e) {
    var mouse_pos = paintr.canvas.getPointer(e.e);
    is_drawing = true;
    line = new fabric.Line([mouse_pos.x, mouse_pos.y, mouse_pos.x, mouse_pos.y], {
      strokeWidth: 5,
      fill: paintr.pen_color,
      stroke: paintr.pen_color,
      originX: 'center',
      originY: 'center',
      evented: true
    });
    paintr.canvas.add(line);
  });

  paintr.canvas.on('mouse:move', function(e) {
    if (!is_drawing) return;
    var mouse_pos = paintr.canvas.getPointer(e.e);
    line.set({ x2: mouse_pos.x, y2: mouse_pos.y });
    paintr.canvas.renderAll();
  });

  paintr.canvas.on('mouse:up', function(e) {
    is_drawing = false;
  });
}

paintr.drawFreehand = function() {
  paintr.toggleMode();
  paintr.canvas.isDrawingMode = true;
  paintr.canvas.freeDrawingLineWidth = 100;
  paintr.canvas.renderAll();
}

paintr.select = function() {
  paintr.toggleMode();
  paintr.canvas.selection = true;
  paintr.canvas.forEachObject(function(obj) {
    obj.selectable = true;
  });
  paintr.canvas.renderAll();
}

paintr.toggleMode = function() {
  paintr.canvas.off('mouse:down');
  paintr.canvas.off('mouse:up');
  paintr.canvas.off('mouse:move');
  paintr.canvas.isDrawingMode = false;
  paintr.canvas.selection = false;
  paintr.canvas.forEachObject(function(obj) {
    obj.selectable = false;
    console.log(obj.stateProperties);
  });
}

window.onload = function() {
  paintr.canvas = new fabric.Canvas('canvas', { selection: true });
  document.getElementById('line').addEventListener('click', paintr.drawRect);
  document.getElementById('freehand').addEventListener('click', paintr.drawFreehand);
  document.getElementById('select').addEventListener('click', paintr.select);
}
{'fraction_non_alphanumeric': 0.16480793060718713, 'fraction_numerical': 0.0027881040892193307, 'mean_word_length': 4.0374414976599065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1008664', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1160, 'n_words': 176}