<commit_before>/*
 * Copyright (C) 2015 - 2018, <NAME> and CosmicMind, Inc. <http://cosmicmind.com>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *	*	Redistributions of source code must retain the above copyright notice, this
 *		list of conditions and the following disclaimer.
 *
 *	*	Redistributions in binary form must reproduce the above copyright notice,
 *		this list of conditions and the following disclaimer in the documentation
 *		and/or other materials provided with the distribution.
 *
 *	*	Neither the name of CosmicMind nor the names of its
 *		contributors may be used to endorse or promote products derived from
 *		this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import UIKit

@objc(TextViewDelegate)
public protocol TextViewDelegate : UITextViewDelegate {
  /**
   A delegation method that is executed when the keyboard will open.
   - Parameter textView: A TextView.
   - Parameter willShowKeyboard value: A NSValue.
   */
  @objc
  optional func textView(textView: TextView, willShowKeyboard value: NSValue)
  
  /**
   A delegation method that is executed when the keyboard will close.
   - Parameter textView: A TextView.
   - Parameter willHideKeyboard value: A NSValue.
   */
  @objc
  optional func textView(textView: TextView, willHideKeyboard value: NSValue)
  
  /**
   A delegation method that is executed when the keyboard did open.
   - Parameter textView: A TextView.
   - Parameter didShowKeyboard value: A NSValue.
   */
  @objc
  optional func textView(textView: TextView, didShowKeyboard value: NSValue)
  
  /**
   A delegation method that is executed when the keyboard did close.
   - Parameter textView: A TextView.
   - Parameter didHideKeyboard value: A NSValue.
   */
  @objc
  optional func textView(textView: TextView, didHideKeyboard value: NSValue)
  
  /**
   A delegation method that is executed when text will be
   processed during editing.
   - Parameter textView: A TextView.
   - Parameter willProcessEditing textStorage: A TextStorage.
   - Parameter text: A String.
   - Parameter range: A NSRange.
   */
  @objc
  optional func textView(textView: TextView, willProcessEditing textStorage: TextStorage, text: String, range: NSRange)
  
  /**
   A delegation method that is executed when text has been
   processed after editing.
   - Parameter textView: A TextView.
   - Parameter didProcessEditing textStorage: A TextStorage.
   - Parameter text: A String.
   - Parameter range: A NSRange.
   */
  @objc
  optional func textView(textView: TextView, didProcessEditing textStorage: TextStorage, text: String, range: NSRange)
}

open class TextView: UITextView {
  /// A boolean indicating whether the text is empty.
  open var isEmpty: Bool {
    return 0 == text?.utf16.count
  }
  
  /// A boolean indicating whether the text is in edit mode.
  open fileprivate(set) var isEditing = true
  
  /// Is the keyboard hidden.
  open fileprivate(set) var isKeyboardHidden = true
  
  /// A property that accesses the backing layer's background
  @IBInspectable
  open override var backgroundColor: UIColor? {
    didSet {
      layer.backgroundColor = backgroundColor?.cgColor
    }
  }
  
  /// Holds default font.
  private var _font: UIFont?
  
  /// The placeholderLabel font value.
  @IBInspectable
  open override var font: UIFont? {
    didSet {
        _font = font
      placeholderLabel.font = font
    }
  }
  
  /// The placeholderLabel text value.
  @IBInspectable
  open var placeholder: String? {
    get {
      return placeholderLabel.text
    }<commit_msg>TextView.isEditing should be false by default<commit_after>/*
 * Copyright (C) 2015 - 2018, <NAME> and CosmicMind, Inc. <http://cosmicmind.com>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *	*	Redistributions of source code must retain the above copyright notice, this
 *		list of conditions and the following disclaimer.
 *
 *	*	Redistributions in binary form must reproduce the above copyright notice,
 *		this list of conditions and the following disclaimer in the documentation
 *		and/or other materials provided with the distribution.
 *
 *	*	Neither the name of CosmicMind nor the names of its
 *		contributors may be used to endorse or promote products derived from
 *		this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import UIKit

@objc(TextViewDelegate)
public protocol TextViewDelegate : UITextViewDelegate {
  /**
   A delegation method that is executed when the keyboard will open.
   - Parameter textView: A TextView.
   - Parameter willShowKeyboard value: A NSValue.
   */
  @objc
  optional func textView(textView: TextView, willShowKeyboard value: NSValue)
  
  /**
   A delegation method that is executed when the keyboard will close.
   - Parameter textView: A TextView.
   - Parameter willHideKeyboard value: A NSValue.
   */
  @objc
  optional func textView(textView: TextView, willHideKeyboard value: NSValue)
  
  /**
   A delegation method that is executed when the keyboard did open.
   - Parameter textView: A TextView.
   - Parameter didShowKeyboard value: A NSValue.
   */
  @objc
  optional func textView(textView: TextView, didShowKeyboard value: NSValue)
  
  /**
   A delegation method that is executed when the keyboard did close.
   - Parameter textView: A TextView.
   - Parameter didHideKeyboard value: A NSValue.
   */
  @objc
  optional func textView(textView: TextView, didHideKeyboard value: NSValue)
  
  /**
   A delegation method that is executed when text will be
   processed during editing.
   - Parameter textView: A TextView.
   - Parameter willProcessEditing textStorage: A TextStorage.
   - Parameter text: A String.
   - Parameter range: A NSRange.
   */
  @objc
  optional func textView(textView: TextView, willProcessEditing textStorage: TextStorage, text: String, range: NSRange)
  
  /**
   A delegation method that is executed when text has been
   processed after editing.
   - Parameter textView: A TextView.
   - Parameter didProcessEditing textStorage: A TextStorage.
   - Parameter text: A String.
   - Parameter range: A NSRange.
   */
  @objc
  optional func textView(textView: TextView, didProcessEditing textStorage: TextStorage, text: String, range: NSRange)
}

open class TextView: UITextView {
  /// A boolean indicating whether the text is empty.
  open var isEmpty: Bool {
    return 0 == text?.utf16.count
  }
  
  /// A boolean indicating whether the text is in edit mode.
  open fileprivate(set) var isEditing = false
  
  /// Is the keyboard hidden.
  open fileprivate(set) var isKeyboardHidden = true
  
  /// A property that accesses the backing layer's background
  @IBInspectable
  open override var backgroundColor: UIColor? {
    didSet {
      layer.backgroundColor = backgroundColor?.cgColor
    }
  }
  
  /// Holds default font.
  private var _font: UIFont?
  
  /// The placeholderLabel font value.
  @IBInspectable
  open override var font: UIFont? {
    didSet {
        _font = font
      placeholderLabel.font = font
    }
  }
  
  /// The placeholderLabel text value.
  @IBInspectable
  open var placeholder: String? {
    get {
      return placeholderLabel.text
    }
{'fraction_non_alphanumeric': 0.06616088363271226, 'fraction_numerical': 0.0024545353118375544, 'mean_word_length': 3.47976011994003, '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': '2980618', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2404, 'n_words': 1047}