B2G/gecko/browser/devtools/styleeditor/StyleEditor.jsm
/**
   * Set the input element that handles display and input for this editor.
   * This detaches the previous input element if previously set.
   *
   * @param DOMElement aElement
   */
Set the input element that handles display and input for this editor.
This detaches the previous input element if previously set.


Set the input element that handles display and input for this editor . This detaches the previous input element if previously set .
set inputElement(aElement)
  {
    if (aElement == this._inputElement) {
      return; 
    }
    if (this._inputElement) {
      if (this._sourceEditor) {
        this._state = {
          text: this._sourceEditor.getText(),
          selection: this._sourceEditor.getSelection(),
          readOnly: this._sourceEditor.readOnly,
          topIndex: this._sourceEditor.getTopIndex(),
        };
        this._sourceEditor.destroy();
        this._sourceEditor = null;
      }
      this.window.removeEventListener("unload",
                                      this._onWindowUnloadBinding, false);
      this._triggerAction("Detach");
    }
    this._inputElement = aElement;
    if (!aElement) {
      return;
    }
    this.window.addEventListener("unload", this._onWindowUnloadBinding, false);
    this._focusOnSourceEditorReady = false;
    this._sourceEditor = null; 
    let sourceEditor = new SourceEditor();
    let config = {
      initialText: this._state.text,
      showLineNumbers: true,
      mode: SourceEditor.MODES.CSS,
      readOnly: this._state.readOnly,
      keys: this._getKeyBindings()
    };
    sourceEditor.init(aElement, config, function onSourceEditorReady() {
      setupBracketCompletion(sourceEditor);
      sourceEditor.addEventListener(SourceEditor.EVENTS.TEXT_CHANGED,
                                    function onTextChanged(aEvent) {
        this.updateStyleSheet();
      }.bind(this));
      this._sourceEditor = sourceEditor;
      if (this._focusOnSourceEditorReady) {
        this._focusOnSourceEditorReady = false;
        sourceEditor.focus();
      }
      sourceEditor.setTopIndex(this._state.topIndex);
      sourceEditor.setSelection(this._state.selection.start,
                                this._state.selection.end);
      this._triggerAction("Attach");
    }.bind(this));
  }
set inputElement ( aElement ) { if ( aElement == this . _inputElement ) { return ; } if ( this . _inputElement ) { if ( this . _sourceEditor ) { this . _state = { text : this . _sourceEditor . getText ( ) , selection : this . _sourceEditor . getSelection ( ) , readOnly : this . _sourceEditor . readOnly , topIndex : this . _sourceEditor . getTopIndex ( ) , } ; this . _sourceEditor . destroy ( ) ; this . _sourceEditor = null ; } this . window . removeEventListener ( "unload" , this . _onWindowUnloadBinding , false ) ; this . _triggerAction ( "Detach" ) ; } this . _inputElement = aElement ; if ( ! aElement ) { return ; } this . window . addEventListener ( "unload" , this . _onWindowUnloadBinding , false ) ; this . _focusOnSourceEditorReady = false ; this . _sourceEditor = null ; let sourceEditor = new SourceEditor ( ) ; let config = { initialText : this . _state . text , showLineNumbers : true , mode : SourceEditor . MODES . CSS , readOnly : this . _state . readOnly , keys : this . _getKeyBindings ( ) } ; sourceEditor . init ( aElement , config , function onSourceEditorReady ( ) { setupBracketCompletion ( sourceEditor ) ; sourceEditor . addEventListener ( SourceEditor . EVENTS . TEXT_CHANGED , function onTextChanged ( aEvent ) { this . updateStyleSheet ( ) ; } . bind ( this ) ) ; this . _sourceEditor = sourceEditor ; if ( this . _focusOnSourceEditorReady ) { this . _focusOnSourceEditorReady = false ; sourceEditor . focus ( ) ; } sourceEditor . setTopIndex ( this . _state . topIndex ) ; sourceEditor . setSelection ( this . _state . selection . start , this . _state . selection . end ) ; this . _triggerAction ( "Attach" ) ; } . bind ( this ) ) ; }
Set the input element that handles display and input for this editor.
Set the input element that handles display and input for this editor .
// no change // detach from current input element // save existing state first (for seamless reattach) // attach to new input element // set it only when ready (safe to use)