src/widgets/Dialogs.js
function (e, autoDismiss) {
        var $primaryBtn     = this.find(".primary"),
            buttonId        = null,
            which           = String.fromCharCode(e.which),
            $focusedElement = this.find(".dialog-button:focus, a:focus");

        function stopEvent() {
            e.preventDefault();
            e.stopPropagation();
        }

        // There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal
        var inTextArea    = (e.target.tagName === "TEXTAREA"),
            inTypingField = inTextArea || ($(e.target).filter(":text, :password").length > 0);

        if (e.which === KeyEvent.DOM_VK_TAB) {
            // We don't want to stopEvent() in this case since we might want the default behavior.
            // _handleTab takes care of stopping/preventing default as necessary.
            _handleTab(e, this);
        } else if (e.which === KeyEvent.DOM_VK_ESCAPE) {
            buttonId = DIALOG_BTN_CANCEL;
        } else if (e.which === KeyEvent.DOM_VK_RETURN && (!inTextArea || e.ctrlKey)) {
            // Enter key in single-line text input always dismisses; in text area, only Ctrl+Enter dismisses
            // Click primary
            stopEvent();
            if (e.target.tagName === "BUTTON") {
                this.find(e.target).click();
            } else if (e.target.tagName !== "INPUT") {
                // If the target element is not BUTTON or INPUT, click the primary button
                // We're making an exception for INPUT element because of this issue: GH-11416
                $primaryBtn.click();
            }
        } else if (e.which === KeyEvent.DOM_VK_SPACE) {
            if ($focusedElement.length) {
                // Space bar on focused button or link
                stopEvent();
                $focusedElement.click();
            }
        } else if (brackets.platform === "mac") {
            // CMD+Backspace Don't Save
            if (e.metaKey && (e.which === KeyEvent.DOM_VK_BACK_SPACE)) {
                if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
                    buttonId = DIALOG_BTN_DONTSAVE;
                }
            // FIXME (issue #418) CMD+. Cancel swallowed by native shell
            } else if (e.metaKey && (e.which === KeyEvent.DOM_VK_PERIOD)) {
                buttonId = DIALOG_BTN_CANCEL;
            }
        } else { // if (brackets.platform === "win") {
            // 'N' Don't Save
            if (which === "N" && !inTypingField) {
                if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
                    buttonId = DIALOG_BTN_DONTSAVE;
                }
            }
        }

        if (buttonId) {
            stopEvent();
            _processButton(this, buttonId, autoDismiss);
        }

        // Stop any other global hooks from processing the event (but
        // allow it to continue bubbling if we haven't otherwise stopped it).
        return true;
    }
function (e, autoDismiss) {
        var $primaryBtn     = this.find(".primary"),
            buttonId        = null,
            which           = String.fromCharCode(e.which),
            $focusedElement = this.find(".dialog-button:focus, a:focus");

        function stopEvent() {
            e.preventDefault();
            e.stopPropagation();
        }

        // There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal
        var inTextArea    = (e.target.tagName === "TEXTAREA"),
            inTypingField = inTextArea || ($(e.target).filter(":text, :password").length > 0);

        if (e.which === KeyEvent.DOM_VK_TAB) {
            // We don't want to stopEvent() in this case since we might want the default behavior.
            // _handleTab takes care of stopping/preventing default as necessary.
            _handleTab(e, this);
        } else if (e.which === KeyEvent.DOM_VK_ESCAPE) {
            buttonId = DIALOG_BTN_CANCEL;
        } else if (e.which === KeyEvent.DOM_VK_RETURN && (!inTextArea || e.ctrlKey)) {
            // Enter key in single-line text input always dismisses; in text area, only Ctrl+Enter dismisses
            // Click primary
            stopEvent();
            if (e.target.tagName === "BUTTON") {
                this.find(e.target).click();
            } else if (e.target.tagName !== "INPUT") {
                // If the target element is not BUTTON or INPUT, click the primary button
                // We're making an exception for INPUT element because of this issue: GH-11416
                $primaryBtn.click();
            }
        } else if (e.which === KeyEvent.DOM_VK_SPACE) {
            if ($focusedElement.length) {
                // Space bar on focused button or link
                stopEvent();
                $focusedElement.click();
            }
        } else if (brackets.platform === "mac") {
            // CMD+Backspace Don't Save
            if (e.metaKey && (e.which === KeyEvent.DOM_VK_BACK_SPACE)) {
                if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
                    buttonId = DIALOG_BTN_DONTSAVE;
                }
            // FIXME (issue #418) CMD+. Cancel swallowed by native shell
            } else if (e.metaKey && (e.which === KeyEvent.DOM_VK_PERIOD)) {
                buttonId = DIALOG_BTN_CANCEL;
            }
        } else { // if (brackets.platform === "win") {
            // 'N' Don't Save
            if (which === "N" && !inTypingField) {
                if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
                    buttonId = DIALOG_BTN_DONTSAVE;
                }
            }
        }

        if (buttonId) {
            stopEvent();
            _processButton(this, buttonId, autoDismiss);
        }

        // Stop any other global hooks from processing the event (but
        // allow it to continue bubbling if we haven't otherwise stopped it).
        return true;
    }
