<commit_before>Tool = ToolHandler.extend({
	beans: true,

	initialize: function(handlers, doc) {
		this.base(handlers);
		if(Paper.document)
			this.document = Paper.document;
	},
	
	setDocument: function(doc) {
		this._document = doc;
		var that = this, curPoint;
		var events = {
			mousedown: function(e) {
				curPoint = new Point(e.offset);
				that.onHandleEvent('MOUSE_DOWN', curPoint, null, null);
				that._document.redraw();
				if(that.eventInterval != -1)
					this.intervalId = setInterval(events.drag, that.eventInterval);
			},
			drag: function(e) {
				if(e) curPoint = new Point(e.offset);
				if(curPoint) {
					that.onHandleEvent('MOUSE_DRAG', curPoint, null, null);
					that._document.redraw();
				}
			},
			dragend: function(e) {
				curPoint = null;
				if(this.eventInterval != -1)
					clearInterval(this.intervalId);
				that.onHandleEvent('MOUSE_UP', new Point(e.offset), null, null);
				that._document.redraw();
			},
			mousemove: function(e) {
				that.onHandleEvent('MOUSE_MOVE', new Point(e.offset), null, null);
				that._document.redraw();
			}
		};
		$(doc.canvas).addEvents(events);
	},
	
	/**
	 * The fixed time delay between each call to the {@link #onMouseDrag}
	 * event. Setting this to an interval means the {@link #onMouseDrag} event
	 * is called repeatedly after the initial {@link #onMouseDown} until the
	 * user releases the mouse.
	 * <commit_msg>Tool#setDocument: remove mousemove functionality for now, since it is interfering with tool.fixedDistance. Remove events when a tool has been attached to another document before. When not passed a document in the constructor, use the global Paper.document. Only redraw the document when the corresponding mousehandler exists.<commit_after>Tool = ToolHandler.extend({
	beans: true,

	initialize: function(handlers, doc) {
		this.base(handlers);
		if(Paper.document)
			this.document = Paper.document;
	},
	
	setDocument: function(doc) {
		if(this._document)
			$(this._document.canvas).removeEvents();
		this._document = doc || Paper.document;
		var that = this, curPoint;
		var events = {
			mousedown: function(e) {
				curPoint = new Point(e.offset);
				that.onHandleEvent('MOUSE_DOWN', curPoint, null, null);
				if(that.onMouseDown)
					that._document.redraw();
				if(that.eventInterval != -1)
					this.intervalId = setInterval(events.drag, that.eventInterval);
			},
			drag: function(e) {
				if(e) curPoint = new Point(e.offset);
				if(curPoint) {
					that.onHandleEvent('MOUSE_DRAG', curPoint, null, null);
					if(that.onMouseDrag)
						that._document.redraw();
				}
			},
			dragend: function(e) {
				curPoint = null;
				if(this.eventInterval != -1)
					clearInterval(this.intervalId);
				that.onHandleEvent('MOUSE_UP', new Point(e.offset), null, null);
				if(that.onMouseUp)
					that._document.redraw();
			}
			// TODO: This is currently interfering with the drag code, needs fixing:
			// mousemove: function(e) {
			// 		that.onHandleEvent('MOUSE_MOVE', new Point(e.offset), null, null);
			// 		that._document.redraw();
			// }
		};
		$(doc.canvas).addEvents(events);
	},
	
	/**
	 * The fixed time delay between each call to the {@link #onMouseDrag}
	 * event. Setting this to an interval means the {@link #onMouseDrag} event
	 * is called repeatedly after the initial {@link #onMouseDown} until the
	 * user releases the mouse.
	 * 
{'fraction_non_alphanumeric': 0.13261968480523342, 'fraction_numerical': 0.0011894142134998512, 'mean_word_length': 3.5831062670299727, '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': '2708753', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1065, 'n_words': 273}