<commit_before>Slate.Drawing = (function ($) {
    "use strict";
    var TMP_TEXT_FONT_FACE = "Verdana";

    var drawing_state = {
        is_drawing: false,
        points: [],
        text_info: {},
        added_shape_ids: {},
        all_shapes: {},
        fill_color: '',
        border_color: '',
        border_width: ''
    };


    function get_event_position(ev) {
        var original_event = ev.originalEvent;

        if (original_event.touches) {
            return {
                'x': original_event.touches[0].pageX,
                'y': original_event.touches[0].pageY
            };
        }

        return {
            'x': original_event.pageX,
            'y': original_event.pageY
        };
    }

    function start_drawing(ev) {
        var position = get_event_position(ev);
        if (Slate.Event.handle_canvas_mousedown_events(position.x, position.y) === false) {
            return;
        }

        drawing_state.is_drawing = true;
        drawing_state.points = [];


        var origin = Slate.Artboard.get_canvas_origin(),
            action_type = $("input[name='board_actions']:checked").val();

        var canvas_x = Slate.Artboard.screen_to_canvas_zoom(position.x) - origin.x;
        var canvas_y = Slate.Artboard.screen_to_canvas_zoom(position.y) - origin.y;

        if (action_type === "pan") {
            drawing_state.points.push({
                x: position.x,
                y: position.y,
            });
        } else if (action_type === "select") {
            Slate.Event.clear_cursor_regions();
            Slate.Event.clear_mousedown_regions();
            Slate.Select.find_select_object(canvas_x, canvas_y);
        } else if (action_type === "text") {
            show_text_box(position.x, position.y);
        } else {
            drawing_state.points.push({
                x: position.x - origin.x,
                y: position.y - origin.y,
            });
        }
        ev.preventDefault();
        ev.stopPropagation();
    }

    function live_update_autoshape(ev) {
        var canvas = document.getElementById("draw_surface"),
            context = canvas.getContext("2d"),
            points = drawing_state.points,
            origin = Slate.Artboard.get_canvas_origin(),
            last_point = points[points.length - 1];

        context.save();
        context.beginPath();
        context.moveTo(last_point.x + origin.x, last_point.y + origin.y);
        context.strokeStyle = drawing_state.border_color;
        context.lineWidth = drawing_state.border_width;

        var position = get_event_position(ev);
        context.lineTo(position.x, position.y);
        context.stroke();
        context.restore();

        points.push({
            x: position.x - origin.x,
            y: position.y - origin.y
        });
    }

    function live_update_rectangle(ev) {
        var canvas = document.getElementById("draw_surface"),
            context = canvas.getContext("2d"),
            origin = Slate.Artboard.get_canvas_origin(),

            points = drawing_state.points,
            last_point = points[points.length - 1],
            x1 = last_point.x,
            y1 = last_point.y,

            position = get_event_position(ev),
            x2 = position.x - origin.x,
            y2 = position.y - origin.y,

            border_width = drawing_state.border_width,
            border_color = drawing_state.border_color,
            fill_color = drawing_state.fill_color;

        context.clearRect(0, 0, canvas.width, canvas.height);

        draw_polygon(context, Slate.Artboard.get_canvas_origin(), border_width, border_color, fill_color,
            [
                { x: x1, y: y1 },
                { x: x1, y: y2 },
                { x: x2, y: y2 },
                { x: x2, y: y1 },
                { x: x1, y: y1 }
            ]);
    }

    function update_display_origin(x, y) {
        Slate.Artboard.set_canvas_origin(x, y);

        Slate.Layer.redraw_screen();
    }

    function live_update_panning(ev) {
        var first_point = drawing_state.points[0],

            position = get_event_position(ev),
            d_x = position.x - first_point.x,
            d_y = position.y - first_point.y,

            origin = Slate.Artboard.get_canvas_origin(),

            new_origin_x = origin.x + d_x,
            new_origin_y = origin.y + d_y;

        update_display_origin(new_origin_x, new_origin_y);

        drawing_state.points[0] = {
            x: position.x,
            y: position.y,<commit_msg>Makes panning happen at the right rate for different zoom levels<commit_after>Slate.Drawing = (function ($) {
    "use strict";
    var TMP_TEXT_FONT_FACE = "Verdana";

    var drawing_state = {
        is_drawing: false,
        points: [],
        text_info: {},
        added_shape_ids: {},
        all_shapes: {},
        fill_color: '',
        border_color: '',
        border_width: ''
    };


    function get_event_position(ev) {
        var original_event = ev.originalEvent;

        if (original_event.touches) {
            return {
                'x': original_event.touches[0].pageX,
                'y': original_event.touches[0].pageY
            };
        }

        return {
            'x': original_event.pageX,
            'y': original_event.pageY
        };
    }

    function start_drawing(ev) {
        var position = get_event_position(ev);
        if (Slate.Event.handle_canvas_mousedown_events(position.x, position.y) === false) {
            return;
        }

        drawing_state.is_drawing = true;
        drawing_state.points = [];


        var origin = Slate.Artboard.get_canvas_origin(),
            action_type = $("input[name='board_actions']:checked").val();

        var canvas_x = Slate.Artboard.screen_to_canvas_zoom(position.x) - origin.x;
        var canvas_y = Slate.Artboard.screen_to_canvas_zoom(position.y) - origin.y;

        if (action_type === "pan") {
            drawing_state.points.push({
                x: position.x,
                y: position.y,
            });
        } else if (action_type === "select") {
            Slate.Event.clear_cursor_regions();
            Slate.Event.clear_mousedown_regions();
            Slate.Select.find_select_object(canvas_x, canvas_y);
        } else if (action_type === "text") {
            show_text_box(position.x, position.y);
        } else {
            drawing_state.points.push({
                x: position.x - origin.x,
                y: position.y - origin.y,
            });
        }
        ev.preventDefault();
        ev.stopPropagation();
    }

    function live_update_autoshape(ev) {
        var canvas = document.getElementById("draw_surface"),
            context = canvas.getContext("2d"),
            points = drawing_state.points,
            origin = Slate.Artboard.get_canvas_origin(),
            last_point = points[points.length - 1];

        context.save();
        context.beginPath();
        context.moveTo(last_point.x + origin.x, last_point.y + origin.y);
        context.strokeStyle = drawing_state.border_color;
        context.lineWidth = drawing_state.border_width;

        var position = get_event_position(ev);
        context.lineTo(position.x, position.y);
        context.stroke();
        context.restore();

        points.push({
            x: position.x - origin.x,
            y: position.y - origin.y
        });
    }

    function live_update_rectangle(ev) {
        var canvas = document.getElementById("draw_surface"),
            context = canvas.getContext("2d"),
            origin = Slate.Artboard.get_canvas_origin(),

            points = drawing_state.points,
            last_point = points[points.length - 1],
            x1 = last_point.x,
            y1 = last_point.y,

            position = get_event_position(ev),
            x2 = position.x - origin.x,
            y2 = position.y - origin.y,

            border_width = drawing_state.border_width,
            border_color = drawing_state.border_color,
            fill_color = drawing_state.fill_color;

        context.clearRect(0, 0, canvas.width, canvas.height);

        draw_polygon(context, Slate.Artboard.get_canvas_origin(), border_width, border_color, fill_color,
            [
                { x: x1, y: y1 },
                { x: x1, y: y2 },
                { x: x2, y: y2 },
                { x: x2, y: y1 },
                { x: x1, y: y1 }
            ]);
    }

    function update_display_origin(x, y) {
        Slate.Artboard.set_canvas_origin(x, y);

        Slate.Layer.redraw_screen();
    }

    function live_update_panning(ev) {
        var first_point = drawing_state.points[0],

            position = get_event_position(ev),
            d_x = Slate.Artboard.screen_to_canvas_zoom(position.x - first_point.x),
            d_y = Slate.Artboard.screen_to_canvas_zoom(position.y - first_point.y),

            origin = Slate.Artboard.get_canvas_origin(),

            new_origin_x = origin.x + d_x,
            new_origin_y = origin.y + d_y;

        update_display_origin(new_origin_x, new_origin_y);

        drawing_state.points[0] = {
            x: position.x,
            y: position.y,
{'fraction_non_alphanumeric': 0.11585033271517399, 'fraction_numerical': 0.005236173230064361, 'mean_word_length': 1.8270120259019427, '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': '4101137', 'n_tokens_mistral': 2831, 'n_tokens_neox': 2751, 'n_words': 461}