function ( e , autoDismiss ) { var $primaryBtn = this . find ( ".primary" ) , buttonId = null , which = String . fromCharCode ( e . which ) , $focusedElement = this . find ( ".dialog-button:focus, a:focus" ) ; function stopEvent ( ) { e . preventDefault ( ) ; e . stopPropagation ( ) ; } // There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal var inTextArea = ( e . target . tagName === "TEXTAREA" ) , inTypingField = inTextArea || ( $ ( e . target ) . filter ( ":text, :password" ) . length > 0 ) ; if ( e . which === KeyEvent . DOM_VK_TAB ) { // We don't want to stopEvent() in this case since we might want the default behavior. // _handleTab takes care of stopping/preventing default as necessary. _handleTab ( e , this ) ; } else if ( e . which === KeyEvent . DOM_VK_ESCAPE ) { buttonId = DIALOG_BTN_CANCEL ; } else if ( e . which === KeyEvent . DOM_VK_RETURN && ( ! inTextArea || e . ctrlKey ) ) { // Enter key in single-line text input always dismisses; in text area, only Ctrl+Enter dismisses // Click primary stopEvent ( ) ; if ( e . target . tagName === "BUTTON" ) { this . find ( e . target ) . click ( ) ; } else if ( e . target . tagName !== "INPUT" ) { // If the target element is not BUTTON or INPUT, click the primary button // We're making an exception for INPUT element because of this issue: GH-11416 $primaryBtn . click ( ) ; } } else if ( e . which === KeyEvent . DOM_VK_SPACE ) { if ( $focusedElement . length ) { // Space bar on focused button or link stopEvent ( ) ; $focusedElement . click ( ) ; } } else if ( brackets . platform === "mac" ) { // CMD+Backspace Don't Save if ( e . metaKey && ( e . which === KeyEvent . DOM_VK_BACK_SPACE ) ) { if ( _hasButton ( this , DIALOG_BTN_DONTSAVE ) ) { buttonId = DIALOG_BTN_DONTSAVE ; } // FIXME (issue #418) CMD+. Cancel swallowed by native shell } else if ( e . metaKey && ( e . which === KeyEvent . DOM_VK_PERIOD ) ) { buttonId = DIALOG_BTN_CANCEL ; } } else { // if (brackets.platform === "win") { // 'N' Don't Save if ( which === "N" && ! inTypingField ) { if ( _hasButton ( this , DIALOG_BTN_DONTSAVE ) ) { buttonId = DIALOG_BTN_DONTSAVE ; } } } if ( buttonId ) { stopEvent ( ) ; _processButton ( this , buttonId , autoDismiss ) ; } // Stop any other global hooks from processing the event (but // allow it to continue bubbling if we haven't otherwise stopped it). return true ; }
Handles the keyDown event for the dialogs
@param {$.Event} e
@param {boolean} autoDismiss
@return {boolean}
Handles the keyDown event for the dialogs