<commit_before>'use strict';

var _     = require('lodash');
var React = require('react');
var Layer = require('react-layer');

var Menu = require('component/Menu.jsx');
var dom  = require('util/dom');

var MenuControl = {
	getDefaultProps : function () {
		return {
			onSearch : _.noop
		};
	},

	getInitialState : function () {
		return {
			open : false
		};
	},

	componentDidUpdate : function () {
		if (this.state.open) {
			var items  = this.props.children;
			var offset = dom.documentOffset(React.findDOMNode(this));
			var props  = _.omit(this.props, 'text', 'icon', 'size');

			var x = (offset.right + offset.left) / 2

			var onBlur = this.onBlur || _.noop;

			if (!this.layer) {
				var self = this;

				this.layer = new Layer(document.body, function () {
					return (
						<Menu x={x} y={offset.bottom}
							onBlur={self.close}
							{...props}>
							{items}
						</Menu>
					);
				});

				window.addEventListener('keyup', this);
			}

			this.layer.render();
		} else if (this.layer) {
			this.layer.destroy();
			this.layer = null;

			// Clear out the search patterns that the parent component is necessarily
			// using to provide filtered menu items.
			this.props.onSearch('');
			window.removeEventListener('keyup', this);
		}
	},

	_toggleMenu : function () {
		this.setState({open : !this.state.open });
	},

	handleEvent : function (evt) {
		switch (evt.type) {
			case 'keyup':
				if (evt.keyCode === 27) {
					this.close();
				}
				break;<commit_msg>Fix menu filtering<commit_after>'use strict';

var _     = require('lodash');
var React = require('react');
var Layer = require('react-layer');

var Menu = require('component/Menu.jsx');
var dom  = require('util/dom');

var MenuControl = {
	getDefaultProps : function () {
		return {
			onSearch : _.noop
		};
	},

	getInitialState : function () {
		return {
			open : false
		};
	},

	componentDidUpdate : function () {
		if (this.state.open) {
			var items  = this.props.children;
			var offset = dom.documentOffset(React.findDOMNode(this));
			var props  = _.omit(this.props, 'text', 'icon', 'size');

			var x = (offset.right + offset.left) / 2

			var onBlur = this.onBlur || _.noop;

			var menu = (
				<Menu x={x} y={offset.bottom}
					onBlur={this.close}
					onSearch={this.onSearch}
					{...props}>
					{items}
				</Menu>
			);

			if (!this.layer) {
				var self = this;

				this.layer = new Layer(document.body, function () {
					return menu;
				});

				window.addEventListener('keyup', this);
			} else {
				// Here's a gross way to re-render the menu when its items have changed
				// (due, for example, to them being filtered) without destroying and
				// recreating the layer every time.
				this.layer._render = function () { return menu; };
			}

			this.layer.render();
		} else if (this.layer) {
			this.layer.destroy();
			this.layer = null;

			// Clear out the search patterns that the parent component is necessarily
			// using to provide filtered menu items.
			this.props.onSearch('');
			window.removeEventListener('keyup', this);
		}
	},

	_toggleMenu : function () {
		this.setState({open : !this.state.open });
	},

	handleEvent : function (evt) {
		switch (evt.type) {
			case 'keyup':
				if (evt.keyCode === 27) {
					this.close();
				}
				break;
{'fraction_non_alphanumeric': 0.1574468085106383, 'fraction_numerical': 0.00182370820668693, 'mean_word_length': 2.761142857142857, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4523673', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1069, 'n_words': 268}