From 1274227bc78757192943af04aa5ab8760c8d5903 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 12 Mar 2014 10:38:36 -0700 Subject: [PATCH 01/24] Editor Preferences Validation - interim checkin --- src/editor/CSSInlineEditor.js | 3 ++- src/editor/Editor.js | 38 ++++++++++++++++++++++++--- src/editor/EditorStatusBar.js | 30 ++++++++++++--------- src/extensions/default/JSLint/main.js | 4 ++- test/spec/SpecRunnerUtils.js | 3 ++- 5 files changed, 58 insertions(+), 20 deletions(-) diff --git a/src/editor/CSSInlineEditor.js b/src/editor/CSSInlineEditor.js index 6e4fe5b4f59..54a0608f87a 100644 --- a/src/editor/CSSInlineEditor.js +++ b/src/editor/CSSInlineEditor.js @@ -107,7 +107,8 @@ define(function (require, exports, module) { */ function _addRule(selectorName, inlineEditor, path) { DocumentManager.getDocumentForPath(path).done(function (styleDoc) { - var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, Editor.getUseTabChar(), Editor.getSpaceUnits()); +// var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, Editor.getUseTabChar(), Editor.getSpaceUnits()); + var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, Editor.getUseTabChar(), inlineEditor.getSpaceUnits()); inlineEditor.addAndSelectRange(selectorName, styleDoc, newRuleInfo.range.from.line, newRuleInfo.range.to.line); inlineEditor.editor.setCursorPos(newRuleInfo.pos.line, newRuleInfo.pos.ch); }); diff --git a/src/editor/Editor.js b/src/editor/Editor.js index bd8f8ba6d0d..848fed95d23 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1539,7 +1539,31 @@ define(function (require, exports, module) { * @return {*} current value of that pref */ Editor.prototype._getOption = function (prefName) { - return PreferencesManager.get(prefName, this.document.file.fullPath); + var value; + + // Call getter methods where appropriate for validation + switch (prefName) { + + case SPACE_UNITS: + value = this.getSpaceUnits(); + break; + +// TODO - convert Editor.get...() to Editor.prototype.get...() +// case SMART_INDENT: +// case USE_TAB_CHAR: +// case TAB_SIZE: +// case CLOSE_BRACKETS: +// case SHOW_LINE_NUMBERS: +// case STYLE_ACTIVE_LINE: +// case WORD_WRAP: +// case CLOSE_TAGS: + + default: + value = PreferencesManager.get(prefName, this.document.file.fullPath); + break; + } + + return value; }; /** @@ -1630,13 +1654,19 @@ define(function (require, exports, module) { * Affects any editors that share the same preference location. * @param {number} value */ - Editor.setSpaceUnits = function (value) { + Editor.prototype.setSpaceUnits = function (value) { PreferencesManager.set(SPACE_UNITS, value); }; /** @type {number} Get indentation width */ - Editor.getSpaceUnits = function () { - return PreferencesManager.get(SPACE_UNITS); + Editor.prototype.getSpaceUnits = function () { + var value = PreferencesManager.get(SPACE_UNITS, this.document.file.fullPath); + +// TODO: +// 1. VALIDATE +// 2. Run UNIT TESTS + + return value; }; /** diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index 68e431d35fd..e3b3a6a4d29 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -71,20 +71,22 @@ define(function (require, exports, module) { $indentWidthLabel.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_TABS : Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES); } - function _getIndentSize() { - return Editor.getUseTabChar() ? Editor.getTabSize() : Editor.getSpaceUnits(); + function _getIndentSize(editor) { +// return Editor.getUseTabChar() ? Editor.getTabSize() : Editor.getSpaceUnits(); + return Editor.getUseTabChar() ? Editor.getTabSize() : editor.getSpaceUnits(); } - function _updateIndentSize() { - var size = _getIndentSize(); + function _updateIndentSize(editor) { + var size = _getIndentSize(editor); $indentWidthLabel.text(size); $indentWidthInput.val(size); } function _toggleIndentType() { + var current = EditorManager.getActiveEditor(); Editor.setUseTabChar(!Editor.getUseTabChar()); _updateIndentType(); - _updateIndentSize(); + _updateIndentSize(current); } function _updateCursorInfo(event, editor) { @@ -115,7 +117,7 @@ define(function (require, exports, module) { } } - function _changeIndentWidth(value) { + function _changeIndentWidth(editor, value) { $indentWidthLabel.removeClass("hidden"); $indentWidthInput.addClass("hidden"); @@ -133,11 +135,12 @@ define(function (require, exports, module) { if (Editor.getUseTabChar()) { Editor.setTabSize(value); } else { - Editor.setSpaceUnits(value); +// Editor.setSpaceUnits(value); + editor.setSpaceUnits(value); } // update indicator - _updateIndentSize(); + _updateIndentSize(editor); // column position may change when tab size changes _updateCursorInfo(); @@ -184,7 +187,7 @@ define(function (require, exports, module) { $(current).on("cursorActivity.statusbar", _updateCursorInfo); $(current).on("optionChange.statusbar", function () { _updateIndentType(); - _updateIndentSize(); + _updateIndentSize(current); }); $(current).on("change.statusbar", function () { // async update to keep typing speed smooth @@ -200,7 +203,7 @@ define(function (require, exports, module) { _updateFileInfo(current); _initOverwriteMode(current); _updateIndentType(); - _updateIndentSize(); + _updateIndentSize(current); } } @@ -218,7 +221,8 @@ define(function (require, exports, module) { $indentWidthLabel .on("click", function () { // update the input value before displaying - $indentWidthInput.val(_getIndentSize()); + var current = EditorManager.getActiveEditor(); + $indentWidthInput.val(_getIndentSize(current)); $indentWidthLabel.addClass("hidden"); $indentWidthInput.removeClass("hidden"); @@ -226,13 +230,13 @@ define(function (require, exports, module) { $indentWidthInput .on("blur", function () { - _changeIndentWidth($indentWidthInput.val()); + _changeIndentWidth(current, $indentWidthInput.val()); }) .on("keyup", function (event) { if (event.keyCode === KeyEvent.DOM_VK_RETURN) { $indentWidthInput.blur(); } else if (event.keyCode === KeyEvent.DOM_VK_ESCAPE) { - _changeIndentWidth(false); + _changeIndentWidth(current, false); } }); }); diff --git a/src/extensions/default/JSLint/main.js b/src/extensions/default/JSLint/main.js index 4fbeb8e7361..306fbdb71b6 100644 --- a/src/extensions/default/JSLint/main.js +++ b/src/extensions/default/JSLint/main.js @@ -88,7 +88,9 @@ define(function (require, exports, module) { if (!options.indent) { // default to using the same indentation value that the editor is using - options.indent = PreferencesManager.get("spaceUnits"); +// options.indent = PreferencesManager.get("spaceUnits"); + // Validation is editor-specific (editor.getSpaceUnits), so self validate + options.indent = PreferencesManager.get("spaceUnits", fullPath) || 4; } // If the user has not defined the environment, we use browser by default. diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index ecdc69d1ae8..a38bd7ce1c4 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -405,7 +405,8 @@ define(function (require, exports, module) { // create Editor instance var editor = new Editor(doc, true, $editorHolder.get(0), visibleRange); Editor.setUseTabChar(EDITOR_USE_TABS); - Editor.setSpaceUnits(EDITOR_SPACE_UNITS); +// Editor.setSpaceUnits(EDITOR_SPACE_UNITS); + editor.setSpaceUnits(EDITOR_SPACE_UNITS); EditorManager._notifyActiveEditorChanged(editor); return editor; From 1b1a60450d8c0c429d03ba08d281c412b9d2ceb9 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 12 Mar 2014 15:54:09 -0700 Subject: [PATCH 02/24] start ValidationUtils module --- src/editor/Editor.js | 18 ++++--- src/utils/ValidationUtils.js | 85 +++++++++++++++++++++++++++++++ test/UnitTestSuite.js | 1 + test/spec/ValidationUtils-test.js | 82 +++++++++++++++++++++++++++++ 4 files changed, 179 insertions(+), 7 deletions(-) create mode 100644 src/utils/ValidationUtils.js create mode 100644 test/spec/ValidationUtils-test.js diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 848fed95d23..99746e98458 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -73,6 +73,7 @@ define(function (require, exports, module) { ViewUtils = require("utils/ViewUtils"), Async = require("utils/Async"), AnimationUtils = require("utils/AnimationUtils"), + ValidationUtils = require("utils/ValidationUtils"), _ = require("thirdparty/lodash"); /** Editor preferences */ @@ -87,6 +88,11 @@ define(function (require, exports, module) { CLOSE_TAGS = "closeTags", cmOptions = {}; + /** @type {number} Constants: default preference values */ + var DEFAULT_SPACE_UNITS = 4, + DEFAULT_TAB_SIZE = 4; + + // Mappings from Brackets preferences to CodeMirror options cmOptions[SMART_INDENT] = "smartIndent"; cmOptions[USE_TAB_CHAR] = "indentWithTabs"; @@ -100,8 +106,8 @@ define(function (require, exports, module) { PreferencesManager.definePreference(SMART_INDENT, "boolean", true); PreferencesManager.definePreference(USE_TAB_CHAR, "boolean", false); - PreferencesManager.definePreference(TAB_SIZE, "number", 4); - PreferencesManager.definePreference(SPACE_UNITS, "number", 4); + PreferencesManager.definePreference(TAB_SIZE, "number", DEFAULT_TAB_SIZE); + PreferencesManager.definePreference(SPACE_UNITS, "number", DEFAULT_SPACE_UNITS); PreferencesManager.definePreference(CLOSE_BRACKETS, "boolean", false); PreferencesManager.definePreference(SHOW_LINE_NUMBERS, "boolean", true); PreferencesManager.definePreference(STYLE_ACTIVE_LINE, "boolean", false); @@ -1661,11 +1667,9 @@ define(function (require, exports, module) { /** @type {number} Get indentation width */ Editor.prototype.getSpaceUnits = function () { var value = PreferencesManager.get(SPACE_UNITS, this.document.file.fullPath); - -// TODO: -// 1. VALIDATE -// 2. Run UNIT TESTS - + if (!ValidationUtils.isIntegerInRange(value, 0, null)) { + return DEFAULT_SPACE_UNITS; + } return value; }; diff --git a/src/utils/ValidationUtils.js b/src/utils/ValidationUtils.js new file mode 100644 index 00000000000..a2e7ea24c8c --- /dev/null +++ b/src/utils/ValidationUtils.js @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + + +/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ +/*global define, $, window */ + +define(function (require, exports, module) { + "use strict"; + + + /** + * @private (but might be useful in a Validation module) + * + * Used to validate type of unknown value passed it. + * + * @param {} value Value for which to validate its type + * @return true if value is an integer + */ + function isInteger(value) { + // Validate value is a number + if (typeof (value) !== "number" || isNaN(parseInt(value, 10))) { + return false; + } + + // Validate number is an integer + if (value > 0) { + if (Math.floor(value) !== value) { + return false; + } + } else if (value < 0) { + if (Math.ceil(value) !== value) { + return false; + } + } + + // Validate integer is in range + return true; + } + + /** + * @private (but might be useful in a Validation module) + * + * Used to validate type of unknown value passed it. + * + * @param {} value Value for which to validate its type + * @param {Number=} lowerLimit Optional lower limit (inclusive) + * @param {Number=} upperLimit Optional upper limit (inclusive) + * @return true if value is an interger, and optionally in specified range. + */ + function isIntegerInRange(value, lowerLimit, upperLimit) { + // Validate value is an integer + if (!isInteger(value)) { + return false; + } + + // Validate integer is in range + return ((!lowerLimit || value >= lowerLimit) && (!upperLimit || value <= upperLimit)); + } + + + // Define public API + exports.isInteger = isInteger; + exports.isIntegerInRange = isIntegerInRange; +}); diff --git a/test/UnitTestSuite.js b/test/UnitTestSuite.js index d7c7c943045..92e05550c02 100644 --- a/test/UnitTestSuite.js +++ b/test/UnitTestSuite.js @@ -72,6 +72,7 @@ define(function (require, exports, module) { require("spec/TextRange-test"); require("spec/UpdateNotification-test"); require("spec/UrlParams-test"); + require("spec/ValidationUtils-test"); require("spec/ViewCommandHandlers-test"); require("spec/ViewUtils-test"); require("spec/WorkingSetView-test"); diff --git a/test/spec/ValidationUtils-test.js b/test/spec/ValidationUtils-test.js new file mode 100644 index 00000000000..3b90146216a --- /dev/null +++ b/test/spec/ValidationUtils-test.js @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + + +/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */ +/*global define, describe, it, expect, beforeEach, afterEach, runs */ + +define(function (require, exports, module) { + 'use strict'; + + var ValidationUtils = require("utils/ValidationUtils"); + + describe("ValidationUtils", function () { + it("should accept valid integers as integer", function () { + expect(ValidationUtils.isInteger(0)).toBe(true); + expect(ValidationUtils.isInteger(12)).toBe(true); + expect(ValidationUtils.isInteger(+2)).toBe(true); + expect(ValidationUtils.isInteger(-5)).toBe(true); + expect(ValidationUtils.isInteger(3e07)).toBe(true); + }); + + it("should not accept non-numbers as integer", function () { + expect(ValidationUtils.isInteger(NaN)).toBe(false); + expect(ValidationUtils.isInteger(null)).toBe(false); + expect(ValidationUtils.isInteger(undefined)).toBe(false); + expect(ValidationUtils.isInteger("str")).toBe(false); + expect(ValidationUtils.isInteger(false)).toBe(false); + expect(ValidationUtils.isInteger([0, 1, 2])).toBe(false); + expect(ValidationUtils.isInteger({ch: 0, line: 0})).toBe(false); + }); + + it("should not accept non-integer numbers as integer", function () { + expect(ValidationUtils.isInteger(-Infinity)).toBe(false); + expect(ValidationUtils.isInteger(Math.PI)).toBe(false); + expect(ValidationUtils.isInteger(0.375)).toBe(false); + expect(ValidationUtils.isInteger(3.29834e-02)).toBe(false); + }); + + // ValidationUtils.isIntegerInRange() uses ValidationUtils.isInteger() + // to validate value, so no need to test non-integers + it("should accept integers in range", function () { + // Range limits are optional + expect(ValidationUtils.isIntegerInRange(1)).toBe(true); + expect(ValidationUtils.isIntegerInRange(3, 0)).toBe(true); + expect(ValidationUtils.isIntegerInRange(12, null, 100)).toBe(true); + expect(ValidationUtils.isIntegerInRange(-2, -10, +10)).toBe(true); + expect(ValidationUtils.isIntegerInRange(13, -Infinity, Infinity)).toBe(true); + }); + + it("should accept optional range limit of zero", function () { + expect(ValidationUtils.isIntegerInRange(2, 0, 10)).toBe(true); + expect(ValidationUtils.isIntegerInRange(-62, -100, 0)).toBe(true); + }); + + it("should not accept integers out of range", function () { + expect(ValidationUtils.isIntegerInRange(21, null, 20)).toBe(false); + expect(ValidationUtils.isIntegerInRange(4, 5)).toBe(false); + expect(ValidationUtils.isIntegerInRange(12, 1, 10)).toBe(false); + expect(ValidationUtils.isIntegerInRange(-1000, -100, 100)).toBe(false); + }); + }); +}); From 8d5482e8d0bec07492e3cb2f4e12d61f83ceb6e0 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 12 Mar 2014 17:12:33 -0700 Subject: [PATCH 03/24] convert remaining editor prefs --- src/editor/CSSInlineEditor.js | 2 +- src/editor/Editor.js | 90 ++++++++++++++++++--------- src/editor/EditorStatusBar.js | 20 +++--- src/extensions/default/JSLint/main.js | 6 +- src/utils/ValidationUtils.js | 4 +- test/spec/Editor-test.js | 6 +- 6 files changed, 78 insertions(+), 50 deletions(-) diff --git a/src/editor/CSSInlineEditor.js b/src/editor/CSSInlineEditor.js index c1bf6c45310..6e8b7395501 100644 --- a/src/editor/CSSInlineEditor.js +++ b/src/editor/CSSInlineEditor.js @@ -108,7 +108,7 @@ define(function (require, exports, module) { function _addRule(selectorName, inlineEditor, path) { DocumentManager.getDocumentForPath(path).done(function (styleDoc) { // var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, Editor.getUseTabChar(), Editor.getSpaceUnits()); - var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, Editor.getUseTabChar(), inlineEditor.getSpaceUnits()); + var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, inlineEditor.getUseTabChar(), inlineEditor.getSpaceUnits()); inlineEditor.addAndSelectRange(selectorName, styleDoc, newRuleInfo.range.from.line, newRuleInfo.range.to.line); inlineEditor.editor.setCursorPos(newRuleInfo.pos.line, newRuleInfo.pos.ch); }); diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 67172f8bde2..f002aa10373 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -884,7 +884,7 @@ define(function (require, exports, module) { */ Editor.prototype.getColOffset = function (pos) { var line = this._codeMirror.getRange({line: pos.line, ch: 0}, pos), - tabSize = Editor.getTabSize(), + tabSize = this.getTabSize(), column = 0, i; @@ -1825,20 +1825,30 @@ define(function (require, exports, module) { // Call getter methods where appropriate for validation switch (prefName) { + case SMART_INDENT: + value = this.getSmartIndent(); + break; + case USE_TAB_CHAR: + value = this.getUseTabChar(); + break; + case TAB_SIZE: + value = this.getTabSize(); + break; case SPACE_UNITS: value = this.getSpaceUnits(); break; - -// TODO - convert Editor.get...() to Editor.prototype.get...() -// case SMART_INDENT: -// case USE_TAB_CHAR: -// case TAB_SIZE: -// case CLOSE_BRACKETS: -// case SHOW_LINE_NUMBERS: -// case STYLE_ACTIVE_LINE: -// case WORD_WRAP: -// case CLOSE_TAGS: - + case CLOSE_BRACKETS: + value = this.getCloseBrackets(); + break; + case SHOW_LINE_NUMBERS: + value = this.getShowLineNumbers(); + break; + case STYLE_ACTIVE_LINE: + value = this.getShowActiveLine(); + break; + case WORD_WRAP: + value = this.getWordWrap(); + break; default: value = PreferencesManager.get(prefName, this.document.file.fullPath); break; @@ -1902,18 +1912,32 @@ define(function (require, exports, module) { // Global settings that affect Editor instances that share the same preference locations + /** + * Sets whether to use smart indenting. + * Affects any editors that share the same preference location. + * @param {boolean} value + */ + Editor.prototype.setSmartIndent = function (value) { + PreferencesManager.set(SMART_INDENT, value); + }; + + /** @type {boolean} Gets whether the current editor uses smart indenting */ + Editor.prototype.getSmartIndent = function () { + return !!PreferencesManager.get(SMART_INDENT, this.document.file.fullPath); + }; + /** * Sets whether to use tab characters (vs. spaces) when inserting new text. * Affects any editors that share the same preference location. * @param {boolean} value */ - Editor.setUseTabChar = function (value) { + Editor.prototype.setUseTabChar = function (value) { PreferencesManager.set(USE_TAB_CHAR, value); }; /** @type {boolean} Gets whether the current editor uses tab characters (vs. spaces) when inserting new text */ - Editor.getUseTabChar = function () { - return PreferencesManager.get(USE_TAB_CHAR); + Editor.prototype.getUseTabChar = function () { + return !!PreferencesManager.get(USE_TAB_CHAR, this.document.file.fullPath); }; /** @@ -1921,13 +1945,17 @@ define(function (require, exports, module) { * Affects any editors that share the same preference location. * @param {number} value */ - Editor.setTabSize = function (value) { + Editor.prototype.setTabSize = function (value) { PreferencesManager.set(TAB_SIZE, value); }; - /** @type {number} Get indent unit */ - Editor.getTabSize = function () { - return PreferencesManager.get(TAB_SIZE); + /** @type {number} Get tab character width */ + Editor.prototype.getTabSize = function () { + var value = PreferencesManager.get(TAB_SIZE, this.document.file.fullPath); + if (!ValidationUtils.isIntegerInRange(value, 1, null)) { + return DEFAULT_TAB_SIZE; + } + return value; }; /** @@ -1953,13 +1981,13 @@ define(function (require, exports, module) { * Affects any editors that share the same preference location. * @param {boolean} value */ - Editor.setCloseBrackets = function (value) { + Editor.prototype.setCloseBrackets = function (value) { PreferencesManager.set(CLOSE_BRACKETS, value); }; /** @type {boolean} Gets whether the current editor uses auto close brackets */ - Editor.getCloseBrackets = function () { - return PreferencesManager.get(CLOSE_BRACKETS); + Editor.prototype.getCloseBrackets = function () { + return !!PreferencesManager.get(CLOSE_BRACKETS, this.document.file.fullPath); }; /** @@ -1967,13 +1995,13 @@ define(function (require, exports, module) { * Affects any editors that share the same preference location. * @param {boolean} value */ - Editor.setShowLineNumbers = function (value) { + Editor.prototype.setShowLineNumbers = function (value) { PreferencesManager.set(SHOW_LINE_NUMBERS, value); }; /** @type {boolean} Returns true if show line numbers is enabled for the current editor */ - Editor.getShowLineNumbers = function () { - return PreferencesManager.get(SHOW_LINE_NUMBERS); + Editor.prototype.getShowLineNumbers = function () { + return !!PreferencesManager.get(SHOW_LINE_NUMBERS, this.document.file.fullPath); }; /** @@ -1981,13 +2009,13 @@ define(function (require, exports, module) { * Affects any editors that share the same preference location. * @param {boolean} value */ - Editor.setShowActiveLine = function (value) { + Editor.prototype.setShowActiveLine = function (value) { PreferencesManager.set(STYLE_ACTIVE_LINE, value); }; /** @type {boolean} Returns true if show active line is enabled for the current editor */ - Editor.getShowActiveLine = function () { - return PreferencesManager.get(STYLE_ACTIVE_LINE); + Editor.prototype.getShowActiveLine = function () { + return !!PreferencesManager.get(STYLE_ACTIVE_LINE, this.document.file.fullPath); }; /** @@ -1995,13 +2023,13 @@ define(function (require, exports, module) { * Affects any editors that share the same preference location. * @param {boolean} value */ - Editor.setWordWrap = function (value) { + Editor.prototype.setWordWrap = function (value) { PreferencesManager.set(WORD_WRAP, value); }; /** @type {boolean} Returns true if word wrap is enabled for the current editor */ - Editor.getWordWrap = function () { - return PreferencesManager.get(WORD_WRAP); + Editor.prototype.getWordWrap = function () { + return !!PreferencesManager.get(WORD_WRAP, this.document.file.fullPath); }; // Set up listeners for preference changes diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index 70ba9cf45fd..b9724bad8c5 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -64,16 +64,15 @@ define(function (require, exports, module) { $fileInfo.text(_formatCountable(lines, Strings.STATUSBAR_LINE_COUNT_SINGULAR, Strings.STATUSBAR_LINE_COUNT_PLURAL)); } - function _updateIndentType() { - var indentWithTabs = Editor.getUseTabChar(); + function _updateIndentType(editor) { + var indentWithTabs = editor.getUseTabChar(); $indentType.text(indentWithTabs ? Strings.STATUSBAR_TAB_SIZE : Strings.STATUSBAR_SPACES); $indentType.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_TOOLTIP_SPACES : Strings.STATUSBAR_INDENT_TOOLTIP_TABS); $indentWidthLabel.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_TABS : Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES); } function _getIndentSize(editor) { -// return Editor.getUseTabChar() ? Editor.getTabSize() : Editor.getSpaceUnits(); - return Editor.getUseTabChar() ? Editor.getTabSize() : editor.getSpaceUnits(); + return editor.getUseTabChar() ? editor.getTabSize() : editor.getSpaceUnits(); } function _updateIndentSize(editor) { @@ -84,8 +83,8 @@ define(function (require, exports, module) { function _toggleIndentType() { var current = EditorManager.getActiveEditor(); - Editor.setUseTabChar(!Editor.getUseTabChar()); - _updateIndentType(); + current.setUseTabChar(!current.getUseTabChar()); + _updateIndentType(current); _updateIndentSize(current); } @@ -133,10 +132,9 @@ define(function (require, exports, module) { } value = Math.max(Math.min(Math.floor(value), 10), 1); - if (Editor.getUseTabChar()) { - Editor.setTabSize(value); + if (editor.getUseTabChar()) { + editor.setTabSize(value); } else { -// Editor.setSpaceUnits(value); editor.setSpaceUnits(value); } @@ -187,7 +185,7 @@ define(function (require, exports, module) { $(current).on("cursorActivity.statusbar", _updateCursorInfo); $(current).on("optionChange.statusbar", function () { - _updateIndentType(); + _updateIndentType(current); _updateIndentSize(current); }); $(current).on("change.statusbar", function () { @@ -203,7 +201,7 @@ define(function (require, exports, module) { _updateLanguageInfo(current); _updateFileInfo(current); _initOverwriteMode(current); - _updateIndentType(); + _updateIndentType(current); _updateIndentSize(current); } } diff --git a/src/extensions/default/JSLint/main.js b/src/extensions/default/JSLint/main.js index 306fbdb71b6..5957c09a4e9 100644 --- a/src/extensions/default/JSLint/main.js +++ b/src/extensions/default/JSLint/main.js @@ -37,6 +37,7 @@ define(function (require, exports, module) { var CodeInspection = brackets.getModule("language/CodeInspection"), PreferencesManager = brackets.getModule("preferences/PreferencesManager"), Strings = brackets.getModule("strings"), + ValidationUtils = brackets.getModule("utils/ValidationUtils"), _ = brackets.getModule("thirdparty/lodash"); var prefs = PreferencesManager.getExtensionPrefs("jslint"); @@ -88,9 +89,8 @@ define(function (require, exports, module) { if (!options.indent) { // default to using the same indentation value that the editor is using -// options.indent = PreferencesManager.get("spaceUnits"); - // Validation is editor-specific (editor.getSpaceUnits), so self validate - options.indent = PreferencesManager.get("spaceUnits", fullPath) || 4; + var indent = PreferencesManager.get("spaceUnits", fullPath); + options.indent = ValidationUtils.isIntegerInRange(indent, 0, null) ? indent : 4; } // If the user has not defined the environment, we use browser by default. diff --git a/src/utils/ValidationUtils.js b/src/utils/ValidationUtils.js index a2e7ea24c8c..72eb14c5a5e 100644 --- a/src/utils/ValidationUtils.js +++ b/src/utils/ValidationUtils.js @@ -34,7 +34,7 @@ define(function (require, exports, module) { * * Used to validate type of unknown value passed it. * - * @param {} value Value for which to validate its type + * @param {*} value Value for which to validate its type * @return true if value is an integer */ function isInteger(value) { @@ -63,7 +63,7 @@ define(function (require, exports, module) { * * Used to validate type of unknown value passed it. * - * @param {} value Value for which to validate its type + * @param {*} value Value for which to validate its type * @param {Number=} lowerLimit Optional lower limit (inclusive) * @param {Number=} upperLimit Optional upper limit (inclusive) * @return true if value is an interger, and optionally in specified range. diff --git a/test/spec/Editor-test.js b/test/spec/Editor-test.js index a05ecdcbd2d..1b9e193babc 100644 --- a/test/spec/Editor-test.js +++ b/test/spec/Editor-test.js @@ -294,7 +294,9 @@ define(function (require, exports, module) { expect(myEditor.getColOffset({line: 5, ch: 4})).toBe(9); // Tab size 2 - Editor.setTabSize(2); + var defaultTabSize = myEditor.getTabSize(); + expect(defaultTabSize).toBe(4); + myEditor.setTabSize(2); expect(myEditor.getColOffset({line: 1, ch: 0})).toBe(0); // first line is all spaces: should be unchanged expect(myEditor.getColOffset({line: 1, ch: 1})).toBe(1); @@ -312,7 +314,7 @@ define(function (require, exports, module) { expect(myEditor.getColOffset({line: 5, ch: 4})).toBe(5); // Restore default - Editor.setTabSize(4); + myEditor.setTabSize(defaultTabSize); }); }); From bc7b0bff7c1865303cef4eb87b9ed5baf137b1d3 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 12 Mar 2014 17:34:30 -0700 Subject: [PATCH 04/24] cleanup --- src/editor/CSSInlineEditor.js | 1 - test/spec/SpecRunnerUtils.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/editor/CSSInlineEditor.js b/src/editor/CSSInlineEditor.js index 6e8b7395501..1c676ef78d6 100644 --- a/src/editor/CSSInlineEditor.js +++ b/src/editor/CSSInlineEditor.js @@ -107,7 +107,6 @@ define(function (require, exports, module) { */ function _addRule(selectorName, inlineEditor, path) { DocumentManager.getDocumentForPath(path).done(function (styleDoc) { -// var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, Editor.getUseTabChar(), Editor.getSpaceUnits()); var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, inlineEditor.getUseTabChar(), inlineEditor.getSpaceUnits()); inlineEditor.addAndSelectRange(selectorName, styleDoc, newRuleInfo.range.from.line, newRuleInfo.range.to.line); inlineEditor.editor.setCursorPos(newRuleInfo.pos.line, newRuleInfo.pos.ch); diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index a38bd7ce1c4..53a060d7b6d 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -404,8 +404,7 @@ define(function (require, exports, module) { // create Editor instance var editor = new Editor(doc, true, $editorHolder.get(0), visibleRange); - Editor.setUseTabChar(EDITOR_USE_TABS); -// Editor.setSpaceUnits(EDITOR_SPACE_UNITS); + editor.setUseTabChar(EDITOR_USE_TABS); editor.setSpaceUnits(EDITOR_SPACE_UNITS); EditorManager._notifyActiveEditorChanged(editor); From d0ef02f9c873191c00e69aa51764945fcaec9547 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 12 Mar 2014 19:44:09 -0700 Subject: [PATCH 05/24] fix range limit of zero --- src/utils/ValidationUtils.js | 4 +++- test/spec/ValidationUtils-test.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/ValidationUtils.js b/src/utils/ValidationUtils.js index 72eb14c5a5e..c50d04f76d7 100644 --- a/src/utils/ValidationUtils.js +++ b/src/utils/ValidationUtils.js @@ -75,7 +75,9 @@ define(function (require, exports, module) { } // Validate integer is in range - return ((!lowerLimit || value >= lowerLimit) && (!upperLimit || value <= upperLimit)); + var hasLowerLimt = (typeof (lowerLimit) === "number"), + hasUpperLimt = (typeof (upperLimit) === "number"); + return ((!hasLowerLimt || value >= lowerLimit) && (!hasUpperLimt || value <= upperLimit)); } diff --git a/test/spec/ValidationUtils-test.js b/test/spec/ValidationUtils-test.js index 3b90146216a..54c5b3a4726 100644 --- a/test/spec/ValidationUtils-test.js +++ b/test/spec/ValidationUtils-test.js @@ -68,8 +68,8 @@ define(function (require, exports, module) { }); it("should accept optional range limit of zero", function () { - expect(ValidationUtils.isIntegerInRange(2, 0, 10)).toBe(true); - expect(ValidationUtils.isIntegerInRange(-62, -100, 0)).toBe(true); + expect(ValidationUtils.isIntegerInRange(-2, 0, 10)).toBe(false); + expect(ValidationUtils.isIntegerInRange(62, -100, 0)).toBe(false); }); it("should not accept integers out of range", function () { From 3719aa27a2730efdcb687852d0c48a5d71e986ec Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 13 Mar 2014 09:12:16 -0700 Subject: [PATCH 06/24] more tests; cleanup comments --- src/utils/ValidationUtils.js | 9 +++------ test/spec/ValidationUtils-test.js | 13 ++++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/utils/ValidationUtils.js b/src/utils/ValidationUtils.js index c50d04f76d7..61a02903c1a 100644 --- a/src/utils/ValidationUtils.js +++ b/src/utils/ValidationUtils.js @@ -30,9 +30,7 @@ define(function (require, exports, module) { /** - * @private (but might be useful in a Validation module) - * - * Used to validate type of unknown value passed it. + * Used to validate whether type of unknown value is an integer. * * @param {*} value Value for which to validate its type * @return true if value is an integer @@ -59,9 +57,8 @@ define(function (require, exports, module) { } /** - * @private (but might be useful in a Validation module) - * - * Used to validate type of unknown value passed it. + * Used to validate whether type of unknown value is an integer, and, if so, + * is it within the option lower and upper limits. * * @param {*} value Value for which to validate its type * @param {Number=} lowerLimit Optional lower limit (inclusive) diff --git a/test/spec/ValidationUtils-test.js b/test/spec/ValidationUtils-test.js index 54c5b3a4726..44630da5ffa 100644 --- a/test/spec/ValidationUtils-test.js +++ b/test/spec/ValidationUtils-test.js @@ -37,13 +37,14 @@ define(function (require, exports, module) { expect(ValidationUtils.isInteger(+2)).toBe(true); expect(ValidationUtils.isInteger(-5)).toBe(true); expect(ValidationUtils.isInteger(3e07)).toBe(true); + expect(ValidationUtils.isInteger(5.28e04)).toBe(true); }); it("should not accept non-numbers as integer", function () { expect(ValidationUtils.isInteger(NaN)).toBe(false); expect(ValidationUtils.isInteger(null)).toBe(false); expect(ValidationUtils.isInteger(undefined)).toBe(false); - expect(ValidationUtils.isInteger("str")).toBe(false); + expect(ValidationUtils.isInteger("4")).toBe(false); expect(ValidationUtils.isInteger(false)).toBe(false); expect(ValidationUtils.isInteger([0, 1, 2])).toBe(false); expect(ValidationUtils.isInteger({ch: 0, line: 0})).toBe(false); @@ -53,11 +54,12 @@ define(function (require, exports, module) { expect(ValidationUtils.isInteger(-Infinity)).toBe(false); expect(ValidationUtils.isInteger(Math.PI)).toBe(false); expect(ValidationUtils.isInteger(0.375)).toBe(false); + expect(ValidationUtils.isInteger(5e-1)).toBe(false); expect(ValidationUtils.isInteger(3.29834e-02)).toBe(false); }); - // ValidationUtils.isIntegerInRange() uses ValidationUtils.isInteger() - // to validate value, so no need to test non-integers + // ValidationUtils.isIntegerInRange() uses ValidationUtils.isInteger() to + // validate value which is tested above, so no need to test non-integers it("should accept integers in range", function () { // Range limits are optional expect(ValidationUtils.isIntegerInRange(1)).toBe(true); @@ -67,8 +69,13 @@ define(function (require, exports, module) { expect(ValidationUtils.isIntegerInRange(13, -Infinity, Infinity)).toBe(true); }); + // Range limits are optional, so they can be specified as null or undefined to + // indicate that end of range should not be enforced, so verify a value of 0 + // (which evaluates to falsey) can be enforced. it("should accept optional range limit of zero", function () { + expect(ValidationUtils.isIntegerInRange(2, 0, 10)).toBe(true); expect(ValidationUtils.isIntegerInRange(-2, 0, 10)).toBe(false); + expect(ValidationUtils.isIntegerInRange(-62, -100, 0)).toBe(true); expect(ValidationUtils.isIntegerInRange(62, -100, 0)).toBe(false); }); From cfb0cce5a8590be9fdfa210e849fecd97adfd3e1 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 13 Mar 2014 12:05:51 -0700 Subject: [PATCH 07/24] implement preference validator --- src/editor/Editor.js | 72 ++++++++---------------------- src/preferences/PreferencesBase.js | 9 +++- 2 files changed, 26 insertions(+), 55 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index f002aa10373..833a89cb633 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -107,8 +107,16 @@ define(function (require, exports, module) { PreferencesManager.definePreference(SMART_INDENT, "boolean", true); PreferencesManager.definePreference(USE_TAB_CHAR, "boolean", false); - PreferencesManager.definePreference(TAB_SIZE, "number", DEFAULT_TAB_SIZE); - PreferencesManager.definePreference(SPACE_UNITS, "number", DEFAULT_SPACE_UNITS); + PreferencesManager.definePreference(TAB_SIZE, "number", DEFAULT_TAB_SIZE, { + validator: function (value) { + return ValidationUtils.isIntegerInRange(value, 1, null); + } + }); + PreferencesManager.definePreference(SPACE_UNITS, "number", DEFAULT_SPACE_UNITS, { + validator: function (value) { + return ValidationUtils.isIntegerInRange(value, 0, null); + } + }); PreferencesManager.definePreference(CLOSE_BRACKETS, "boolean", false); PreferencesManager.definePreference(SHOW_LINE_NUMBERS, "boolean", true); PreferencesManager.definePreference(STYLE_ACTIVE_LINE, "boolean", false); @@ -1820,41 +1828,7 @@ define(function (require, exports, module) { * @return {*} current value of that pref */ Editor.prototype._getOption = function (prefName) { - var value; - - // Call getter methods where appropriate for validation - switch (prefName) { - - case SMART_INDENT: - value = this.getSmartIndent(); - break; - case USE_TAB_CHAR: - value = this.getUseTabChar(); - break; - case TAB_SIZE: - value = this.getTabSize(); - break; - case SPACE_UNITS: - value = this.getSpaceUnits(); - break; - case CLOSE_BRACKETS: - value = this.getCloseBrackets(); - break; - case SHOW_LINE_NUMBERS: - value = this.getShowLineNumbers(); - break; - case STYLE_ACTIVE_LINE: - value = this.getShowActiveLine(); - break; - case WORD_WRAP: - value = this.getWordWrap(); - break; - default: - value = PreferencesManager.get(prefName, this.document.file.fullPath); - break; - } - - return value; + return PreferencesManager.get(prefName, this.document.file.fullPath); }; /** @@ -1923,7 +1897,7 @@ define(function (require, exports, module) { /** @type {boolean} Gets whether the current editor uses smart indenting */ Editor.prototype.getSmartIndent = function () { - return !!PreferencesManager.get(SMART_INDENT, this.document.file.fullPath); + return PreferencesManager.get(SMART_INDENT, this.document.file.fullPath); }; /** @@ -1937,7 +1911,7 @@ define(function (require, exports, module) { /** @type {boolean} Gets whether the current editor uses tab characters (vs. spaces) when inserting new text */ Editor.prototype.getUseTabChar = function () { - return !!PreferencesManager.get(USE_TAB_CHAR, this.document.file.fullPath); + return PreferencesManager.get(USE_TAB_CHAR, this.document.file.fullPath); }; /** @@ -1951,11 +1925,7 @@ define(function (require, exports, module) { /** @type {number} Get tab character width */ Editor.prototype.getTabSize = function () { - var value = PreferencesManager.get(TAB_SIZE, this.document.file.fullPath); - if (!ValidationUtils.isIntegerInRange(value, 1, null)) { - return DEFAULT_TAB_SIZE; - } - return value; + return PreferencesManager.get(TAB_SIZE, this.document.file.fullPath); }; /** @@ -1969,11 +1939,7 @@ define(function (require, exports, module) { /** @type {number} Get indentation width */ Editor.prototype.getSpaceUnits = function () { - var value = PreferencesManager.get(SPACE_UNITS, this.document.file.fullPath); - if (!ValidationUtils.isIntegerInRange(value, 0, null)) { - return DEFAULT_SPACE_UNITS; - } - return value; + return PreferencesManager.get(SPACE_UNITS, this.document.file.fullPath); }; /** @@ -1987,7 +1953,7 @@ define(function (require, exports, module) { /** @type {boolean} Gets whether the current editor uses auto close brackets */ Editor.prototype.getCloseBrackets = function () { - return !!PreferencesManager.get(CLOSE_BRACKETS, this.document.file.fullPath); + return PreferencesManager.get(CLOSE_BRACKETS, this.document.file.fullPath); }; /** @@ -2001,7 +1967,7 @@ define(function (require, exports, module) { /** @type {boolean} Returns true if show line numbers is enabled for the current editor */ Editor.prototype.getShowLineNumbers = function () { - return !!PreferencesManager.get(SHOW_LINE_NUMBERS, this.document.file.fullPath); + return PreferencesManager.get(SHOW_LINE_NUMBERS, this.document.file.fullPath); }; /** @@ -2015,7 +1981,7 @@ define(function (require, exports, module) { /** @type {boolean} Returns true if show active line is enabled for the current editor */ Editor.prototype.getShowActiveLine = function () { - return !!PreferencesManager.get(STYLE_ACTIVE_LINE, this.document.file.fullPath); + return PreferencesManager.get(STYLE_ACTIVE_LINE, this.document.file.fullPath); }; /** @@ -2029,7 +1995,7 @@ define(function (require, exports, module) { /** @type {boolean} Returns true if word wrap is enabled for the current editor */ Editor.prototype.getWordWrap = function () { - return !!PreferencesManager.get(WORD_WRAP, this.document.file.fullPath); + return PreferencesManager.get(WORD_WRAP, this.document.file.fullPath); }; // Set up listeners for preference changes diff --git a/src/preferences/PreferencesBase.js b/src/preferences/PreferencesBase.js index fe1e82b2c45..9cff79320e5 100644 --- a/src/preferences/PreferencesBase.js +++ b/src/preferences/PreferencesBase.js @@ -1102,7 +1102,8 @@ define(function (require, exports, module) { type: type, initial: initial, name: options.name, - description: options.description + description: options.description, + validator: options.validator }); this.set(id, initial, { location: { @@ -1431,7 +1432,11 @@ define(function (require, exports, module) { if (scope) { var result = scope.get(id, context); if (result !== undefined) { - return _.cloneDeep(result); + var pref = this.getPreference(id); + var validator = pref && pref.validator; + if (!validator || validator(result)) { + return _.cloneDeep(result); + } } } } From 3428312ec1a2d2f765d0ad565a3f6e7e3cd625e2 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 13 Mar 2014 12:10:41 -0700 Subject: [PATCH 08/24] update for preference validator --- src/extensions/default/JSLint/main.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/extensions/default/JSLint/main.js b/src/extensions/default/JSLint/main.js index 5957c09a4e9..76b471e7569 100644 --- a/src/extensions/default/JSLint/main.js +++ b/src/extensions/default/JSLint/main.js @@ -89,8 +89,7 @@ define(function (require, exports, module) { if (!options.indent) { // default to using the same indentation value that the editor is using - var indent = PreferencesManager.get("spaceUnits", fullPath); - options.indent = ValidationUtils.isIntegerInRange(indent, 0, null) ? indent : 4; + options.indent = PreferencesManager.get("spaceUnits", fullPath); } // If the user has not defined the environment, we use browser by default. From f476ac5706b3a37dbc3bb143b02d23fd9fbd5d54 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 13 Mar 2014 14:07:49 -0700 Subject: [PATCH 09/24] changes for code review --- src/extensions/default/JSLint/main.js | 1 - src/utils/ValidationUtils.js | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/extensions/default/JSLint/main.js b/src/extensions/default/JSLint/main.js index 76b471e7569..a14ec2ca1de 100644 --- a/src/extensions/default/JSLint/main.js +++ b/src/extensions/default/JSLint/main.js @@ -37,7 +37,6 @@ define(function (require, exports, module) { var CodeInspection = brackets.getModule("language/CodeInspection"), PreferencesManager = brackets.getModule("preferences/PreferencesManager"), Strings = brackets.getModule("strings"), - ValidationUtils = brackets.getModule("utils/ValidationUtils"), _ = brackets.getModule("thirdparty/lodash"); var prefs = PreferencesManager.getExtensionPrefs("jslint"); diff --git a/src/utils/ValidationUtils.js b/src/utils/ValidationUtils.js index 61a02903c1a..1801ec4ee4d 100644 --- a/src/utils/ValidationUtils.js +++ b/src/utils/ValidationUtils.js @@ -33,7 +33,7 @@ define(function (require, exports, module) { * Used to validate whether type of unknown value is an integer. * * @param {*} value Value for which to validate its type - * @return true if value is an integer + * @return {boolean} true if value is an integer */ function isInteger(value) { // Validate value is a number @@ -61,9 +61,9 @@ define(function (require, exports, module) { * is it within the option lower and upper limits. * * @param {*} value Value for which to validate its type - * @param {Number=} lowerLimit Optional lower limit (inclusive) - * @param {Number=} upperLimit Optional upper limit (inclusive) - * @return true if value is an interger, and optionally in specified range. + * @param {number=} lowerLimit Optional lower limit (inclusive) + * @param {number=} upperLimit Optional upper limit (inclusive) + * @return {boolean} true if value is an interger, and optionally in specified range. */ function isIntegerInRange(value, lowerLimit, upperLimit) { // Validate value is an integer From 8268997683f0b1dc5dca20c05a58d9d06ef18f1f Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 13 Mar 2014 15:49:02 -0700 Subject: [PATCH 10/24] more code review changes --- src/editor/Editor.js | 33 +++++++++++++-------------------- src/editor/EditorStatusBar.js | 3 ++- src/utils/ValidationUtils.js | 14 +++++--------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 833a89cb633..20a99bf3cc6 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -89,10 +89,13 @@ define(function (require, exports, module) { CLOSE_TAGS = "closeTags", cmOptions = {}; - /** @type {number} Constants: default preference values */ - var DEFAULT_SPACE_UNITS = 4, - DEFAULT_TAB_SIZE = 4; - + /** @type {number} Constants */ + var MIN_SPACE_UNITS = 0, + MIN_TAB_SIZE = 1, + DEFAULT_SPACE_UNITS = 4, + DEFAULT_TAB_SIZE = 4, + MAX_SPACE_UNITS = 10, + MAX_TAB_SIZE = 10; // Mappings from Brackets preferences to CodeMirror options cmOptions[SMART_INDENT] = "smartIndent"; @@ -109,12 +112,12 @@ define(function (require, exports, module) { PreferencesManager.definePreference(USE_TAB_CHAR, "boolean", false); PreferencesManager.definePreference(TAB_SIZE, "number", DEFAULT_TAB_SIZE, { validator: function (value) { - return ValidationUtils.isIntegerInRange(value, 1, null); + return ValidationUtils.isIntegerInRange(value, MIN_TAB_SIZE, MAX_TAB_SIZE); } }); PreferencesManager.definePreference(SPACE_UNITS, "number", DEFAULT_SPACE_UNITS, { validator: function (value) { - return ValidationUtils.isIntegerInRange(value, 0, null); + return ValidationUtils.isIntegerInRange(value, MIN_SPACE_UNITS, MAX_SPACE_UNITS); } }); PreferencesManager.definePreference(CLOSE_BRACKETS, "boolean", false); @@ -1886,20 +1889,6 @@ define(function (require, exports, module) { // Global settings that affect Editor instances that share the same preference locations - /** - * Sets whether to use smart indenting. - * Affects any editors that share the same preference location. - * @param {boolean} value - */ - Editor.prototype.setSmartIndent = function (value) { - PreferencesManager.set(SMART_INDENT, value); - }; - - /** @type {boolean} Gets whether the current editor uses smart indenting */ - Editor.prototype.getSmartIndent = function () { - return PreferencesManager.get(SMART_INDENT, this.document.file.fullPath); - }; - /** * Sets whether to use tab characters (vs. spaces) when inserting new text. * Affects any editors that share the same preference location. @@ -2026,4 +2015,8 @@ define(function (require, exports, module) { exports.Editor = Editor; exports.BOUNDARY_CHECK_NORMAL = BOUNDARY_CHECK_NORMAL; exports.BOUNDARY_IGNORE_TOP = BOUNDARY_IGNORE_TOP; + exports.MIN_SPACE_UNITS = MIN_SPACE_UNITS; + exports.MAX_SPACE_UNITS = MAX_SPACE_UNITS; + exports.MIN_TAB_SIZE = MIN_TAB_SIZE; + exports.MAX_TAB_SIZE = MAX_TAB_SIZE; }); diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index b9724bad8c5..b55a3543dff 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -131,10 +131,11 @@ define(function (require, exports, module) { return; } - value = Math.max(Math.min(Math.floor(value), 10), 1); if (editor.getUseTabChar()) { + value = Math.max(Math.min(Math.floor(value), Editor.MAX_TAB_SIZE), Editor.MIN_TAB_SIZE); editor.setTabSize(value); } else { + value = Math.max(Math.min(Math.floor(value), Editor.MAX_SPACE_UNITS), Editor.MIN_SPACE_UNITS); editor.setSpaceUnits(value); } diff --git a/src/utils/ValidationUtils.js b/src/utils/ValidationUtils.js index 1801ec4ee4d..87f9c41ccbd 100644 --- a/src/utils/ValidationUtils.js +++ b/src/utils/ValidationUtils.js @@ -42,17 +42,12 @@ define(function (require, exports, module) { } // Validate number is an integer - if (value > 0) { - if (Math.floor(value) !== value) { - return false; - } - } else if (value < 0) { - if (Math.ceil(value) !== value) { - return false; - } + if (value > 0 && Math.floor(value) !== value) { + return false; + } else if (value < 0 && Math.ceil(value) !== value) { + return false; } - // Validate integer is in range return true; } @@ -74,6 +69,7 @@ define(function (require, exports, module) { // Validate integer is in range var hasLowerLimt = (typeof (lowerLimit) === "number"), hasUpperLimt = (typeof (upperLimit) === "number"); + return ((!hasLowerLimt || value >= lowerLimit) && (!hasUpperLimt || value <= upperLimit)); } From fd72a4f5c01e4bee9bd8179ad1856a01d1032ecd Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 14 Mar 2014 08:35:44 -0700 Subject: [PATCH 11/24] fix unit test; use ValidationUtils for validating\! --- src/editor/EditorStatusBar.js | 5 +++-- test/spec/PreferencesBase-test-files/.brackets.json | 4 ++-- test/spec/PreferencesBase-test.js | 6 +++--- test/spec/PreferencesManager-test.js | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index b55a3543dff..aff5b64efae 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -39,7 +39,8 @@ define(function (require, exports, module) { KeyEvent = require("utils/KeyEvent"), StatusBar = require("widgets/StatusBar"), Strings = require("strings"), - StringUtils = require("utils/StringUtils"); + StringUtils = require("utils/StringUtils"), + ValidationUtils = require("utils/ValidationUtils"); /* StatusBar indicators */ var $languageInfo, @@ -127,7 +128,7 @@ define(function (require, exports, module) { // restore focus to the editor EditorManager.focusEditor(); - if (!value || isNaN(value)) { + if (!ValidationUtils.isInteger(value)) { return; } diff --git a/test/spec/PreferencesBase-test-files/.brackets.json b/test/spec/PreferencesBase-test-files/.brackets.json index 63279938bb6..7af2e801747 100644 --- a/test/spec/PreferencesBase-test-files/.brackets.json +++ b/test/spec/PreferencesBase-test-files/.brackets.json @@ -1,8 +1,8 @@ { - "spaceUnits": 92, + "spaceUnits": 9, "path": { "foo.go": { - "spaceUnits": 27 + "spaceUnits": 7 } } } \ No newline at end of file diff --git a/test/spec/PreferencesBase-test.js b/test/spec/PreferencesBase-test.js index 209f9186c6e..453f9edf9d3 100644 --- a/test/spec/PreferencesBase-test.js +++ b/test/spec/PreferencesBase-test.js @@ -1118,12 +1118,12 @@ define(function (require, exports, module) { waitsForDone(pm.addScope("project", projectScope)); runs(function () { projectScope.addLayer(new PreferencesBase.PathLayer("/")); - expect(pm.get("spaceUnits")).toBe(92); + expect(pm.get("spaceUnits")).toBe(9); expect(pm.get("spaceUnits", { scopeOrder: ["project"], filename: "/foo.go" - })).toBe(27); + })).toBe(7); }); }); @@ -1201,7 +1201,7 @@ define(function (require, exports, module) { return changes.length > 0; }); runs(function () { - expect(pm.get("spaceUnits")).toBe(92); + expect(pm.get("spaceUnits")).toBe(9); expect(changes).toEqual([{ ids: ["spaceUnits"] }]); diff --git a/test/spec/PreferencesManager-test.js b/test/spec/PreferencesManager-test.js index 804c53ce6d4..67d0dba345d 100644 --- a/test/spec/PreferencesManager-test.js +++ b/test/spec/PreferencesManager-test.js @@ -134,14 +134,14 @@ define(function (require, exports, module) { waitsForDone(SpecRunnerUtils.openProjectFiles(".brackets.json")); runs(function () { - expect(PreferencesManager.get("spaceUnits")).toBe(92); + expect(PreferencesManager.get("spaceUnits")).toBe(9); waitsForDone(FileViewController.openAndSelectDocument(nonProjectFile, FileViewController.WORKING_SET_VIEW)); }); runs(function () { - expect(PreferencesManager.get("spaceUnits")).not.toBe(92); + expect(PreferencesManager.get("spaceUnits")).not.toBe(9); // Changing projects will force a change in the project scope. SpecRunnerUtils.loadProjectInTestWindow(projectWithoutSettings); @@ -150,7 +150,7 @@ define(function (require, exports, module) { waitsForDone(SpecRunnerUtils.openProjectFiles("file_one.js")); }); runs(function () { - expect(PreferencesManager.get("spaceUnits")).not.toBe(92); + expect(PreferencesManager.get("spaceUnits")).not.toBe(9); }); }); From 0b441d918c13fe88eaa3d42c478d83bd680092ca Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 14 Mar 2014 09:08:23 -0700 Subject: [PATCH 12/24] fix validation --- src/editor/EditorStatusBar.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index aff5b64efae..745863d32d5 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -35,7 +35,7 @@ define(function (require, exports, module) { var AppInit = require("utils/AppInit"), AnimationUtils = require("utils/AnimationUtils"), EditorManager = require("editor/EditorManager"), - Editor = require("editor/Editor").Editor, + Editor = require("editor/Editor"), KeyEvent = require("utils/KeyEvent"), StatusBar = require("widgets/StatusBar"), Strings = require("strings"), @@ -128,16 +128,17 @@ define(function (require, exports, module) { // restore focus to the editor EditorManager.focusEditor(); - if (!ValidationUtils.isInteger(value)) { + var valInt = parseInt(value, 10); + if (!ValidationUtils.isInteger(valInt)) { return; } if (editor.getUseTabChar()) { - value = Math.max(Math.min(Math.floor(value), Editor.MAX_TAB_SIZE), Editor.MIN_TAB_SIZE); - editor.setTabSize(value); + valInt = Math.max(Math.min(Math.floor(valInt), Editor.MAX_TAB_SIZE), Editor.MIN_TAB_SIZE); + editor.setTabSize(valInt); } else { - value = Math.max(Math.min(Math.floor(value), Editor.MAX_SPACE_UNITS), Editor.MIN_SPACE_UNITS); - editor.setSpaceUnits(value); + valInt = Math.max(Math.min(Math.floor(valInt), Editor.MAX_SPACE_UNITS), Editor.MIN_SPACE_UNITS); + editor.setSpaceUnits(valInt); } // update indicator From 5d22e351e641f39435ef55d73c9cf023d8568a8a Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 14 Mar 2014 09:28:51 -0700 Subject: [PATCH 13/24] add unit test for validator --- test/spec/PreferencesBase-test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/spec/PreferencesBase-test.js b/test/spec/PreferencesBase-test.js index 453f9edf9d3..721fb5c4413 100644 --- a/test/spec/PreferencesBase-test.js +++ b/test/spec/PreferencesBase-test.js @@ -1064,6 +1064,18 @@ define(function (require, exports, module) { expect(saveDone).toBe(true); }); + + it("should support validator to ignore invalid values", function () { + var pm = new PreferencesBase.PreferencesSystem(); + pm.definePreference("spaceUnits", "number", 4, { + validator: function (value) { + return (value >= 0 && value <= 10); + } + }); + + pm.set("spaceUnits", 12); // out-of-range + expect(pm.get("spaceUnits")).toBe(4); // expect default + }); }); describe("File Storage", function () { From 0824ff660d016803ea02a3295da0a10841cda1ca Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 14 Mar 2014 13:43:16 -0700 Subject: [PATCH 14/24] implement validator on set --- src/editor/Editor.js | 25 ++++++++++++++----------- src/editor/EditorStatusBar.js | 15 ++++++--------- src/preferences/PreferencesBase.js | 11 +++++++++-- test/spec/PreferencesBase-test.js | 21 +++++++++++++++++++-- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 20a99bf3cc6..96e983e2a56 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1893,9 +1893,10 @@ define(function (require, exports, module) { * Sets whether to use tab characters (vs. spaces) when inserting new text. * Affects any editors that share the same preference location. * @param {boolean} value + * @return {boolean} true if value was set */ Editor.prototype.setUseTabChar = function (value) { - PreferencesManager.set(USE_TAB_CHAR, value); + return PreferencesManager.set(USE_TAB_CHAR, value); }; /** @type {boolean} Gets whether the current editor uses tab characters (vs. spaces) when inserting new text */ @@ -1907,9 +1908,10 @@ define(function (require, exports, module) { * Sets tab character width. * Affects any editors that share the same preference location. * @param {number} value + * @return {boolean} true if value was set */ Editor.prototype.setTabSize = function (value) { - PreferencesManager.set(TAB_SIZE, value); + return PreferencesManager.set(TAB_SIZE, value); }; /** @type {number} Get tab character width */ @@ -1921,9 +1923,10 @@ define(function (require, exports, module) { * Sets indentation width. * Affects any editors that share the same preference location. * @param {number} value + * @return {boolean} true if value was set */ Editor.prototype.setSpaceUnits = function (value) { - PreferencesManager.set(SPACE_UNITS, value); + return PreferencesManager.set(SPACE_UNITS, value); }; /** @type {number} Get indentation width */ @@ -1935,9 +1938,10 @@ define(function (require, exports, module) { * Sets the auto close brackets. * Affects any editors that share the same preference location. * @param {boolean} value + * @return {boolean} true if value was set */ Editor.prototype.setCloseBrackets = function (value) { - PreferencesManager.set(CLOSE_BRACKETS, value); + return PreferencesManager.set(CLOSE_BRACKETS, value); }; /** @type {boolean} Gets whether the current editor uses auto close brackets */ @@ -1949,9 +1953,10 @@ define(function (require, exports, module) { * Sets show line numbers option. * Affects any editors that share the same preference location. * @param {boolean} value + * @return {boolean} true if value was set */ Editor.prototype.setShowLineNumbers = function (value) { - PreferencesManager.set(SHOW_LINE_NUMBERS, value); + return PreferencesManager.set(SHOW_LINE_NUMBERS, value); }; /** @type {boolean} Returns true if show line numbers is enabled for the current editor */ @@ -1963,9 +1968,10 @@ define(function (require, exports, module) { * Sets show active line option. * Affects any editors that share the same preference location. * @param {boolean} value + * @return {boolean} true if value was set */ Editor.prototype.setShowActiveLine = function (value) { - PreferencesManager.set(STYLE_ACTIVE_LINE, value); + return PreferencesManager.set(STYLE_ACTIVE_LINE, value); }; /** @type {boolean} Returns true if show active line is enabled for the current editor */ @@ -1977,9 +1983,10 @@ define(function (require, exports, module) { * Sets word wrap option. * Affects any editors that share the same preference location. * @param {boolean} value + * @return {boolean} true if value was set */ Editor.prototype.setWordWrap = function (value) { - PreferencesManager.set(WORD_WRAP, value); + return PreferencesManager.set(WORD_WRAP, value); }; /** @type {boolean} Returns true if word wrap is enabled for the current editor */ @@ -2015,8 +2022,4 @@ define(function (require, exports, module) { exports.Editor = Editor; exports.BOUNDARY_CHECK_NORMAL = BOUNDARY_CHECK_NORMAL; exports.BOUNDARY_IGNORE_TOP = BOUNDARY_IGNORE_TOP; - exports.MIN_SPACE_UNITS = MIN_SPACE_UNITS; - exports.MAX_SPACE_UNITS = MAX_SPACE_UNITS; - exports.MIN_TAB_SIZE = MIN_TAB_SIZE; - exports.MAX_TAB_SIZE = MAX_TAB_SIZE; }); diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index 745863d32d5..d5d893aacf9 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -35,7 +35,6 @@ define(function (require, exports, module) { var AppInit = require("utils/AppInit"), AnimationUtils = require("utils/AnimationUtils"), EditorManager = require("editor/EditorManager"), - Editor = require("editor/Editor"), KeyEvent = require("utils/KeyEvent"), StatusBar = require("widgets/StatusBar"), Strings = require("strings"), @@ -129,16 +128,14 @@ define(function (require, exports, module) { EditorManager.focusEditor(); var valInt = parseInt(value, 10); - if (!ValidationUtils.isInteger(valInt)) { - return; - } - if (editor.getUseTabChar()) { - valInt = Math.max(Math.min(Math.floor(valInt), Editor.MAX_TAB_SIZE), Editor.MIN_TAB_SIZE); - editor.setTabSize(valInt); + if (!editor.setTabSize(valInt)) { + return; // validation failed + } } else { - valInt = Math.max(Math.min(Math.floor(valInt), Editor.MAX_SPACE_UNITS), Editor.MIN_SPACE_UNITS); - editor.setSpaceUnits(valInt); + if (!editor.setSpaceUnits(valInt)) { + return; // validation failed + } } // update indicator diff --git a/src/preferences/PreferencesBase.js b/src/preferences/PreferencesBase.js index 9cff79320e5..13114377c77 100644 --- a/src/preferences/PreferencesBase.js +++ b/src/preferences/PreferencesBase.js @@ -1432,8 +1432,8 @@ define(function (require, exports, module) { if (scope) { var result = scope.get(id, context); if (result !== undefined) { - var pref = this.getPreference(id); - var validator = pref && pref.validator; + var pref = this.getPreference(id), + validator = pref && pref.validator; if (!validator || validator(result)) { return _.cloneDeep(result); } @@ -1505,11 +1505,18 @@ define(function (require, exports, module) { return false; } } + var scope = this._scopes[location.scope]; if (!scope) { return false; } + var pref = this.getPreference(id), + validator = pref && pref.validator; + if (validator && !validator(value)) { + return false; + } + var wasSet = scope.set(id, value, context, location); if (wasSet) { this._triggerChange({ diff --git a/test/spec/PreferencesBase-test.js b/test/spec/PreferencesBase-test.js index 721fb5c4413..35c61cc8f8f 100644 --- a/test/spec/PreferencesBase-test.js +++ b/test/spec/PreferencesBase-test.js @@ -1073,8 +1073,8 @@ define(function (require, exports, module) { } }); - pm.set("spaceUnits", 12); // out-of-range - expect(pm.get("spaceUnits")).toBe(4); // expect default + expect(pm.set("spaceUnits", 12)).toBe(false); // fail: out-of-range + expect(pm.get("spaceUnits")).toBe(4); // expect default }); }); @@ -1139,6 +1139,23 @@ define(function (require, exports, module) { }); }); + it("can validate preferences loaded from disk", function () { + var filestorage = new PreferencesBase.FileStorage(settingsFile.fullPath); + var pm = new PreferencesBase.PreferencesSystem(); + var projectScope = new PreferencesBase.Scope(filestorage); + waitsForDone(pm.addScope("project", projectScope)); + runs(function () { + projectScope.addLayer(new PreferencesBase.PathLayer("/")); + pm.definePreference("spaceUnits", "number", 3, { + validator: function (value) { + return (value >= 0 && value <= 8); + } + }); + // Value on disk (9) is out-of-range, so expect default (3) + expect(pm.get("spaceUnits")).toBe(3); + }); + }); + it("can save preferences", function () { var filestorage = new PreferencesBase.FileStorage(settingsFile.fullPath); var pm = new PreferencesBase.PreferencesSystem(); From a32a39b15bd00de417e5436b7554d0a2857cfad9 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 14 Mar 2014 13:49:21 -0700 Subject: [PATCH 15/24] code cleanup --- src/editor/EditorStatusBar.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index d5d893aacf9..14e8d64e1ab 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -38,8 +38,7 @@ define(function (require, exports, module) { KeyEvent = require("utils/KeyEvent"), StatusBar = require("widgets/StatusBar"), Strings = require("strings"), - StringUtils = require("utils/StringUtils"), - ValidationUtils = require("utils/ValidationUtils"); + StringUtils = require("utils/StringUtils"); /* StatusBar indicators */ var $languageInfo, From b6fb768b6168902fd6b897c0a61bcda0d384eeff Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 14 Mar 2014 15:18:38 -0700 Subject: [PATCH 16/24] add jsdoc info --- src/editor/EditorStatusBar.js | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index 14e8d64e1ab..548d122f652 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -50,19 +50,38 @@ define(function (require, exports, module) { $statusOverwrite; + /** + * Determine string based on count + * @param {number} number Count + * @param {string} singularStr Singular string + * @param {string} pluralStr Plural string + * @return {string} Proper string to use for count + */ function _formatCountable(number, singularStr, pluralStr) { return StringUtils.format(number > 1 ? pluralStr : singularStr, number); } + /** + * Update file mode + * @param {Editor} editor Current editor + */ function _updateLanguageInfo(editor) { $languageInfo.text(editor.document.getLanguage().getName()); } + /** + * Update file information + * @param {Editor} editor Current editor + */ function _updateFileInfo(editor) { var lines = editor.lineCount(); $fileInfo.text(_formatCountable(lines, Strings.STATUSBAR_LINE_COUNT_SINGULAR, Strings.STATUSBAR_LINE_COUNT_PLURAL)); } + /** + * Update indent type and size + * @param {Editor} editor Current editor + */ function _updateIndentType(editor) { var indentWithTabs = editor.getUseTabChar(); $indentType.text(indentWithTabs ? Strings.STATUSBAR_TAB_SIZE : Strings.STATUSBAR_SPACES); @@ -70,16 +89,28 @@ define(function (require, exports, module) { $indentWidthLabel.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_TABS : Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES); } + /** + * Get indent size based on type + * @param {Editor} editor Current editor + * @return {number} Indent size + */ function _getIndentSize(editor) { return editor.getUseTabChar() ? editor.getTabSize() : editor.getSpaceUnits(); } + /** + * Update indent size + * @param {Editor} editor Current editor + */ function _updateIndentSize(editor) { var size = _getIndentSize(editor); $indentWidthLabel.text(size); $indentWidthInput.val(size); } + /** + * Toggle indent type + */ function _toggleIndentType() { var current = EditorManager.getActiveEditor(); current.setUseTabChar(!current.getUseTabChar()); @@ -87,6 +118,11 @@ define(function (require, exports, module) { _updateIndentSize(current); } + /** + * Update cursor(s)/selection(s) information + * @param {Event} event (unused) + * @param {Editor} editor Current editor + */ function _updateCursorInfo(event, editor) { editor = editor || EditorManager.getActiveEditor(); @@ -116,6 +152,11 @@ define(function (require, exports, module) { $cursorInfo.text(cursorStr + selStr); } + /** + * Change indent size + * @param {Editor} editor Current editor + * @param {string} value Size entered into status bar + */ function _changeIndentWidth(editor, value) { $indentWidthLabel.removeClass("hidden"); $indentWidthInput.addClass("hidden"); @@ -144,6 +185,13 @@ define(function (require, exports, module) { _updateCursorInfo(); } + /** + * Update insert/overwrite label + * @param {Event} event (unused) + * @param {Editor} editor Current editor + * @param {string} newstate New overwrite state + * @param {boolean=} doNotAnimate True if state should not be animated + */ function _updateOverwriteLabel(event, editor, newstate, doNotAnimate) { if ($statusOverwrite.text() === (newstate ? Strings.STATUSBAR_OVERWRITE : Strings.STATUSBAR_INSERT)) { // label already up-to-date @@ -157,6 +205,10 @@ define(function (require, exports, module) { } } + /** + * Update insert/overwrite indicator + * @param {Event} event (unused) + */ function _updateEditorOverwriteMode(event) { var editor = EditorManager.getActiveEditor(), newstate = !editor._codeMirror.state.overwrite; @@ -166,10 +218,20 @@ define(function (require, exports, module) { editor.toggleOverwrite(newstate); } + /** + * Initialize insert/overwrite indicator + * @param {Editor} currentEditor Current editor + */ function _initOverwriteMode(currentEditor) { currentEditor.toggleOverwrite($statusOverwrite.text() === Strings.STATUSBAR_OVERWRITE); } + /** + * Handle active editor change event + * @param {Event} event (unused) + * @param {Editor} current Current editor + * @param {Editor} previous Previous editor + */ function _onActiveEditorChange(event, current, previous) { if (previous) { $(previous).off(".statusbar"); @@ -205,6 +267,9 @@ define(function (require, exports, module) { } } + /** + * Initialize + */ function _init() { $languageInfo = $("#status-language"); $cursorInfo = $("#status-cursor"); From 35b18b83a49e5a784e56833546e5e31c6519336a Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Mon, 17 Mar 2014 18:02:35 -0700 Subject: [PATCH 17/24] add test for negative space units --- test/spec/PreferencesBase-test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/spec/PreferencesBase-test.js b/test/spec/PreferencesBase-test.js index 35c61cc8f8f..7cda52e9976 100644 --- a/test/spec/PreferencesBase-test.js +++ b/test/spec/PreferencesBase-test.js @@ -1073,7 +1073,10 @@ define(function (require, exports, module) { } }); - expect(pm.set("spaceUnits", 12)).toBe(false); // fail: out-of-range + expect(pm.set("spaceUnits", 12)).toBe(false); // fail: out-of-range upper + expect(pm.get("spaceUnits")).toBe(4); // expect default + + expect(pm.set("spaceUnits", -1)).toBe(false); // fail: out-of-range lower expect(pm.get("spaceUnits")).toBe(4); // expect default }); }); From 24183446eb1aa2fd06dcbf7a2ff6229c754f69dd Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Tue, 18 Mar 2014 10:04:02 -0700 Subject: [PATCH 18/24] restore original API as deprecated --- src/editor/Editor.js | 142 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 69dbcebcdfa..ebddeaa6610 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -67,6 +67,7 @@ define(function (require, exports, module) { var AnimationUtils = require("utils/AnimationUtils"), Async = require("utils/Async"), CodeMirror = require("thirdparty/CodeMirror2/lib/codemirror"), + DeprecationWarning = require("utils/DeprecationWarning"), Menus = require("command/Menus"), PerfUtils = require("utils/PerfUtils"), PreferencesManager = require("preferences/PreferencesManager"), @@ -1894,6 +1895,147 @@ define(function (require, exports, module) { // Global settings that affect Editor instances that share the same preference locations + /** + * @deprecated Use Editor instance method instead + * Sets whether to use tab characters (vs. spaces) when inserting new text. + * Affects any editors that share the same preference location. + * @param {boolean} value + */ + Editor.setUseTabChar = function (value) { + DeprecationWarning.deprecationWarning("Editor.setUseTabChar was called, use Editor.prototype.setUseTabChar (on Editor instance) instead."); + PreferencesManager.set(USE_TAB_CHAR, value); + }; + + /** + * @deprecated Use Editor instance method instead + * @type {boolean} Gets whether the current editor uses tab characters (vs. spaces) when inserting new text + */ + Editor.getUseTabChar = function () { + DeprecationWarning.deprecationWarning("Editor.getUseTabChar was called, use Editor.prototype.getUseTabChar (on Editor instance) instead."); + return PreferencesManager.get(USE_TAB_CHAR); + }; + + /** + * @deprecated Use Editor instance method instead + * Sets tab character width. + * Affects any editors that share the same preference location. + * @param {number} value + */ + Editor.setTabSize = function (value) { + DeprecationWarning.deprecationWarning("Editor.setTabSize was called, use Editor.prototype.setTabSize (on Editor instance) instead."); + PreferencesManager.set(TAB_SIZE, value); + }; + + /** + * @deprecated Use Editor instance method instead + * @type {number} Get indent unit + */ + Editor.getTabSize = function () { + DeprecationWarning.deprecationWarning("Editor.getTabSize was called, use Editor.prototype.getTabSize (on Editor instance) instead."); + return PreferencesManager.get(TAB_SIZE); + }; + + /** + * @deprecated Use Editor instance method instead + * Sets indentation width. + * Affects any editors that share the same preference location. + * @param {number} value + */ + Editor.setSpaceUnits = function (value) { + DeprecationWarning.deprecationWarning("Editor.setSpaceUnits was called, use Editor.prototype.setSpaceUnits (on Editor instance) instead."); + PreferencesManager.set(SPACE_UNITS, value); + }; + + /** + * @deprecated Use Editor instance method instead + * @type {number} Get indentation width + */ + Editor.getSpaceUnits = function () { + DeprecationWarning.deprecationWarning("Editor.getSpaceUnits was called, use Editor.prototype.getSpaceUnits (on Editor instance) instead."); + return PreferencesManager.get(SPACE_UNITS); + }; + + /** + * @deprecated Use Editor instance method instead + * Sets the auto close brackets. + * Affects any editors that share the same preference location. + * @param {boolean} value + */ + Editor.setCloseBrackets = function (value) { + DeprecationWarning.deprecationWarning("Editor.setCloseBrackets was called, use Editor.prototype.setCloseBrackets (on Editor instance) instead."); + PreferencesManager.set(CLOSE_BRACKETS, value); + }; + + /** + * @deprecated Use Editor instance method instead + * @type {boolean} Gets whether the current editor uses auto close brackets + */ + Editor.getCloseBrackets = function () { + DeprecationWarning.deprecationWarning("Editor.getCloseBrackets was called, use Editor.prototype.getCloseBrackets (on Editor instance) instead."); + return PreferencesManager.get(CLOSE_BRACKETS); + }; + + /** + * @deprecated Use Editor instance method instead + * Sets show line numbers option. + * Affects any editors that share the same preference location. + * @param {boolean} value + */ + Editor.setShowLineNumbers = function (value) { + DeprecationWarning.deprecationWarning("Editor.setShowLineNumbers was called, use Editor.prototype.setShowLineNumbers (on Editor instance) instead."); + PreferencesManager.set(SHOW_LINE_NUMBERS, value); + }; + + /** + * @deprecated Use Editor instance method instead + * @type {boolean} Returns true if show line numbers is enabled for the current editor + */ + Editor.getShowLineNumbers = function () { + DeprecationWarning.deprecationWarning("Editor.getShowLineNumbers was called, use Editor.prototype.getShowLineNumbers (on Editor instance) instead."); + return PreferencesManager.get(SHOW_LINE_NUMBERS); + }; + + /** + * @deprecated Use Editor instance method instead + * Sets show active line option. + * Affects any editors that share the same preference location. + * @param {boolean} value + */ + Editor.setShowActiveLine = function (value) { + DeprecationWarning.deprecationWarning("Editor.setShowActiveLine was called, use Editor.prototype.setShowActiveLine (on Editor instance) instead."); + PreferencesManager.set(STYLE_ACTIVE_LINE, value); + }; + + /** + * @deprecated Use Editor instance method instead + * @type {boolean} Returns true if show active line is enabled for the current editor + */ + Editor.getShowActiveLine = function () { + DeprecationWarning.deprecationWarning("Editor.getShowActiveLine was called, use Editor.prototype.getShowActiveLine (on Editor instance) instead."); + return PreferencesManager.get(STYLE_ACTIVE_LINE); + }; + + /** + * @deprecated Use Editor instance method instead + * Sets word wrap option. + * Affects any editors that share the same preference location. + * @param {boolean} value + */ + Editor.setWordWrap = function (value) { + DeprecationWarning.deprecationWarning("Editor.setWordWrap was called, use Editor.prototype.setWordWrap (on Editor instance) instead."); + PreferencesManager.set(WORD_WRAP, value); + }; + + /** + * @deprecated Use Editor instance method instead + * @type {boolean} Returns true if word wrap is enabled for the current editor + */ + Editor.getWordWrap = function () { + DeprecationWarning.deprecationWarning("Editor.getWordWrap was called, use Editor.prototype.getWordWrap (on Editor instance) instead."); + return PreferencesManager.get(WORD_WRAP); + }; + + /** * Sets whether to use tab characters (vs. spaces) when inserting new text. * Affects any editors that share the same preference location. From bc71a608f736a2cb8e529888842793752954f951 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 20 Mar 2014 13:30:37 -0700 Subject: [PATCH 19/24] return both and from set() --- src/editor/Editor.js | 14 +++++++------- src/preferences/PreferencesBase.js | 11 ++++++----- src/preferences/PreferencesManager.js | 5 +++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index ebddeaa6610..d1231091dd3 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -2043,7 +2043,7 @@ define(function (require, exports, module) { * @return {boolean} true if value was set */ Editor.prototype.setUseTabChar = function (value) { - return PreferencesManager.set(USE_TAB_CHAR, value); + return PreferencesManager.set(USE_TAB_CHAR, value).valid; }; /** @type {boolean} Gets whether the current editor uses tab characters (vs. spaces) when inserting new text */ @@ -2058,7 +2058,7 @@ define(function (require, exports, module) { * @return {boolean} true if value was set */ Editor.prototype.setTabSize = function (value) { - return PreferencesManager.set(TAB_SIZE, value); + return PreferencesManager.set(TAB_SIZE, value).valid; }; /** @type {number} Get tab character width */ @@ -2073,7 +2073,7 @@ define(function (require, exports, module) { * @return {boolean} true if value was set */ Editor.prototype.setSpaceUnits = function (value) { - return PreferencesManager.set(SPACE_UNITS, value); + return PreferencesManager.set(SPACE_UNITS, value).valid; }; /** @type {number} Get indentation width */ @@ -2088,7 +2088,7 @@ define(function (require, exports, module) { * @return {boolean} true if value was set */ Editor.prototype.setCloseBrackets = function (value) { - return PreferencesManager.set(CLOSE_BRACKETS, value); + return PreferencesManager.set(CLOSE_BRACKETS, value).valid; }; /** @type {boolean} Gets whether the current editor uses auto close brackets */ @@ -2103,7 +2103,7 @@ define(function (require, exports, module) { * @return {boolean} true if value was set */ Editor.prototype.setShowLineNumbers = function (value) { - return PreferencesManager.set(SHOW_LINE_NUMBERS, value); + return PreferencesManager.set(SHOW_LINE_NUMBERS, value).valid; }; /** @type {boolean} Returns true if show line numbers is enabled for the current editor */ @@ -2118,7 +2118,7 @@ define(function (require, exports, module) { * @return {boolean} true if value was set */ Editor.prototype.setShowActiveLine = function (value) { - return PreferencesManager.set(STYLE_ACTIVE_LINE, value); + return PreferencesManager.set(STYLE_ACTIVE_LINE, value).valid; }; /** @type {boolean} Returns true if show active line is enabled for the current editor */ @@ -2133,7 +2133,7 @@ define(function (require, exports, module) { * @return {boolean} true if value was set */ Editor.prototype.setWordWrap = function (value) { - return PreferencesManager.set(WORD_WRAP, value); + return PreferencesManager.set(WORD_WRAP, value).valid; }; /** @type {boolean} Returns true if word wrap is enabled for the current editor */ diff --git a/src/preferences/PreferencesBase.js b/src/preferences/PreferencesBase.js index 13114377c77..47d65f7fbbb 100644 --- a/src/preferences/PreferencesBase.js +++ b/src/preferences/PreferencesBase.js @@ -1480,7 +1480,8 @@ define(function (require, exports, module) { * @param {string} id Identifier of the preference to set * @param {Object} value New value for the preference * @param {{location: ?Object, context: ?Object}=} options Specific location in which to set the value or the context to use when setting the value - * @return {boolean} true if a value was set + * @return {valid: {boolean}, true if no validator specified or if value is valid + * stored: {boolean}} true if a value was stored */ set: function (id, value, options) { options = options || {}; @@ -1502,19 +1503,19 @@ define(function (require, exports, module) { scope: scopeOrder[scopeOrder.length - 2] }; } else { - return false; + return { valid: true, stored: false }; } } var scope = this._scopes[location.scope]; if (!scope) { - return false; + return { valid: true, stored: false }; } var pref = this.getPreference(id), validator = pref && pref.validator; if (validator && !validator(value)) { - return false; + return { valid: false, stored: false }; } var wasSet = scope.set(id, value, context, location); @@ -1523,7 +1524,7 @@ define(function (require, exports, module) { ids: [id] }); } - return wasSet; + return { valid: true, stored: wasSet }; }, /** diff --git a/src/preferences/PreferencesManager.js b/src/preferences/PreferencesManager.js index 3f215e3b209..fda6eab3eca 100644 --- a/src/preferences/PreferencesManager.js +++ b/src/preferences/PreferencesManager.js @@ -560,7 +560,8 @@ define(function (require, exports, module) { * @param {Object} value New value for the preference * @param {{location: ?Object, context: ?Object|string}=} options Specific location in which to set the value or the context to use when setting the value * @param {boolean=} doNotSave True if the preference change should not be saved automatically. - * @return {boolean} true if a value was set + * @return {valid: {boolean}, true if no validator specified or if value is valid + * stored: {boolean}} true if a value was stored */ function set(id, value, options, doNotSave) { if (options && options.context) { @@ -607,7 +608,7 @@ define(function (require, exports, module) { */ function setValueAndSave(id, value, options) { DeprecationWarning.deprecationWarning("setValueAndSave called for " + id + ". Use set instead."); - var changed = set(id, value, options); + var changed = set(id, value, options).stored; preferencesManager.save(); return changed; } From d2d4c72808707334ca9d3fad7c4c1f116484aa5f Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 20 Mar 2014 15:35:15 -0700 Subject: [PATCH 20/24] fix tests --- test/spec/PreferencesBase-test.js | 37 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/test/spec/PreferencesBase-test.js b/test/spec/PreferencesBase-test.js index 7cda52e9976..373aceac119 100644 --- a/test/spec/PreferencesBase-test.js +++ b/test/spec/PreferencesBase-test.js @@ -278,7 +278,7 @@ define(function (require, exports, module) { // MemoryStorage operates synchronously scope.load(); - expect(pm.set("foo", foo)).toBe(true); + expect(pm.set("foo", foo).stored).toBe(true); expect(pm.get("foo").value).toBe(42); expect(scope._dirty).toBe(true); @@ -289,7 +289,7 @@ define(function (require, exports, module) { foo.value = "!!!"; expect(foo.value).toBe("!!!"); - expect(pm.set("foo", foo)).toBe(true); + expect(pm.set("foo", foo).stored).toBe(true); expect(scope._dirty).toBe(true); var fooCopyFromPref = pm.get("foo"); @@ -565,7 +565,7 @@ define(function (require, exports, module) { location: { scope: "nonscope" } - })).toBe(false); + }).stored).toBe(false); }); it("supports nested scopes", function () { @@ -894,20 +894,20 @@ define(function (require, exports, module) { location: { scope: "doesNotExist" } - })).toBe(false); + }).stored).toBe(false); expect(pm.get("spaceUnits")).toBe(4); expect(changes).toBe(0); expect(pm.getPreferenceLocation("spaceUnits")).toEqual({ scope: "default" }); - expect(pm.set("spaceUnits", 6)).toBe(true); + expect(pm.set("spaceUnits", 6).stored).toBe(true); expect(user.data).toEqual({ spaceUnits: 6 }); expect(changes).toBe(1); - expect(pm.set("spaceUnits", 7)).toBe(true); + expect(pm.set("spaceUnits", 7).stored).toBe(true); expect(user.data).toEqual({ spaceUnits: 7 }); @@ -917,7 +917,7 @@ define(function (require, exports, module) { location: { scope: "session" } - })).toBe(true); + }).stored).toBe(true); expect(user.data).toEqual({ spaceUnits: 7 }); @@ -926,7 +926,7 @@ define(function (require, exports, module) { }); expect(changes).toBe(3); - expect(pm.set("spaceUnits", 9)).toBe(true); + expect(pm.set("spaceUnits", 9).stored).toBe(true); expect(changes).toBe(4); expect(session.data).toEqual({ spaceUnits: 9 @@ -936,7 +936,7 @@ define(function (require, exports, module) { location: { scope: "session" } - })).toBe(true); + }).stored).toBe(true); expect(changes).toBe(5); expect(session.data.spaceUnits).toBeUndefined(); expect(pm.get("spaceUnits")).toBe(7); @@ -945,7 +945,7 @@ define(function (require, exports, module) { pm.setDefaultFilename("/index.html"); expect(changes).toBe(6); expect(pm.get("spaceUnits")).toBe(2); - expect(pm.set("spaceUnits", 10)).toBe(true); + expect(pm.set("spaceUnits", 10).stored).toBe(true); expect(changes).toBe(7); expect(project.data.path["**.html"].spaceUnits).toBe(10); @@ -957,11 +957,11 @@ define(function (require, exports, module) { location: { scope: "project" } - })).toBe(true); + }).stored).toBe(true); expect(pm.getPreferenceLocation("spaceUnits")).toEqual({ scope: "project" }); - expect(pm.set("spaceUnits", 12)).toBe(true); + expect(pm.set("spaceUnits", 12).stored).toBe(true); expect(project.data.spaceUnits).toBe(12); expect(pm.set("spaceUnits", 13, { @@ -970,7 +970,7 @@ define(function (require, exports, module) { layer: "path", layerID: "**.js" } - })).toBe(true); + }).stored).toBe(true); expect(pm.getPreferenceLocation("spaceUnits")).toEqual({ scope: "project" }); @@ -1067,17 +1067,18 @@ define(function (require, exports, module) { it("should support validator to ignore invalid values", function () { var pm = new PreferencesBase.PreferencesSystem(); + pm.addScope("user", new PreferencesBase.MemoryStorage()); pm.definePreference("spaceUnits", "number", 4, { validator: function (value) { return (value >= 0 && value <= 10); } }); + + expect(pm.set("spaceUnits", 12).valid).toBe(false); // fail: out-of-range upper + expect(pm.get("spaceUnits")).toBe(4); // expect default - expect(pm.set("spaceUnits", 12)).toBe(false); // fail: out-of-range upper - expect(pm.get("spaceUnits")).toBe(4); // expect default - - expect(pm.set("spaceUnits", -1)).toBe(false); // fail: out-of-range lower - expect(pm.get("spaceUnits")).toBe(4); // expect default + expect(pm.set("spaceUnits", -1).valid).toBe(false); // fail: out-of-range lower + expect(pm.get("spaceUnits")).toBe(4); // expect default }); }); From 835bc459d29bdd820ea7448521e246e46c2c7ee9 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Sun, 23 Mar 2014 09:58:54 -0700 Subject: [PATCH 21/24] use lodash to generate validator function --- src/editor/Editor.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index d69ea8c9863..a244ec0918d 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -121,15 +121,11 @@ define(function (require, exports, module) { PreferencesManager.definePreference(SMART_INDENT, "boolean", true); PreferencesManager.definePreference(SOFT_TABS, "boolean", true); PreferencesManager.definePreference(SPACE_UNITS, "number", DEFAULT_SPACE_UNITS, { - validator: function (value) { - return ValidationUtils.isIntegerInRange(value, MIN_SPACE_UNITS, MAX_SPACE_UNITS); - } + validator: _.partialRight(ValidationUtils.isIntegerInRange, MIN_SPACE_UNITS, MAX_SPACE_UNITS) }); PreferencesManager.definePreference(STYLE_ACTIVE_LINE, "boolean", false); PreferencesManager.definePreference(TAB_SIZE, "number", DEFAULT_TAB_SIZE, { - validator: function (value) { - return ValidationUtils.isIntegerInRange(value, MIN_TAB_SIZE, MAX_TAB_SIZE); - } + validator: _.partialRight(ValidationUtils.isIntegerInRange, MIN_TAB_SIZE, MAX_TAB_SIZE) }); PreferencesManager.definePreference(USE_TAB_CHAR, "boolean", false); PreferencesManager.definePreference(WORD_WRAP, "boolean", true); From 2062a78e4d917a5927b491101d1ecd9cd0160048 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 27 Mar 2014 13:24:19 -0700 Subject: [PATCH 22/24] revert to old API with a few small changes --- src/editor/CSSInlineEditor.js | 2 +- src/editor/Editor.js | 220 +++++++------------------- src/editor/EditorStatusBar.js | 50 +++--- src/extensions/default/JSLint/main.js | 6 +- test/spec/Editor-test.js | 6 +- test/spec/SpecRunnerUtils.js | 4 +- 6 files changed, 88 insertions(+), 200 deletions(-) diff --git a/src/editor/CSSInlineEditor.js b/src/editor/CSSInlineEditor.js index 035fd1ce72e..a485b26a0e2 100644 --- a/src/editor/CSSInlineEditor.js +++ b/src/editor/CSSInlineEditor.js @@ -121,7 +121,7 @@ define(function (require, exports, module) { */ function _addRule(selectorName, inlineEditor, path) { DocumentManager.getDocumentForPath(path).done(function (styleDoc) { - var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, inlineEditor.getUseTabChar(), inlineEditor.getSpaceUnits()); + var newRuleInfo = CSSUtils.addRuleToDocument(styleDoc, selectorName, Editor.getUseTabChar(path), Editor.getSpaceUnits(path)); inlineEditor.addAndSelectRange(selectorName, styleDoc, newRuleInfo.range.from.line, newRuleInfo.range.to.line); inlineEditor.editor.setCursorPos(newRuleInfo.pos.line, newRuleInfo.pos.ch); }); diff --git a/src/editor/Editor.js b/src/editor/Editor.js index a244ec0918d..5d5a8533e22 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -67,7 +67,6 @@ define(function (require, exports, module) { var AnimationUtils = require("utils/AnimationUtils"), Async = require("utils/Async"), CodeMirror = require("thirdparty/CodeMirror2/lib/codemirror"), - DeprecationWarning = require("utils/DeprecationWarning"), Menus = require("command/Menus"), PerfUtils = require("utils/PerfUtils"), PopUpManager = require("widgets/PopUpManager"), @@ -2026,251 +2025,138 @@ define(function (require, exports, module) { // Global settings that affect Editor instances that share the same preference locations /** - * @deprecated Use Editor instance method instead * Sets whether to use tab characters (vs. spaces) when inserting new text. * Affects any editors that share the same preference location. * @param {boolean} value + * @param {string=} fullPath + * @return {boolean} true if value was valid */ - Editor.setUseTabChar = function (value) { - DeprecationWarning.deprecationWarning("Editor.setUseTabChar was called, use Editor.prototype.setUseTabChar (on Editor instance) instead."); - PreferencesManager.set(USE_TAB_CHAR, value); + Editor.setUseTabChar = function (value, fullPath) { + var options = fullPath && {context: fullPath}; + return PreferencesManager.set(USE_TAB_CHAR, value, options); }; /** - * @deprecated Use Editor instance method instead - * @type {boolean} Gets whether the current editor uses tab characters (vs. spaces) when inserting new text + * @type {boolean} Gets whether the specified or current file uses tab characters (vs. spaces) when inserting new text */ - Editor.getUseTabChar = function () { - DeprecationWarning.deprecationWarning("Editor.getUseTabChar was called, use Editor.prototype.getUseTabChar (on Editor instance) instead."); - return PreferencesManager.get(USE_TAB_CHAR); + Editor.getUseTabChar = function (fullPath) { + return PreferencesManager.get(USE_TAB_CHAR, fullPath); }; /** - * @deprecated Use Editor instance method instead * Sets tab character width. * Affects any editors that share the same preference location. * @param {number} value + * @param {string=} fullPath + * @return {boolean} true if value was valid */ - Editor.setTabSize = function (value) { - DeprecationWarning.deprecationWarning("Editor.setTabSize was called, use Editor.prototype.setTabSize (on Editor instance) instead."); - PreferencesManager.set(TAB_SIZE, value); + Editor.setTabSize = function (value, fullPath) { + var options = fullPath && {context: fullPath}; + return PreferencesManager.set(TAB_SIZE, value, options); }; /** - * @deprecated Use Editor instance method instead * @type {number} Get indent unit */ - Editor.getTabSize = function () { - DeprecationWarning.deprecationWarning("Editor.getTabSize was called, use Editor.prototype.getTabSize (on Editor instance) instead."); - return PreferencesManager.get(TAB_SIZE); + Editor.getTabSize = function (fullPath) { + return PreferencesManager.get(TAB_SIZE, fullPath); }; /** - * @deprecated Use Editor instance method instead * Sets indentation width. * Affects any editors that share the same preference location. * @param {number} value + * @param {string=} fullPath + * @return {boolean} true if value was valid */ - Editor.setSpaceUnits = function (value) { - DeprecationWarning.deprecationWarning("Editor.setSpaceUnits was called, use Editor.prototype.setSpaceUnits (on Editor instance) instead."); - PreferencesManager.set(SPACE_UNITS, value); + Editor.setSpaceUnits = function (value, fullPath) { + var options = fullPath && {context: fullPath}; + return PreferencesManager.set(SPACE_UNITS, value, options); }; /** - * @deprecated Use Editor instance method instead * @type {number} Get indentation width */ - Editor.getSpaceUnits = function () { - DeprecationWarning.deprecationWarning("Editor.getSpaceUnits was called, use Editor.prototype.getSpaceUnits (on Editor instance) instead."); - return PreferencesManager.get(SPACE_UNITS); + Editor.getSpaceUnits = function (fullPath) { + return PreferencesManager.get(SPACE_UNITS, fullPath); }; /** - * @deprecated Use Editor instance method instead * Sets the auto close brackets. * Affects any editors that share the same preference location. * @param {boolean} value + * @param {string=} fullPath + * @return {boolean} true if value was valid */ - Editor.setCloseBrackets = function (value) { - DeprecationWarning.deprecationWarning("Editor.setCloseBrackets was called, use Editor.prototype.setCloseBrackets (on Editor instance) instead."); - PreferencesManager.set(CLOSE_BRACKETS, value); + Editor.setCloseBrackets = function (value, fullPath) { + var options = fullPath && {context: fullPath}; + return PreferencesManager.set(CLOSE_BRACKETS, value, options); }; /** - * @deprecated Use Editor instance method instead - * @type {boolean} Gets whether the current editor uses auto close brackets + * @type {boolean} Gets whether the specified or current file uses auto close brackets */ - Editor.getCloseBrackets = function () { - DeprecationWarning.deprecationWarning("Editor.getCloseBrackets was called, use Editor.prototype.getCloseBrackets (on Editor instance) instead."); - return PreferencesManager.get(CLOSE_BRACKETS); + Editor.getCloseBrackets = function (fullPath) { + return PreferencesManager.get(CLOSE_BRACKETS, fullPath); }; /** - * @deprecated Use Editor instance method instead * Sets show line numbers option. * Affects any editors that share the same preference location. * @param {boolean} value + * @param {string=} fullPath + * @return {boolean} true if value was valid */ - Editor.setShowLineNumbers = function (value) { - DeprecationWarning.deprecationWarning("Editor.setShowLineNumbers was called, use Editor.prototype.setShowLineNumbers (on Editor instance) instead."); - PreferencesManager.set(SHOW_LINE_NUMBERS, value); + Editor.setShowLineNumbers = function (value, fullPath) { + var options = fullPath && {context: fullPath}; + return PreferencesManager.set(SHOW_LINE_NUMBERS, value, options); }; /** - * @deprecated Use Editor instance method instead - * @type {boolean} Returns true if show line numbers is enabled for the current editor + * @type {boolean} Returns true if show line numbers is enabled for the specified or current file */ - Editor.getShowLineNumbers = function () { - DeprecationWarning.deprecationWarning("Editor.getShowLineNumbers was called, use Editor.prototype.getShowLineNumbers (on Editor instance) instead."); - return PreferencesManager.get(SHOW_LINE_NUMBERS); + Editor.getShowLineNumbers = function (fullPath) { + return PreferencesManager.get(SHOW_LINE_NUMBERS, fullPath); }; /** - * @deprecated Use Editor instance method instead * Sets show active line option. * Affects any editors that share the same preference location. * @param {boolean} value + * @param {string=} fullPath + * @return {boolean} true if value was valid */ - Editor.setShowActiveLine = function (value) { - DeprecationWarning.deprecationWarning("Editor.setShowActiveLine was called, use Editor.prototype.setShowActiveLine (on Editor instance) instead."); - PreferencesManager.set(STYLE_ACTIVE_LINE, value); + Editor.setShowActiveLine = function (value, fullPath) { + return PreferencesManager.set(STYLE_ACTIVE_LINE, value); }; /** - * @deprecated Use Editor instance method instead - * @type {boolean} Returns true if show active line is enabled for the current editor + * @type {boolean} Returns true if show active line is enabled for the specified or current file */ - Editor.getShowActiveLine = function () { - DeprecationWarning.deprecationWarning("Editor.getShowActiveLine was called, use Editor.prototype.getShowActiveLine (on Editor instance) instead."); - return PreferencesManager.get(STYLE_ACTIVE_LINE); + Editor.getShowActiveLine = function (fullPath) { + return PreferencesManager.get(STYLE_ACTIVE_LINE, fullPath); }; /** - * @deprecated Use Editor instance method instead * Sets word wrap option. * Affects any editors that share the same preference location. * @param {boolean} value + * @param {string=} fullPath + * @return {boolean} true if value was valid */ - Editor.setWordWrap = function (value) { - DeprecationWarning.deprecationWarning("Editor.setWordWrap was called, use Editor.prototype.setWordWrap (on Editor instance) instead."); - PreferencesManager.set(WORD_WRAP, value); + Editor.setWordWrap = function (value, fullPath) { + var options = fullPath && {context: fullPath}; + return PreferencesManager.set(WORD_WRAP, value, options); }; /** - * @deprecated Use Editor instance method instead - * @type {boolean} Returns true if word wrap is enabled for the current editor + * @type {boolean} Returns true if word wrap is enabled for the specified or current file */ - Editor.getWordWrap = function () { - DeprecationWarning.deprecationWarning("Editor.getWordWrap was called, use Editor.prototype.getWordWrap (on Editor instance) instead."); - return PreferencesManager.get(WORD_WRAP); + Editor.getWordWrap = function (fullPath) { + return PreferencesManager.get(WORD_WRAP, fullPath); }; - /** - * Sets whether to use tab characters (vs. spaces) when inserting new text. - * Affects any editors that share the same preference location. - * @param {boolean} value - * @return {boolean} true if value was set - */ - Editor.prototype.setUseTabChar = function (value) { - return PreferencesManager.set(USE_TAB_CHAR, value).valid; - }; - - /** @type {boolean} Gets whether the current editor uses tab characters (vs. spaces) when inserting new text */ - Editor.prototype.getUseTabChar = function () { - return PreferencesManager.get(USE_TAB_CHAR, this.document.file.fullPath); - }; - - /** - * Sets tab character width. - * Affects any editors that share the same preference location. - * @param {number} value - * @return {boolean} true if value was set - */ - Editor.prototype.setTabSize = function (value) { - return PreferencesManager.set(TAB_SIZE, value).valid; - }; - - /** @type {number} Get tab character width */ - Editor.prototype.getTabSize = function () { - return PreferencesManager.get(TAB_SIZE, this.document.file.fullPath); - }; - - /** - * Sets indentation width. - * Affects any editors that share the same preference location. - * @param {number} value - * @return {boolean} true if value was set - */ - Editor.prototype.setSpaceUnits = function (value) { - return PreferencesManager.set(SPACE_UNITS, value).valid; - }; - - /** @type {number} Get indentation width */ - Editor.prototype.getSpaceUnits = function () { - return PreferencesManager.get(SPACE_UNITS, this.document.file.fullPath); - }; - - /** - * Sets the auto close brackets. - * Affects any editors that share the same preference location. - * @param {boolean} value - * @return {boolean} true if value was set - */ - Editor.prototype.setCloseBrackets = function (value) { - return PreferencesManager.set(CLOSE_BRACKETS, value).valid; - }; - - /** @type {boolean} Gets whether the current editor uses auto close brackets */ - Editor.prototype.getCloseBrackets = function () { - return PreferencesManager.get(CLOSE_BRACKETS, this.document.file.fullPath); - }; - - /** - * Sets show line numbers option. - * Affects any editors that share the same preference location. - * @param {boolean} value - * @return {boolean} true if value was set - */ - Editor.prototype.setShowLineNumbers = function (value) { - return PreferencesManager.set(SHOW_LINE_NUMBERS, value).valid; - }; - - /** @type {boolean} Returns true if show line numbers is enabled for the current editor */ - Editor.prototype.getShowLineNumbers = function () { - return PreferencesManager.get(SHOW_LINE_NUMBERS, this.document.file.fullPath); - }; - - /** - * Sets show active line option. - * Affects any editors that share the same preference location. - * @param {boolean} value - * @return {boolean} true if value was set - */ - Editor.prototype.setShowActiveLine = function (value) { - return PreferencesManager.set(STYLE_ACTIVE_LINE, value).valid; - }; - - /** @type {boolean} Returns true if show active line is enabled for the current editor */ - Editor.prototype.getShowActiveLine = function () { - return PreferencesManager.get(STYLE_ACTIVE_LINE, this.document.file.fullPath); - }; - - /** - * Sets word wrap option. - * Affects any editors that share the same preference location. - * @param {boolean} value - * @return {boolean} true if value was set - */ - Editor.prototype.setWordWrap = function (value) { - return PreferencesManager.set(WORD_WRAP, value).valid; - }; - - /** @type {boolean} Returns true if word wrap is enabled for the current editor */ - Editor.prototype.getWordWrap = function () { - return PreferencesManager.get(WORD_WRAP, this.document.file.fullPath); - }; - // Set up listeners for preference changes editorOptions.forEach(function (prefName) { PreferencesManager.on("change", prefName, function () { diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index 548d122f652..06b6585faf8 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -34,6 +34,7 @@ define(function (require, exports, module) { // Load dependent modules var AppInit = require("utils/AppInit"), AnimationUtils = require("utils/AnimationUtils"), + Editor = require("editor/Editor").Editor, EditorManager = require("editor/EditorManager"), KeyEvent = require("utils/KeyEvent"), StatusBar = require("widgets/StatusBar"), @@ -80,10 +81,10 @@ define(function (require, exports, module) { /** * Update indent type and size - * @param {Editor} editor Current editor + * @param {string} fullPath Path to file in current editor */ - function _updateIndentType(editor) { - var indentWithTabs = editor.getUseTabChar(); + function _updateIndentType(fullPath) { + var indentWithTabs = Editor.getUseTabChar(fullPath); $indentType.text(indentWithTabs ? Strings.STATUSBAR_TAB_SIZE : Strings.STATUSBAR_SPACES); $indentType.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_TOOLTIP_SPACES : Strings.STATUSBAR_INDENT_TOOLTIP_TABS); $indentWidthLabel.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_TABS : Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES); @@ -91,19 +92,19 @@ define(function (require, exports, module) { /** * Get indent size based on type - * @param {Editor} editor Current editor + * @param {string} fullPath Path to file in current editor * @return {number} Indent size */ - function _getIndentSize(editor) { - return editor.getUseTabChar() ? editor.getTabSize() : editor.getSpaceUnits(); + function _getIndentSize(fullPath) { + return Editor.getUseTabChar(fullPath) ? Editor.getTabSize(fullPath) : Editor.getSpaceUnits(fullPath); } /** * Update indent size - * @param {Editor} editor Current editor + * @param {string} fullPath Path to file in current editor */ - function _updateIndentSize(editor) { - var size = _getIndentSize(editor); + function _updateIndentSize(fullPath) { + var size = _getIndentSize(fullPath); $indentWidthLabel.text(size); $indentWidthInput.val(size); } @@ -112,10 +113,12 @@ define(function (require, exports, module) { * Toggle indent type */ function _toggleIndentType() { - var current = EditorManager.getActiveEditor(); - current.setUseTabChar(!current.getUseTabChar()); - _updateIndentType(current); - _updateIndentSize(current); + var current = EditorManager.getActiveEditor(), + fullPath = current && current.document.file.fullPath; + + Editor.setUseTabChar(!Editor.getUseTabChar(fullPath), fullPath); + _updateIndentType(fullPath); + _updateIndentSize(fullPath); } /** @@ -154,10 +157,10 @@ define(function (require, exports, module) { /** * Change indent size - * @param {Editor} editor Current editor + * @param {string} fullPath Path to file in current editor * @param {string} value Size entered into status bar */ - function _changeIndentWidth(editor, value) { + function _changeIndentWidth(fullPath, value) { $indentWidthLabel.removeClass("hidden"); $indentWidthInput.addClass("hidden"); @@ -168,18 +171,18 @@ define(function (require, exports, module) { EditorManager.focusEditor(); var valInt = parseInt(value, 10); - if (editor.getUseTabChar()) { - if (!editor.setTabSize(valInt)) { + if (Editor.getUseTabChar(fullPath)) { + if (!Editor.setTabSize(valInt, fullPath)) { return; // validation failed } } else { - if (!editor.setSpaceUnits(valInt)) { + if (!Editor.setSpaceUnits(valInt, fullPath)) { return; // validation failed } } // update indicator - _updateIndentSize(editor); + _updateIndentSize(fullPath); // column position may change when tab size changes _updateCursorInfo(); @@ -242,12 +245,13 @@ define(function (require, exports, module) { if (!current) { StatusBar.hide(); // calls resizeEditor() if needed } else { + var fullPath = current.document.file.fullPath; StatusBar.show(); // calls resizeEditor() if needed $(current).on("cursorActivity.statusbar", _updateCursorInfo); $(current).on("optionChange.statusbar", function () { - _updateIndentType(current); - _updateIndentSize(current); + _updateIndentType(fullPath); + _updateIndentSize(fullPath); }); $(current).on("change.statusbar", function () { // async update to keep typing speed smooth @@ -262,8 +266,8 @@ define(function (require, exports, module) { _updateLanguageInfo(current); _updateFileInfo(current); _initOverwriteMode(current); - _updateIndentType(current); - _updateIndentSize(current); + _updateIndentType(fullPath); + _updateIndentSize(fullPath); } } diff --git a/src/extensions/default/JSLint/main.js b/src/extensions/default/JSLint/main.js index 90c4f24c3cd..c3ec9705dcc 100644 --- a/src/extensions/default/JSLint/main.js +++ b/src/extensions/default/JSLint/main.js @@ -35,6 +35,7 @@ define(function (require, exports, module) { // Load dependent modules var CodeInspection = brackets.getModule("language/CodeInspection"), + Editor = brackets.getModule("editor/Editor").Editor, PreferencesManager = brackets.getModule("preferences/PreferencesManager"), Strings = brackets.getModule("strings"), _ = brackets.getModule("thirdparty/lodash"); @@ -62,10 +63,7 @@ define(function (require, exports, module) { // gets indentation size depending whether the tabs or spaces are used function _getIndentSize(fullPath) { - return PreferencesManager.get( - PreferencesManager.get("useTabChar", fullPath) ? "tabSize" : "spaceUnits", - fullPath - ); + return Editor.getUseTabChar(fullPath) ? Editor.getTabSize(fullPath) : Editor.getSpaceUnits(fullPath); } /** diff --git a/test/spec/Editor-test.js b/test/spec/Editor-test.js index 995b4b483b6..8ec1cf2aa05 100644 --- a/test/spec/Editor-test.js +++ b/test/spec/Editor-test.js @@ -295,9 +295,9 @@ define(function (require, exports, module) { expect(myEditor.getColOffset({line: 5, ch: 4})).toBe(9); // Tab size 2 - var defaultTabSize = myEditor.getTabSize(); + var defaultTabSize = Editor.getTabSize(); expect(defaultTabSize).toBe(4); - myEditor.setTabSize(2); + Editor.setTabSize(2); expect(myEditor.getColOffset({line: 1, ch: 0})).toBe(0); // first line is all spaces: should be unchanged expect(myEditor.getColOffset({line: 1, ch: 1})).toBe(1); @@ -315,7 +315,7 @@ define(function (require, exports, module) { expect(myEditor.getColOffset({line: 5, ch: 4})).toBe(5); // Restore default - myEditor.setTabSize(defaultTabSize); + Editor.setTabSize(defaultTabSize); }); }); diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index e7f90697d8a..1d6591c862d 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -404,8 +404,8 @@ define(function (require, exports, module) { // create Editor instance var editor = new Editor(doc, true, $editorHolder.get(0), visibleRange); - editor.setUseTabChar(EDITOR_USE_TABS); - editor.setSpaceUnits(EDITOR_SPACE_UNITS); + Editor.setUseTabChar(EDITOR_USE_TABS); + Editor.setSpaceUnits(EDITOR_SPACE_UNITS); EditorManager._notifyActiveEditorChanged(editor); return editor; From 3d82669a91d7465408cf9655769ba83230536f6b Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 27 Mar 2014 15:53:28 -0700 Subject: [PATCH 23/24] jsdoc updates --- src/editor/Editor.js | 42 +++++++++++++++++++++++------------ src/editor/EditorStatusBar.js | 2 +- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 5d5a8533e22..823be41d03d 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -2028,7 +2028,7 @@ define(function (require, exports, module) { * Sets whether to use tab characters (vs. spaces) when inserting new text. * Affects any editors that share the same preference location. * @param {boolean} value - * @param {string=} fullPath + * @param {string=} fullPath Path to file to get preference for * @return {boolean} true if value was valid */ Editor.setUseTabChar = function (value, fullPath) { @@ -2037,7 +2037,9 @@ define(function (require, exports, module) { }; /** - * @type {boolean} Gets whether the specified or current file uses tab characters (vs. spaces) when inserting new text + * Gets whether the specified or current file uses tab characters (vs. spaces) when inserting new text + * @param {string=} fullPath Path to file to get preference for + * @return {boolean} */ Editor.getUseTabChar = function (fullPath) { return PreferencesManager.get(USE_TAB_CHAR, fullPath); @@ -2047,7 +2049,7 @@ define(function (require, exports, module) { * Sets tab character width. * Affects any editors that share the same preference location. * @param {number} value - * @param {string=} fullPath + * @param {string=} fullPath Path to file to get preference for * @return {boolean} true if value was valid */ Editor.setTabSize = function (value, fullPath) { @@ -2056,7 +2058,9 @@ define(function (require, exports, module) { }; /** - * @type {number} Get indent unit + * Get indent unit + * @param {string=} fullPath Path to file to get preference for + * @return {number} */ Editor.getTabSize = function (fullPath) { return PreferencesManager.get(TAB_SIZE, fullPath); @@ -2066,7 +2070,7 @@ define(function (require, exports, module) { * Sets indentation width. * Affects any editors that share the same preference location. * @param {number} value - * @param {string=} fullPath + * @param {string=} fullPath Path to file to get preference for * @return {boolean} true if value was valid */ Editor.setSpaceUnits = function (value, fullPath) { @@ -2075,7 +2079,9 @@ define(function (require, exports, module) { }; /** - * @type {number} Get indentation width + * Get indentation width + * @param {string=} fullPath Path to file to get preference for + * @return {number} */ Editor.getSpaceUnits = function (fullPath) { return PreferencesManager.get(SPACE_UNITS, fullPath); @@ -2085,7 +2091,7 @@ define(function (require, exports, module) { * Sets the auto close brackets. * Affects any editors that share the same preference location. * @param {boolean} value - * @param {string=} fullPath + * @param {string=} fullPath Path to file to get preference for * @return {boolean} true if value was valid */ Editor.setCloseBrackets = function (value, fullPath) { @@ -2094,7 +2100,9 @@ define(function (require, exports, module) { }; /** - * @type {boolean} Gets whether the specified or current file uses auto close brackets + * Gets whether the specified or current file uses auto close brackets + * @param {string=} fullPath Path to file to get preference for + * @return {boolean} */ Editor.getCloseBrackets = function (fullPath) { return PreferencesManager.get(CLOSE_BRACKETS, fullPath); @@ -2104,7 +2112,7 @@ define(function (require, exports, module) { * Sets show line numbers option. * Affects any editors that share the same preference location. * @param {boolean} value - * @param {string=} fullPath + * @param {string=} fullPath Path to file to get preference for * @return {boolean} true if value was valid */ Editor.setShowLineNumbers = function (value, fullPath) { @@ -2113,7 +2121,9 @@ define(function (require, exports, module) { }; /** - * @type {boolean} Returns true if show line numbers is enabled for the specified or current file + * Returns true if show line numbers is enabled for the specified or current file + * @param {string=} fullPath Path to file to get preference for + * @return {boolean} */ Editor.getShowLineNumbers = function (fullPath) { return PreferencesManager.get(SHOW_LINE_NUMBERS, fullPath); @@ -2123,7 +2133,7 @@ define(function (require, exports, module) { * Sets show active line option. * Affects any editors that share the same preference location. * @param {boolean} value - * @param {string=} fullPath + * @param {string=} fullPath Path to file to get preference for * @return {boolean} true if value was valid */ Editor.setShowActiveLine = function (value, fullPath) { @@ -2131,7 +2141,9 @@ define(function (require, exports, module) { }; /** - * @type {boolean} Returns true if show active line is enabled for the specified or current file + * Returns true if show active line is enabled for the specified or current file + * @param {string=} fullPath Path to file to get preference for + * @return {boolean} */ Editor.getShowActiveLine = function (fullPath) { return PreferencesManager.get(STYLE_ACTIVE_LINE, fullPath); @@ -2141,7 +2153,7 @@ define(function (require, exports, module) { * Sets word wrap option. * Affects any editors that share the same preference location. * @param {boolean} value - * @param {string=} fullPath + * @param {string=} fullPath Path to file to get preference for * @return {boolean} true if value was valid */ Editor.setWordWrap = function (value, fullPath) { @@ -2150,7 +2162,9 @@ define(function (require, exports, module) { }; /** - * @type {boolean} Returns true if word wrap is enabled for the specified or current file + * Returns true if word wrap is enabled for the specified or current file + * @param {string=} fullPath Path to file to get preference for + * @return {boolean} */ Editor.getWordWrap = function (fullPath) { return PreferencesManager.get(WORD_WRAP, fullPath); diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index 06b6585faf8..086e9b343b4 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -34,8 +34,8 @@ define(function (require, exports, module) { // Load dependent modules var AppInit = require("utils/AppInit"), AnimationUtils = require("utils/AnimationUtils"), - Editor = require("editor/Editor").Editor, EditorManager = require("editor/EditorManager"), + Editor = require("editor/Editor").Editor, KeyEvent = require("utils/KeyEvent"), StatusBar = require("widgets/StatusBar"), Strings = require("strings"), From 76a5b9187147dbab672aeaa03298cfc501d89540 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 27 Mar 2014 19:05:42 -0700 Subject: [PATCH 24/24] fix whitespace --- src/editor/EditorStatusBar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index 086e9b343b4..b80112df067 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -114,9 +114,9 @@ define(function (require, exports, module) { */ function _toggleIndentType() { var current = EditorManager.getActiveEditor(), - fullPath = current && current.document.file.fullPath; + fullPath = current && current.document.file.fullPath; - Editor.setUseTabChar(!Editor.getUseTabChar(fullPath), fullPath); + Editor.setUseTabChar(!Editor.getUseTabChar(fullPath), fullPath); _updateIndentType(fullPath); _updateIndentSize(fullPath); } @@ -245,7 +245,7 @@ define(function (require, exports, module) { if (!current) { StatusBar.hide(); // calls resizeEditor() if needed } else { - var fullPath = current.document.file.fullPath; + var fullPath = current.document.file.fullPath; StatusBar.show(); // calls resizeEditor() if needed $(current).on("cursorActivity.statusbar", _updateCursorInfo);