<commit_before>//
//  AddWordViewController.swift
//  Kotoba
//
//  Created by <NAME> on 06/17.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import UIKit

final class AddWordViewController: UIViewController
{
	@IBOutlet weak var textField: UITextField!
	@IBOutlet weak var tableView: UITableView!
	@IBOutlet weak var searchingIndicator: UIActivityIndicatorView!
	
	@IBOutlet weak var suggestionView: UIView!
	@IBOutlet weak var suggestionLabel: UILabel!
	@IBOutlet weak var suggestionToggleButton: UIButton!

	@IBOutlet weak var typingViewBottomLayoutConstraint: NSLayoutConstraint!
	@IBOutlet weak var suggestionViewBottomLayoutConstraint: NSLayoutConstraint!
	@IBOutlet weak var suggestionViewHeightLayoutConstraint: NSLayoutConstraint!

	var suggestionsVisible = false
	var suggestionHeight = CGFloat(200)
	let suggestionHeaderHeight = CGFloat(44) // NOTE: This value should match "Header View" in the storyboard

	var haveSuggestions = false // NOTE: This value is true if the pasteboard contained text the last time it was checked
	var sourcePasteboardString: String?
	var pasteboardWords: [Word] = []
	
	var keyboardVisible = false
	var keyboardHeight = CGFloat(0)

	deinit
	{
		NotificationCenter.default.removeObserver(self)
	}
	
	override func viewDidLoad()
	{
		super.viewDidLoad()
		prepareKeyboardNotifications()

		if UserDefaults.standard.CHOCKTUBA_DUH
		{
			self.textField.autocapitalizationType = .allCharacters
		}
		
		// NOTE: This improves the initial view animation, when the keyboard and suggestions appear, but it also
		// generates the warning below. If we wait until the tableView is in the view hierarchy (in viewDidAppear) the
		// keyboard animation is already in progress and it's too late to adjust the width of the top-level view.
		self.view.layoutIfNeeded()
		
		/*
		[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <UITableView: 0x7f8064035e00; frame = (0 44; 414 156); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x600001310b10>; layer = <CALayer: 0x600001d2d2c0>; contentOffset: {0, 0}; contentSize: {414, 0}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <Kotoba.AddWordViewController: 0x7f806370ac80>>
		*/
		
		NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(notification:)), name: UIApplication.didBecomeActiveNotification, object: nil)
	}
	
	override func viewWillAppear(_ animated: Bool)
	{
		debugLog()
		super.viewWillAppear(animated)

		// TODO: Decide if the keyboard should appear before or after the view.
		showKeyboard()
	}
	
	override func viewDidAppear(_ animated: Bool)
	{
		debugLog()
		super.viewDidAppear(animated)

		// TODO: Decide if the keyboard should appear before or after the view.
		//showKeyboard()
	}
	
	override func viewWillDisappear(_ animated: Bool)
	{
		debugLog()
		super.viewWillDisappear(animated)
		
		hideKeyboard()
	}
	
	@objc func applicationDidBecomeActive(notification: NSNotification)
	{
		debugLog()

		#if true
		suggestionsVisible = !UIPasteboard.general.ignoreSuggestions
		let duration: TimeInterval = 0.2
		UIView.animate(withDuration: duration)
		{
			self.updateLayoutFromPasteboard()
			self.updateLayersForSuggestions()
			self.updateTableView()
			self.view.layoutIfNeeded()
		}
		#endif

		checkMigration()
	}
}<commit_msg>Clean up commented-out code.<commit_after>//
//  AddWordViewController.swift
//  Kotoba
//
//  Created by <NAME> on 06/17.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import UIKit

final class AddWordViewController: UIViewController
{
	@IBOutlet weak var textField: UITextField!
	@IBOutlet weak var tableView: UITableView!
	@IBOutlet weak var searchingIndicator: UIActivityIndicatorView!
	
	@IBOutlet weak var suggestionView: UIView!
	@IBOutlet weak var suggestionLabel: UILabel!
	@IBOutlet weak var suggestionToggleButton: UIButton!

	@IBOutlet weak var typingViewBottomLayoutConstraint: NSLayoutConstraint!
	@IBOutlet weak var suggestionViewBottomLayoutConstraint: NSLayoutConstraint!
	@IBOutlet weak var suggestionViewHeightLayoutConstraint: NSLayoutConstraint!

	var suggestionsVisible = false
	var suggestionHeight = CGFloat(200)
	let suggestionHeaderHeight = CGFloat(44) // NOTE: This value should match "Header View" in the storyboard

	var haveSuggestions = false // NOTE: This value is true if the pasteboard contained text the last time it was checked
	var sourcePasteboardString: String?
	var pasteboardWords: [Word] = []
	
	var keyboardVisible = false
	var keyboardHeight = CGFloat(0)

	deinit
	{
		NotificationCenter.default.removeObserver(self)
	}
	
	override func viewDidLoad()
	{
		super.viewDidLoad()
		prepareKeyboardNotifications()

		if UserDefaults.standard.CHOCKTUBA_DUH
		{
			self.textField.autocapitalizationType = .allCharacters
		}
		
		// NOTE: This improves the initial view animation, when the keyboard and suggestions appear, but it also
		// generates the warning below. If we wait until the tableView is in the view hierarchy (in viewDidAppear) the
		// keyboard animation is already in progress and it's too late to adjust the width of the top-level view.
		self.view.layoutIfNeeded()
		
		/*
		[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <UITableView: 0x7f8064035e00; frame = (0 44; 414 156); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x600001310b10>; layer = <CALayer: 0x600001d2d2c0>; contentOffset: {0, 0}; contentSize: {414, 0}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <Kotoba.AddWordViewController: 0x7f806370ac80>>
		*/
		
		NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(notification:)), name: UIApplication.didBecomeActiveNotification, object: nil)
	}
	
	override func viewWillAppear(_ animated: Bool)
	{
		debugLog()
		super.viewWillAppear(animated)

		// TODO: Decide if the keyboard should appear before or after the view.
		showKeyboard()
	}
	
	override func viewDidAppear(_ animated: Bool)
	{
		debugLog()
		super.viewDidAppear(animated)
	}
	
	override func viewWillDisappear(_ animated: Bool)
	{
		debugLog()
		super.viewWillDisappear(animated)
		
		hideKeyboard()
	}
	
	@objc func applicationDidBecomeActive(notification: NSNotification)
	{
		debugLog()

		#if true
		suggestionsVisible = !UIPasteboard.general.ignoreSuggestions
		let duration: TimeInterval = 0.2
		UIView.animate(withDuration: duration)
		{
			self.updateLayoutFromPasteboard()
			self.updateLayersForSuggestions()
			self.updateTableView()
			self.view.layoutIfNeeded()
		}
		#endif

		checkMigration()
	}
}
{'fraction_non_alphanumeric': 0.07398119122257053, 'fraction_numerical': 0.01956112852664577, 'mean_word_length': 4.847507331378299, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '5549642', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2259, 'n_words': 812}