<commit_before>// Concrete Model Editor
//
// Copyright (c) 2010 <NAME>
//
// Concrete is freely distributable under the terms of an MIT-style license.

Concrete.Editor = Class.create({

  // Options:
  //   readOnlyMode: if set, the model can not be modified via user events, default: false
  //   clipboard:    if a DOM node is provided it is used as clipboard, default: internal clipboard
  //   rootClasses:  set of classes which can be instaniated on root level, default: all 
  //   externalIdentifierProvider: 
  //                 an object providing access to identifiers of objects which are not
  //                 part of the model being edited in this instance of the editor, default: none
  //   externalModule: name of the external module which represents the module being edited
  //                 by this instance of the editor (see externalIdentifierProvider)
  //                 if set, external identifiers from the named module will be ignored, default: none
  //   followReferenceSupport:
  //                 if set to true, this editor will provide the functionality to follow references
  //                 and to step back and forward in the jump history, default: true
  //   onFollowReference:
  //                 a function which will be called when a reference is invoked
  //                 it gets two argments, the source reference element and the target element, default: none
  //   onFollowExternalReference:
  //                 a function which will be called when an external reference is invoked, 
  //                 it gets two arguments, the module (provided by the identifier provider) and the identifier,
  //                 if not defined, external references can not be followed, default: none
  //   scrolling:    specifies if the current element should scroll into view
  //                 possible values: none, horizontal, vertical, both, default: both
  //   allowDuplicates: classes of which instances with the same identifier may exist, default: none              
  //
	initialize: function(editorRoot, templateProvider, metamodelProvider, identifierProvider, options) {
    this.options = options || {};
    if (this.options.readOnlyMode == undefined) this.options.readOnlyMode = false;
    if (this.options.followReferenceSupport == undefined) this.options.followReferenceSupport = true;
    this.options.scrolling = this.options.scrolling || "both";
		this.editorRoot = editorRoot;
		this._setupRoot();
		this.templateProvider = templateProvider;
		this.metamodelProvider = metamodelProvider;
		this.identifierProvider = identifierProvider;
		this._createInlineEditor();
		this.modelInterface = new Concrete.ModelInterface(this.modelRoot, this.templateProvider, this.metamodelProvider);
		this.modelInterface.addModelChangeListener(this.identifierProvider);
		this.rootClasses = (options && options.rootClasses) || this.metamodelProvider.metaclasses;
		this.maxRootElements = -1;
    this.externalIdentifierProvider = options.externalIdentifierProvider;
		this.constraintChecker = new Concrete.ConstraintChecker(this.modelRoot, this.rootClasses, this.identifierProvider, 
      {externalIdentifierProvider: this.externalIdentifierProvider, 
       externalModule: this.options.externalModule,
       allowDuplicates: this.options.allowDuplicates});
		this.modelInterface.addModelChangeListener(this.constraintChecker);
		this.modelRoot.insert({top: this.templateProvider.emptyElement()});
		this.selector = this._createSelector();
		this.selector.selectDirect(this.modelRoot.down());
		this.adjustMarker();
		this.jumpStack = [];
		this.clipboard = (options && options.clipboard) || new Concrete.Clipboard();
    this.onFollowReference = options.onFollowReference;
    this.onFollowExternalReference = options.onFollowExternalReference;
		this._hasFocus = false;
	},
	
	_setupRoot: function() {
		this.editorRoot.insert({top: "<div class='ct_root'></div>"});
		this.modelRoot = this.editorRoot.childElements().first();
		this.editorRoot.insert({bottom: "<div style='position: absolute; left: 0; top: 0' class='ct_cursor'></div>"});
		this.marker = this.editorRoot.childElements().last();
		this.editorRoot.insert({bottom: "<div style='position: fixed; display: none; left: 0; top: 0;' class='ct_error_popup'></div>"});
		this.popup = this.editorRoot.childElements().last();
	},
	
	_createInlineEditor: function() {
		var marker = this.marker;
		this.inlineEditor = new Concrete.InlineEditor(function(isActive) {
			if (isActive) {
				marker.hide();
			}
			else {
				marker.show();
			}
		});
	},
	
	_createSelector: function() {
		var editor = this;
		return new Concrete.Selector( 
			function(oldNode, newNode) {
				if (editor.options.scrolling != "none") Concrete.Scroller.scrollTo(newNode, editor.options.scrolling);
				if (oldNode) {
					if (!newNode.ancestors().include(oldNode) && newNode != oldNode) {
						editor.hideEmptyFeatures(oldNode);
					}
				}
				editor.adjustMarker();
			});
	},
		
	handleEvent: function(event) {
		if (event.type == "click" && event.isLeftClick()) {
			if (Event.element(event).ancestors().concat(Event.element(event)).include(this.editorRoot)) {
				this._hasFocus = true;
				this.editorRoot.addClassName("ct_focus");
			}
			else {
				this._hasFocus = false;
				this.editorRoot.removeClassName("ct_focus");
			}
		}
		if (!this._hasFocus) return;
		
		if (event.type == "mousemove") {
			this._handleErrorHighlight(event);
			this._handleRefHighlight(event);
		}
		if (this.inlineEditor.isActive) {
			if (event.type == "click" && event.isLeftClick()) {
				this.inlineEditor.cancel()
				this.selector.selectDirect(Event.element(event));	
			}
			else if (event.keyCode == 9) { 	// tab
				this.inlineEditor.finish();
				if (event.shiftKey) {<commit_msg>fixed hiding of empty features<commit_after>// Concrete Model Editor
//
// Copyright (c) 2010 <NAME>
//
// Concrete is freely distributable under the terms of an MIT-style license.

Concrete.Editor = Class.create({

  // Options:
  //   readOnlyMode: if set, the model can not be modified via user events, default: false
  //   clipboard:    if a DOM node is provided it is used as clipboard, default: internal clipboard
  //   rootClasses:  set of classes which can be instaniated on root level, default: all 
  //   externalIdentifierProvider: 
  //                 an object providing access to identifiers of objects which are not
  //                 part of the model being edited in this instance of the editor, default: none
  //   externalModule: name of the external module which represents the module being edited
  //                 by this instance of the editor (see externalIdentifierProvider)
  //                 if set, external identifiers from the named module will be ignored, default: none
  //   followReferenceSupport:
  //                 if set to true, this editor will provide the functionality to follow references
  //                 and to step back and forward in the jump history, default: true
  //   onFollowReference:
  //                 a function which will be called when a reference is invoked
  //                 it gets two argments, the source reference element and the target element, default: none
  //   onFollowExternalReference:
  //                 a function which will be called when an external reference is invoked, 
  //                 it gets two arguments, the module (provided by the identifier provider) and the identifier,
  //                 if not defined, external references can not be followed, default: none
  //   scrolling:    specifies if the current element should scroll into view
  //                 possible values: none, horizontal, vertical, both, default: both
  //   allowDuplicates: classes of which instances with the same identifier may exist, default: none              
  //
	initialize: function(editorRoot, templateProvider, metamodelProvider, identifierProvider, options) {
    this.options = options || {};
    if (this.options.readOnlyMode == undefined) this.options.readOnlyMode = false;
    if (this.options.followReferenceSupport == undefined) this.options.followReferenceSupport = true;
    this.options.scrolling = this.options.scrolling || "both";
		this.editorRoot = editorRoot;
		this._setupRoot();
		this.templateProvider = templateProvider;
		this.metamodelProvider = metamodelProvider;
		this.identifierProvider = identifierProvider;
		this._createInlineEditor();
		this.modelInterface = new Concrete.ModelInterface(this.modelRoot, this.templateProvider, this.metamodelProvider);
		this.modelInterface.addModelChangeListener(this.identifierProvider);
		this.rootClasses = (options && options.rootClasses) || this.metamodelProvider.metaclasses;
		this.maxRootElements = -1;
    this.externalIdentifierProvider = options.externalIdentifierProvider;
		this.constraintChecker = new Concrete.ConstraintChecker(this.modelRoot, this.rootClasses, this.identifierProvider, 
      {externalIdentifierProvider: this.externalIdentifierProvider, 
       externalModule: this.options.externalModule,
       allowDuplicates: this.options.allowDuplicates});
		this.modelInterface.addModelChangeListener(this.constraintChecker);
		this.modelRoot.insert({top: this.templateProvider.emptyElement()});
		this.selector = this._createSelector();
		this.selector.selectDirect(this.modelRoot.down());
		this.adjustMarker();
		this.jumpStack = [];
		this.clipboard = (options && options.clipboard) || new Concrete.Clipboard();
    this.onFollowReference = options.onFollowReference;
    this.onFollowExternalReference = options.onFollowExternalReference;
		this._hasFocus = false;
	},
	
	_setupRoot: function() {
		this.editorRoot.insert({top: "<div class='ct_root'></div>"});
		this.modelRoot = this.editorRoot.childElements().first();
		this.editorRoot.insert({bottom: "<div style='position: absolute; left: 0; top: 0' class='ct_cursor'></div>"});
		this.marker = this.editorRoot.childElements().last();
		this.editorRoot.insert({bottom: "<div style='position: fixed; display: none; left: 0; top: 0;' class='ct_error_popup'></div>"});
		this.popup = this.editorRoot.childElements().last();
	},
	
	_createInlineEditor: function() {
		var marker = this.marker;
		this.inlineEditor = new Concrete.InlineEditor(function(isActive) {
			if (isActive) {
				marker.hide();
			}
			else {
				marker.show();
			}
		});
	},
	
	_createSelector: function() {
		var editor = this;
		return new Concrete.Selector( 
			function(oldNode, newNode) {
				if (editor.options.scrolling != "none") Concrete.Scroller.scrollTo(newNode, editor.options.scrolling);
				if (oldNode && newNode != oldNode) {
          var oa = oldNode.ancestors();
          oa.unshift(oldNode);
          var na = newNode.ancestors();
          na.unshift(newNode);
          oa.reverse().each(function(n) {
            if (n != na.pop() && n.isElement()) {
              editor.hideEmptyFeatures(n);
            }
          });
				}
				editor.adjustMarker();
			});
	},
		
	handleEvent: function(event) {
		if (event.type == "click" && event.isLeftClick()) {
			if (Event.element(event).ancestors().concat(Event.element(event)).include(this.editorRoot)) {
				this._hasFocus = true;
				this.editorRoot.addClassName("ct_focus");
			}
			else {
				this._hasFocus = false;
				this.editorRoot.removeClassName("ct_focus");
			}
		}
		if (!this._hasFocus) return;
		
		if (event.type == "mousemove") {
			this._handleErrorHighlight(event);
			this._handleRefHighlight(event);
		}
		if (this.inlineEditor.isActive) {
			if (event.type == "click" && event.isLeftClick()) {
				this.inlineEditor.cancel()
				this.selector.selectDirect(Event.element(event));	
			}
			else if (event.keyCode == 9) { 	// tab
				this.inlineEditor.finish();
				if (event.shiftKey) {
{'fraction_non_alphanumeric': 0.11226222826086957, 'fraction_numerical': 0.0016983695652173913, 'mean_word_length': 3.4009715994020926, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3696602', 'n_tokens_mistral': 3483, 'n_tokens_neox': 3183, 'n_words': 865}