<commit_before>import {
  Component,
  OnInit,
  AfterViewInit,
  OnChanges,
  Input,
  Output,
  EventEmitter,
  SimpleChanges
} from '@angular/core';

// Import the codemirror packages
import Codemirror from 'codemirror';
import 'codemirror/addon/comment/comment';
import 'codemirror/addon/hint/show-hint';
import 'codemirror/addon/lint/lint';
import 'codemirror/addon/fold/foldcode';
import 'codemirror/addon/fold/foldgutter';
import 'codemirror/addon/fold/brace-fold';
import 'codemirror/addon/fold/indent-fold';
import 'codemirror/addon/edit/matchbrackets';
import 'codemirror/addon/edit/closebrackets';
import 'codemirror-graphql/hint';
import 'codemirror-graphql/lint';
import 'codemirror-graphql/mode';
import 'codemirror-graphql/info';
import 'codemirror-graphql/jump';

import { marked } from 'marked';

import { initialQuery } from './initialQuery';

const AUTOCOMPLETE_CHARS = /^[a-zA-Z0-9_@(]$/;

@Component({
  selector: 'app-query-editor',
  templateUrl: './query-editor.component.html',
  styleUrls: ['./query-editor.component.scss']
})
export class QueryEditorComponent implements AfterViewInit, OnChanges {

  @Output() sendRequest = new EventEmitter();
  @Output() toggleHeaderDialog = new EventEmitter();

  _query = localStorage.getItem('altair:query');
  @Output() queryChange = new EventEmitter<string>();
  @Input()
  public set initialQuery(val: string){
    if (!val) {
      val = initialQuery;
    }
    this._query = val;
    if (this.codeEditor) {
      this.codeEditor.setValue(val);
    }
  }

  codeEditor = null;
  @Input() gqlSchema = null;

  constructor() { }

  ngAfterViewInit() {
    const editorTextArea = document.querySelector('.app-query-editor-input');
    const editorOptions = <any>{
      mode: 'graphql',
      lineWrapping: true,
      lineNumbers: true,
      foldGutter: true,
      tabSize: 2,
      extraKeys: {
        'Cmd-Enter': (cm) => this.sendRequest.next(cm),
        'Ctrl-Enter': (cm) => this.sendRequest.next(cm),
        'Ctrl-Space': () => this.codeEditor.showHint({ completeSingle: true })
      },
      gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
      autoCloseBrackets: true,
      matchBrackets: true
    };

    if (this.gqlSchema) {
      editorOptions.lint = {};
      editorOptions.hintOptions = {
        completeSingle: false
      };
      editorOptions.info = {
        renderDescription: text => {
          return marked(text, { sanitize: true });
        }
      };
      editorOptions.jump = {};
    }<commit_msg>Fixed updating schema when the URL is set.<commit_after>import {
  Component,
  OnInit,
  AfterViewInit,
  OnChanges,
  Input,
  Output,
  EventEmitter,
  SimpleChanges
} from '@angular/core';

// Import the codemirror packages
import Codemirror from 'codemirror';
import 'codemirror/addon/comment/comment';
import 'codemirror/addon/hint/show-hint';
import 'codemirror/addon/lint/lint';
import 'codemirror/addon/fold/foldcode';
import 'codemirror/addon/fold/foldgutter';
import 'codemirror/addon/fold/brace-fold';
import 'codemirror/addon/fold/indent-fold';
import 'codemirror/addon/edit/matchbrackets';
import 'codemirror/addon/edit/closebrackets';
import 'codemirror-graphql/hint';
import 'codemirror-graphql/lint';
import 'codemirror-graphql/mode';
import 'codemirror-graphql/info';
import 'codemirror-graphql/jump';

import { marked } from 'marked';

import { initialQuery } from './initialQuery';

const AUTOCOMPLETE_CHARS = /^[a-zA-Z0-9_@(]$/;

@Component({
  selector: 'app-query-editor',
  templateUrl: './query-editor.component.html',
  styleUrls: ['./query-editor.component.scss']
})
export class QueryEditorComponent implements AfterViewInit, OnChanges {

  @Output() sendRequest = new EventEmitter();
  @Output() toggleHeaderDialog = new EventEmitter();

  _query = localStorage.getItem('altair:query');
  @Output() queryChange = new EventEmitter<string>();
  @Input()
  public set initialQuery(val: string){
    if (!val) {
      val = initialQuery;
    }
    this._query = val;
    if (this.codeEditor) {
      this.codeEditor.setValue(val);
    }
  }

  codeEditor = null;
  @Input() gqlSchema = null;

  constructor() { }

  ngAfterViewInit() {
    const editorTextArea = document.querySelector('.app-query-editor-input');
    const editorOptions = <any>{
      mode: 'graphql',
      lineWrapping: true,
      lineNumbers: true,
      foldGutter: true,
      tabSize: 2,
      extraKeys: {
        'Cmd-Enter': (cm) => this.sendRequest.next(cm),
        'Ctrl-Enter': (cm) => this.sendRequest.next(cm),
        'Ctrl-Space': () => this.codeEditor.showHint({ completeSingle: true })
      },
      gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
      autoCloseBrackets: true,
      matchBrackets: true,
      lint: {},
      hintOptions: {},
      info: {},
      jump: {}
    };

    if (this.gqlSchema) {
      editorOptions.lint = {};
      editorOptions.hintOptions = {
        completeSingle: false
      };
      editorOptions.info = {
        renderDescription: text => {
          return marked(text, { sanitize: true });
        }
      };
      editorOptions.jump = {};
    }
{'fraction_non_alphanumeric': 0.14360872954014028, 'fraction_numerical': 0.0011691348402182386, 'mean_word_length': 3.4596003475238923, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4883940', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1682, 'n_words': 319}