<commit_before>const React = require('react/addons');
const MenuButton = require('../MenuButton');

const ToggleMarkup = require('../../helpers/Manipulation/ToggleMarkup');
const EditorStore = require('../../stores/EditorStore');

const LinkButton = React.createClass({
  statics: {
    isVisible: () => true,
  },

  propTypes: MenuButton.propTypes,

  getDefaultProps() {
    return {
      type: "a",
      text: "Link",
      icon: "fa-link",
      hasValue: true
    };
  },

  setValue(value) {
    const content = this.handlePress(value || "");
    EditorStore.set({content: content});
  },

  handlePress(value) {
    value = value || "";
    const guids   = this.props.selection.guids();
    const offsets = this.props.selection.offsets();
    const position = this.props.selection.position();

    if (value && !value.match(/^http/)) { value = "http://" + value; }

    const options = { type: this.props.type, value: value };
    const result = this._toggleMarkup().execute(guids, offsets, options);

    return { content: result.content, position: position };
  },

  _toggleMarkup() {
    return new ToggleMarkup(this.props.content);
  },

  render() {
    return (
      <MenuButton {...this.props}
        onPress={this.handlePress}
        onSetValue={this.props.onSetValue}
      />
    );
  }<commit_msg>fix handling of link values<commit_after>const React = require('react/addons');
const MenuButton = require('../MenuButton');

const ToggleMarkup = require('../../helpers/Manipulation/ToggleMarkup');
const EditorStore = require('../../stores/EditorStore');

const LinkButton = React.createClass({
  statics: {
    isVisible: () => true,
  },

  propTypes: MenuButton.propTypes,

  getDefaultProps() {
    return {
      type: "a",
      text: "Link",
      icon: "fa-link",
      hasValue: true
    };
  },

  setValue(value) {
    const { content, position } = this.handlePress(value || "");
    EditorStore.set({content: content});
  },

  handlePress(value) {
    value = value || "";
    const guids   = this.props.selection.guids();
    const offsets = this.props.selection.offsets();
    const position = this.props.selection.position();

    if (value && !value.match(/^http/)) { value = "http://" + value; }

    const options = { type: this.props.type, value: value };
    const result = this._toggleMarkup().execute(guids, offsets, options);

    return { content: result.content, position: position };
  },

  _toggleMarkup() {
    return new ToggleMarkup(this.props.content);
  },

  render() {
    return (
      <MenuButton {...this.props}
        onPress={this.handlePress}
        onSetValue={this.props.onSetValue}
      />
    );
  }
{'fraction_non_alphanumeric': 0.1657934131736527, 'fraction_numerical': 0.0, 'mean_word_length': 2.9895522388059703, 'pattern_counts': {'":': 0, '<': 5, '<?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': '360382', 'n_tokens_mistral': 837, 'n_tokens_neox': 817, 'n_words': 165}