From 72536cfb9f3d73ca6df5b49c35c16aa699f6c761 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Mon, 11 Mar 2013 09:51:24 -0700 Subject: [PATCH 1/9] Provide editor options "line numbers", "active line" and "word wrap" as new menu items under View menu. --- src/brackets.js | 1 + src/command/Commands.js | 3 + src/command/DefaultMenus.js | 4 ++ src/editor/Editor.js | 72 +++++++++++++++++++- src/index.html | 5 +- src/nls/root/strings.js | 3 + src/styles/brackets.less | 4 ++ src/styles/brackets_codemirror_override.less | 4 ++ src/styles/brackets_theme_default.less | 3 + 9 files changed, 94 insertions(+), 5 deletions(-) diff --git a/src/brackets.js b/src/brackets.js index 46090ac6898..10c97df1785 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -99,6 +99,7 @@ define(function (require, exports, module) { require("command/DefaultMenus"); require("document/ChangedDocumentTracker"); require("editor/EditorCommandHandlers"); + require("editor/EditorOptionHandlers"); require("view/ViewCommandHandlers"); require("help/HelpCommandHandlers"); require("search/FindInFiles"); diff --git a/src/command/Commands.js b/src/command/Commands.js index 3d38f8bf101..b07c398553d 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -78,6 +78,9 @@ define(function (require, exports, module) { exports.VIEW_INCREASE_FONT_SIZE = "view.increaseFontSize"; exports.VIEW_DECREASE_FONT_SIZE = "view.decreaseFontSize"; exports.VIEW_RESTORE_FONT_SIZE = "view.restoreFontSize"; + exports.TOGGLE_LINE_NUMBERS = "view.toggleLineNumbers"; + exports.TOGGLE_ACTIVE_LINE = "view.toggleActiveLine"; + exports.TOGGLE_WORD_WRAP = "view.toggleWordWrap"; exports.TOGGLE_JSLINT = "debug.jslint"; exports.SORT_WORKINGSET_BY_ADDED = "view.sortWorkingSetByAdded"; exports.SORT_WORKINGSET_BY_NAME = "view.sortWorkingSetByName"; diff --git a/src/command/DefaultMenus.js b/src/command/DefaultMenus.js index 1d8c0527cc8..ba4c5e8a1dc 100644 --- a/src/command/DefaultMenus.js +++ b/src/command/DefaultMenus.js @@ -108,6 +108,10 @@ define(function (require, exports, module) { menu.addMenuItem(Commands.VIEW_DECREASE_FONT_SIZE); menu.addMenuItem(Commands.VIEW_RESTORE_FONT_SIZE); menu.addMenuDivider(); + menu.addMenuItem(Commands.TOGGLE_LINE_NUMBERS); + menu.addMenuItem(Commands.TOGGLE_ACTIVE_LINE); + menu.addMenuItem(Commands.TOGGLE_WORD_WRAP); + menu.addMenuDivider(); menu.addMenuItem(Commands.TOGGLE_JSLINT); /* diff --git a/src/editor/Editor.js b/src/editor/Editor.js index dbc956ac7c0..4d8bd39f89c 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -73,7 +73,8 @@ define(function (require, exports, module) { ViewUtils = require("utils/ViewUtils"); var PREFERENCES_CLIENT_ID = "com.adobe.brackets.Editor", - defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false }; + defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false, + showLineNumbers: true, styleActiveLine: true, wordWrap: true }; /** Editor preferences */ var _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs); @@ -90,6 +91,15 @@ define(function (require, exports, module) { /** @type {boolean} Global setting: Auto closes (, {, [, " and ' */ var _closeBrackets = _prefs.getValue("closeBrackets"); + /** @type {boolean} Global setting: Show line numbers in the gutter */ + var _showLineNumbers = _prefs.getValue("showLineNumbers"); + + /** @type {boolean} Global setting: Highlight the background of the line that has the cursor */ + var _styleActiveLine = _prefs.getValue("styleActiveLine"); + + /** @type {boolean} Global setting: Auto wrap lines */ + var _wordWrap = _prefs.getValue("wordWrap"); + /** @type {boolean} Guard flag to prevent focus() reentrancy (via blur handlers), even across Editors */ var _duringFocus = false; @@ -344,9 +354,11 @@ define(function (require, exports, module) { indentWithTabs: _useTabChar, tabSize: _tabSize, indentUnit: _indentUnit, - lineNumbers: true, + lineNumbers: _showLineNumbers, + lineWrapping: _wordWrap, + styleActiveLine: _styleActiveLine, matchBrackets: true, - dragDrop: false, // work around issue #1123 + dragDrop: true, extraKeys: codeMirrorKeyMap, autoCloseBrackets: _closeBrackets, autoCloseTags: { @@ -1363,6 +1375,60 @@ define(function (require, exports, module) { return _closeBrackets; }; + /** + * Sets show line numbers option and reapply it to all open editors. + * @param {boolean} value + */ + Editor.setShowLineNumbers = function (value) { + _showLineNumbers = value; + _instances.forEach(function (editor) { + editor._codeMirror.setOption("lineNumbers", _showLineNumbers); + }); + + _prefs.setValue("showLineNumbers", Boolean(_showLineNumbers)); + }; + + /** @type {boolean} Gets whether all editors are showing line numbers */ + Editor.getShowLineNumbers = function () { + return _showLineNumbers; + }; + + /** + * Sets show active line option and reapply it to all open editors. + * @param {boolean} value + */ + Editor.setShowActiveLine = function (value) { + _styleActiveLine = value; + _instances.forEach(function (editor) { + editor._codeMirror.setOption("styleActiveLine", _styleActiveLine); + }); + + _prefs.setValue("styleActiveLine", Boolean(_styleActiveLine)); + }; + + /** @type {boolean} Gets whether all editors are showing active line */ + Editor.getShowActiveLine = function () { + return _styleActiveLine; + }; + + /** + * Sets word wrap option and reapply it to all open editors. + * @param {boolean} value + */ + Editor.setWordWrap = function (value) { + _wordWrap = value; + _instances.forEach(function (editor) { + editor._codeMirror.setOption("lineWrapping", _wordWrap); + }); + + _prefs.setValue("wordWrap", Boolean(_wordWrap)); + }; + + /** @type {boolean} Gets whether all editors are enabled for word wrap */ + Editor.getWordWrap = function () { + return _wordWrap; + }; + // Define public API exports.Editor = Editor; exports.BOUNDARY_CHECK_NORMAL = BOUNDARY_CHECK_NORMAL; diff --git a/src/index.html b/src/index.html index b9d0d443ff5..70e066cc309 100644 --- a/src/index.html +++ b/src/index.html @@ -101,10 +101,11 @@ - + + + - diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 5700321c66b..64d2d765ac4 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -211,6 +211,9 @@ define({ "CMD_INCREASE_FONT_SIZE" : "Increase Font Size", "CMD_DECREASE_FONT_SIZE" : "Decrease Font Size", "CMD_RESTORE_FONT_SIZE" : "Restore Font Size", + "CMD_TOGGLE_LINE_NUMBERS" : "Show Line Numbers", + "CMD_TOGGLE_ACTIVE_LINE" : "Show Active Line", + "CMD_TOGGLE_WORD_WRAP" : "Enable Word Wrap", "CMD_SORT_WORKINGSET_BY_ADDED" : "Sort by Added", "CMD_SORT_WORKINGSET_BY_NAME" : "Sort by Name", "CMD_SORT_WORKINGSET_BY_TYPE" : "Sort by Type", diff --git a/src/styles/brackets.less b/src/styles/brackets.less index 10e227f135f..a6888aec929 100644 --- a/src/styles/brackets.less +++ b/src/styles/brackets.less @@ -570,6 +570,10 @@ a, img { height: auto; } + .CodeMirror-activeline-background { + background: darken(@activeline-bgcolor, @bc-color-step-size / 2) !important; + } + .inline-editor-header { padding: 10px 10px 0px 10px; diff --git a/src/styles/brackets_codemirror_override.less b/src/styles/brackets_codemirror_override.less index 6294fc0657b..ea61bc58f66 100644 --- a/src/styles/brackets_codemirror_override.less +++ b/src/styles/brackets_codemirror_override.less @@ -44,6 +44,10 @@ @code-padding: 15px; +.CodeMirror-activeline-background { + background: @activeline-bgcolor !important; +} + .cm-s-default { span.cm-keyword {color: @accent-keyword;} span.cm-atom {color: @accent-atom;} diff --git a/src/styles/brackets_theme_default.less b/src/styles/brackets_theme_default.less index 82ee29624c6..f67ae4b09c6 100644 --- a/src/styles/brackets_theme_default.less +++ b/src/styles/brackets_theme_default.less @@ -101,6 +101,9 @@ @selection-color-focused: #d2dcf8; @selection-color-unfocused: #d9d9d9; +/* background color of the line that has the cursor */ +@activeline-bgcolor: #e8f2ff; + /* Code font formatting * * NOTE (JRB): In order to get the web font to load early enough, we have a div called "dummy-text" that From 8f35d6441e552c4f1f12452e0314271cb71708a8 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Mon, 11 Mar 2013 09:51:24 -0700 Subject: [PATCH 2/9] Provide editor options "line numbers", "active line" and "word wrap" as new menu items under View menu. --- src/brackets.js | 1 + src/command/Commands.js | 3 + src/command/DefaultMenus.js | 4 ++ src/editor/Editor.js | 72 ++++++++++++++++++- src/editor/EditorOptionHandlers.js | 76 ++++++++++++++++++++ src/index.html | 5 +- src/nls/root/strings.js | 3 + src/styles/brackets.less | 4 ++ src/styles/brackets_codemirror_override.less | 4 ++ src/styles/brackets_theme_default.less | 3 + 10 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 src/editor/EditorOptionHandlers.js diff --git a/src/brackets.js b/src/brackets.js index 46090ac6898..10c97df1785 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -99,6 +99,7 @@ define(function (require, exports, module) { require("command/DefaultMenus"); require("document/ChangedDocumentTracker"); require("editor/EditorCommandHandlers"); + require("editor/EditorOptionHandlers"); require("view/ViewCommandHandlers"); require("help/HelpCommandHandlers"); require("search/FindInFiles"); diff --git a/src/command/Commands.js b/src/command/Commands.js index 3d38f8bf101..b07c398553d 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -78,6 +78,9 @@ define(function (require, exports, module) { exports.VIEW_INCREASE_FONT_SIZE = "view.increaseFontSize"; exports.VIEW_DECREASE_FONT_SIZE = "view.decreaseFontSize"; exports.VIEW_RESTORE_FONT_SIZE = "view.restoreFontSize"; + exports.TOGGLE_LINE_NUMBERS = "view.toggleLineNumbers"; + exports.TOGGLE_ACTIVE_LINE = "view.toggleActiveLine"; + exports.TOGGLE_WORD_WRAP = "view.toggleWordWrap"; exports.TOGGLE_JSLINT = "debug.jslint"; exports.SORT_WORKINGSET_BY_ADDED = "view.sortWorkingSetByAdded"; exports.SORT_WORKINGSET_BY_NAME = "view.sortWorkingSetByName"; diff --git a/src/command/DefaultMenus.js b/src/command/DefaultMenus.js index 1d8c0527cc8..ba4c5e8a1dc 100644 --- a/src/command/DefaultMenus.js +++ b/src/command/DefaultMenus.js @@ -108,6 +108,10 @@ define(function (require, exports, module) { menu.addMenuItem(Commands.VIEW_DECREASE_FONT_SIZE); menu.addMenuItem(Commands.VIEW_RESTORE_FONT_SIZE); menu.addMenuDivider(); + menu.addMenuItem(Commands.TOGGLE_LINE_NUMBERS); + menu.addMenuItem(Commands.TOGGLE_ACTIVE_LINE); + menu.addMenuItem(Commands.TOGGLE_WORD_WRAP); + menu.addMenuDivider(); menu.addMenuItem(Commands.TOGGLE_JSLINT); /* diff --git a/src/editor/Editor.js b/src/editor/Editor.js index dbc956ac7c0..4d8bd39f89c 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -73,7 +73,8 @@ define(function (require, exports, module) { ViewUtils = require("utils/ViewUtils"); var PREFERENCES_CLIENT_ID = "com.adobe.brackets.Editor", - defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false }; + defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false, + showLineNumbers: true, styleActiveLine: true, wordWrap: true }; /** Editor preferences */ var _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs); @@ -90,6 +91,15 @@ define(function (require, exports, module) { /** @type {boolean} Global setting: Auto closes (, {, [, " and ' */ var _closeBrackets = _prefs.getValue("closeBrackets"); + /** @type {boolean} Global setting: Show line numbers in the gutter */ + var _showLineNumbers = _prefs.getValue("showLineNumbers"); + + /** @type {boolean} Global setting: Highlight the background of the line that has the cursor */ + var _styleActiveLine = _prefs.getValue("styleActiveLine"); + + /** @type {boolean} Global setting: Auto wrap lines */ + var _wordWrap = _prefs.getValue("wordWrap"); + /** @type {boolean} Guard flag to prevent focus() reentrancy (via blur handlers), even across Editors */ var _duringFocus = false; @@ -344,9 +354,11 @@ define(function (require, exports, module) { indentWithTabs: _useTabChar, tabSize: _tabSize, indentUnit: _indentUnit, - lineNumbers: true, + lineNumbers: _showLineNumbers, + lineWrapping: _wordWrap, + styleActiveLine: _styleActiveLine, matchBrackets: true, - dragDrop: false, // work around issue #1123 + dragDrop: true, extraKeys: codeMirrorKeyMap, autoCloseBrackets: _closeBrackets, autoCloseTags: { @@ -1363,6 +1375,60 @@ define(function (require, exports, module) { return _closeBrackets; }; + /** + * Sets show line numbers option and reapply it to all open editors. + * @param {boolean} value + */ + Editor.setShowLineNumbers = function (value) { + _showLineNumbers = value; + _instances.forEach(function (editor) { + editor._codeMirror.setOption("lineNumbers", _showLineNumbers); + }); + + _prefs.setValue("showLineNumbers", Boolean(_showLineNumbers)); + }; + + /** @type {boolean} Gets whether all editors are showing line numbers */ + Editor.getShowLineNumbers = function () { + return _showLineNumbers; + }; + + /** + * Sets show active line option and reapply it to all open editors. + * @param {boolean} value + */ + Editor.setShowActiveLine = function (value) { + _styleActiveLine = value; + _instances.forEach(function (editor) { + editor._codeMirror.setOption("styleActiveLine", _styleActiveLine); + }); + + _prefs.setValue("styleActiveLine", Boolean(_styleActiveLine)); + }; + + /** @type {boolean} Gets whether all editors are showing active line */ + Editor.getShowActiveLine = function () { + return _styleActiveLine; + }; + + /** + * Sets word wrap option and reapply it to all open editors. + * @param {boolean} value + */ + Editor.setWordWrap = function (value) { + _wordWrap = value; + _instances.forEach(function (editor) { + editor._codeMirror.setOption("lineWrapping", _wordWrap); + }); + + _prefs.setValue("wordWrap", Boolean(_wordWrap)); + }; + + /** @type {boolean} Gets whether all editors are enabled for word wrap */ + Editor.getWordWrap = function () { + return _wordWrap; + }; + // Define public API exports.Editor = Editor; exports.BOUNDARY_CHECK_NORMAL = BOUNDARY_CHECK_NORMAL; diff --git a/src/editor/EditorOptionHandlers.js b/src/editor/EditorOptionHandlers.js new file mode 100644 index 00000000000..a5aba21f045 --- /dev/null +++ b/src/editor/EditorOptionHandlers.js @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013 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"; + + var AppInit = require("utils/AppInit"), + Editor = require("editor/Editor").Editor, + Commands = require("command/Commands"), + CommandManager = require("command/CommandManager"), + Strings = require("strings"); + + /** + * @private + * Activates/Deactivates showing line numbers option + */ + function _toggleLineNumbers() { + Editor.setShowLineNumbers(!Editor.getShowLineNumbers()); + CommandManager.get(Commands.TOGGLE_LINE_NUMBERS).setChecked(Editor.getShowLineNumbers()); + } + + + /** + * @private + * Activates/Deactivates showing active line option + */ + function _toggleActiveLine() { + Editor.setShowActiveLine(!Editor.getShowActiveLine()); + CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine()); + } + + + /** + * @private + * Activates/Deactivates word wrap option + */ + function _toggleWordWrap() { + Editor.setWordWrap(!Editor.getWordWrap()); + CommandManager.get(Commands.TOGGLE_WORD_WRAP).setChecked(Editor.getWordWrap()); + } + + function _init() { + CommandManager.get(Commands.TOGGLE_LINE_NUMBERS).setChecked(Editor.getShowLineNumbers()); + CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine()); + CommandManager.get(Commands.TOGGLE_WORD_WRAP).setChecked(Editor.getWordWrap()); + } + + CommandManager.register(Strings.CMD_TOGGLE_LINE_NUMBERS, Commands.TOGGLE_LINE_NUMBERS, _toggleLineNumbers); + CommandManager.register(Strings.CMD_TOGGLE_ACTIVE_LINE, Commands.TOGGLE_ACTIVE_LINE, _toggleActiveLine); + CommandManager.register(Strings.CMD_TOGGLE_WORD_WRAP, Commands.TOGGLE_WORD_WRAP, _toggleWordWrap); + + AppInit.htmlReady(_init); +}); diff --git a/src/index.html b/src/index.html index b9d0d443ff5..70e066cc309 100644 --- a/src/index.html +++ b/src/index.html @@ -101,10 +101,11 @@ - + + + - diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 5700321c66b..64d2d765ac4 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -211,6 +211,9 @@ define({ "CMD_INCREASE_FONT_SIZE" : "Increase Font Size", "CMD_DECREASE_FONT_SIZE" : "Decrease Font Size", "CMD_RESTORE_FONT_SIZE" : "Restore Font Size", + "CMD_TOGGLE_LINE_NUMBERS" : "Show Line Numbers", + "CMD_TOGGLE_ACTIVE_LINE" : "Show Active Line", + "CMD_TOGGLE_WORD_WRAP" : "Enable Word Wrap", "CMD_SORT_WORKINGSET_BY_ADDED" : "Sort by Added", "CMD_SORT_WORKINGSET_BY_NAME" : "Sort by Name", "CMD_SORT_WORKINGSET_BY_TYPE" : "Sort by Type", diff --git a/src/styles/brackets.less b/src/styles/brackets.less index 10e227f135f..a6888aec929 100644 --- a/src/styles/brackets.less +++ b/src/styles/brackets.less @@ -570,6 +570,10 @@ a, img { height: auto; } + .CodeMirror-activeline-background { + background: darken(@activeline-bgcolor, @bc-color-step-size / 2) !important; + } + .inline-editor-header { padding: 10px 10px 0px 10px; diff --git a/src/styles/brackets_codemirror_override.less b/src/styles/brackets_codemirror_override.less index 6294fc0657b..ea61bc58f66 100644 --- a/src/styles/brackets_codemirror_override.less +++ b/src/styles/brackets_codemirror_override.less @@ -44,6 +44,10 @@ @code-padding: 15px; +.CodeMirror-activeline-background { + background: @activeline-bgcolor !important; +} + .cm-s-default { span.cm-keyword {color: @accent-keyword;} span.cm-atom {color: @accent-atom;} diff --git a/src/styles/brackets_theme_default.less b/src/styles/brackets_theme_default.less index 82ee29624c6..f67ae4b09c6 100644 --- a/src/styles/brackets_theme_default.less +++ b/src/styles/brackets_theme_default.less @@ -101,6 +101,9 @@ @selection-color-focused: #d2dcf8; @selection-color-unfocused: #d9d9d9; +/* background color of the line that has the cursor */ +@activeline-bgcolor: #e8f2ff; + /* Code font formatting * * NOTE (JRB): In order to get the web font to load early enough, we have a div called "dummy-text" that From 5f5ef09b8dc1f4705c088faaf75190d85684ca41 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Tue, 12 Mar 2013 23:15:33 -0700 Subject: [PATCH 3/9] Add unit tests for word-wrap and active line options. --- test/UnitTestSuite.js | 1 + .../EditorOptionHandlers-test-files/test.css | 1 + .../EditorOptionHandlers-test-files/test.html | 12 + test/spec/EditorOptionHandlers-test.js | 316 ++++++++++++++++++ 4 files changed, 330 insertions(+) create mode 100644 test/spec/EditorOptionHandlers-test-files/test.css create mode 100644 test/spec/EditorOptionHandlers-test-files/test.html create mode 100644 test/spec/EditorOptionHandlers-test.js diff --git a/test/UnitTestSuite.js b/test/UnitTestSuite.js index 7b36e9c74dc..6cf2fa1a699 100644 --- a/test/UnitTestSuite.js +++ b/test/UnitTestSuite.js @@ -35,6 +35,7 @@ define(function (require, exports, module) { require("spec/DocumentCommandHandlers-test"); require("spec/Editor-test"); require("spec/EditorCommandHandlers-test"); + require("spec/EditorOptionHandlers-test"); require("spec/EditorManager-test"); require("spec/ExtensionUtils-test"); require("spec/FileIndexManager-test"); diff --git a/test/spec/EditorOptionHandlers-test-files/test.css b/test/spec/EditorOptionHandlers-test-files/test.css new file mode 100644 index 00000000000..ef7b580936b --- /dev/null +++ b/test/spec/EditorOptionHandlers-test-files/test.css @@ -0,0 +1 @@ +.longLineClass { margin: 0 auto; padding: 2em; max-width: 800px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.5em; color: #333333; background-color: #ffffff; -webkit-box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); -moz-box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); } \ No newline at end of file diff --git a/test/spec/EditorOptionHandlers-test-files/test.html b/test/spec/EditorOptionHandlers-test-files/test.html new file mode 100644 index 00000000000..0e8c832fc03 --- /dev/null +++ b/test/spec/EditorOptionHandlers-test-files/test.html @@ -0,0 +1,12 @@ + + + +Simple Test + + + + +

Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome!

+

Brackets is awesome!

+ + \ No newline at end of file diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js new file mode 100644 index 00000000000..152b375379c --- /dev/null +++ b/test/spec/EditorOptionHandlers-test.js @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2013 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, beforeEach, afterEach, it, runs, waitsFor, expect, brackets, waitsForDone */ + +define(function (require, exports, module) { + 'use strict'; + + // Load dependent modules + var CommandManager, // loaded from brackets.test + Commands, // loaded from brackets.test + EditorManager, // loaded from brackets.test + DocumentManager, // loaded from brackets.test + FileViewController, + SpecRunnerUtils = require("spec/SpecRunnerUtils"); + + + describe("EditorOptionHandlers", function () { + this.category = "integration"; + + var testPath = SpecRunnerUtils.getTestPath("/spec/EditorOptionHandlers-test-files"), + testWindow; + + beforeEach(function () { + SpecRunnerUtils.createTestWindowAndRun(this, function (w) { + testWindow = w; + + // Load module instances from brackets.test + CommandManager = testWindow.brackets.test.CommandManager; + Commands = testWindow.brackets.test.Commands; + EditorManager = testWindow.brackets.test.EditorManager; + DocumentManager = testWindow.brackets.test.DocumentManager; + FileViewController = testWindow.brackets.test.FileViewController; + + SpecRunnerUtils.loadProjectInTestWindow(testPath); + }); + }); + + afterEach(function () { + SpecRunnerUtils.closeTestWindow(); + }); + + var CSS_FILE = testPath + "/test.css", + HTML_FILE = testPath + "/test.html"; + + it("should wrap long lines in main editor by default", function () { + var promise, + editor, + firstLineBottom, + nextLineBottom; + + runs(function () { + promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: HTML_FILE}); + waitsForDone(promise, "Open into working set"); + }); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + // Set the cursor at the beginning of the long line and get its bottom coordinate. + editor.setCursorPos({line: 8, ch: 0}); + firstLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; + + // Set the cursor somewhere on the long line that will be part of an extra line + // created by word-wrap and get its bottom coordinate. + editor.setCursorPos({line: 8, ch: 210}); + nextLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; + expect(firstLineBottom).toBeLessThan(nextLineBottom); + }); + }); + + it("should also wrap long lines in inline editor by default", function () { + var promise, + firstLineBottom, + nextLineBottom, + inlineEditor; + + runs(function () { + promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: HTML_FILE}); + waitsForDone(promise, "Open into working set"); + }); + + runs(function () { + // Open inline editor onto test.css's ".testClass" rule + promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 11}); + waitsForDone(promise, "Open inline editor"); + }); + + runs(function () { + inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + expect(inlineEditor).toBeTruthy(); + + // Set the cursor at the beginning of the long line and get its bottom coordinate. + inlineEditor.setCursorPos({line: 0, ch: 0}); + firstLineBottom = inlineEditor._codeMirror.cursorCoords(null, "local").bottom; + + // Set the cursor somewhere on the long line that will be part of an extra line + // created by word-wrap and get its bottom coordinate. + inlineEditor.setCursorPos({line: 0, ch: 160}); + nextLineBottom = inlineEditor._codeMirror.cursorCoords(null, "local").bottom; + expect(firstLineBottom).toBeLessThan(nextLineBottom); + }); + }); + + it("should NOT wrap the long lines after turning off word-wrap", function () { + var promise, + editor, + firstLineBottom, + nextLineBottom; + + // Turn off word-wrap + runs(function () { + promise = CommandManager.execute(Commands.TOGGLE_WORD_WRAP); + waitsForDone(promise, "Toggle word-wrap"); + }); + + runs(function () { + promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: CSS_FILE}); + waitsForDone(promise, "Open into working set"); + }); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + editor.setCursorPos({line: 0, ch: 1}); + firstLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; + + editor.setCursorPos({line: 0, ch: 180}); + nextLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; + expect(firstLineBottom).toEqual(nextLineBottom); + }); + }); + + it("should NOT wrap the long lines in another document when word-wrap off", function () { + var promise, + editor, + firstLineBottom, + nextLineBottom; + + runs(function () { + promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: CSS_FILE}); + waitsForDone(promise, "Open into working set"); + }); + + // Turn off word-wrap + runs(function () { + promise = CommandManager.execute(Commands.TOGGLE_WORD_WRAP); + waitsForDone(promise, "Toggle word-wrap"); + }); + + runs(function () { + var openAndSelect = function (path) { + var doc, didOpen = false, gotError = false; + + // open file + runs(function () { + FileViewController.openAndSelectDocument(path, FileViewController.PROJECT_MANAGER) + .done(function () { didOpen = true; }) + .fail(function () { gotError = true; }); + }); + waitsFor(function () { return didOpen && !gotError; }, "FILE_OPEN on file timeout", 1000); + }; + + openAndSelect(HTML_FILE); + }); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + editor.setCursorPos({line: 8, ch: 0}); + firstLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; + + editor.setCursorPos({line: 8, ch: 210}); + nextLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; + expect(firstLineBottom).toEqual(nextLineBottom); + }); + }); + + it("should show active line in main editor by default", function () { + var promise, + editor, + lineInfo; + + runs(function () { + promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: HTML_FILE}); + waitsForDone(promise, "Open into working set"); + }); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + editor.setCursorPos({line: 5, ch: 0}); + lineInfo = editor._codeMirror.lineInfo(5); + expect(lineInfo.wrapClass).toBe("CodeMirror-activeline"); + }); + }); + + it("should also show active line in inline editor by default", function () { + var promise, + inlineEditor, + lineInfo; + + runs(function () { + promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: HTML_FILE}); + waitsForDone(promise, "Open into working set"); + }); + + runs(function () { + // Open inline editor onto test.css's ".testClass" rule + promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 11}); + waitsForDone(promise, "Open inline editor"); + }); + + runs(function () { + inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + expect(inlineEditor).toBeTruthy(); + + lineInfo = inlineEditor._codeMirror.lineInfo(0); + expect(lineInfo.wrapClass).toBe("CodeMirror-activeline"); + }); + }); + + it("should NOT style active line after turning it off", function () { + var promise, + editor, + lineInfo; + + // Turn off show active line + runs(function () { + promise = CommandManager.execute(Commands.TOGGLE_ACTIVE_LINE); + waitsForDone(promise, "Toggle active line"); + }); + + runs(function () { + promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: CSS_FILE}); + waitsForDone(promise, "Open into working set"); + }); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + lineInfo = editor._codeMirror.lineInfo(0); + expect(lineInfo.wrapClass).toBeUndefined(); + }); + }); + + it("should NOT style the active line when opening another document with show active line off", function () { + var promise, + editor, + lineInfo; + + runs(function () { + promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: CSS_FILE}); + waitsForDone(promise, "Open into working set"); + }); + + // Turn off show active line + runs(function () { + promise = CommandManager.execute(Commands.TOGGLE_ACTIVE_LINE); + waitsForDone(promise, "Toggle active line"); + }); + + runs(function () { + var openAndSelect = function (path) { + var doc, didOpen = false, gotError = false; + + // open file + runs(function () { + FileViewController.openAndSelectDocument(path, FileViewController.PROJECT_MANAGER) + .done(function () { didOpen = true; }) + .fail(function () { gotError = true; }); + }); + waitsFor(function () { return didOpen && !gotError; }, "FILE_OPEN on file timeout", 1000); + }; + + openAndSelect(HTML_FILE); + }); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + editor.setCursorPos({line: 3, ch: 5}); + lineInfo = editor._codeMirror.lineInfo(3); + expect(lineInfo.wrapClass).toBeUndefined(); + }); + }); + }); +}); From 47a3be3693fda64ed3f96ef60aa3bf9f808bdf53 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Thu, 14 Mar 2013 11:13:05 -0700 Subject: [PATCH 4/9] Move auto close brackets to EditorOptionHandlers.js file. --- src/editor/EditorManager.js | 13 ------------- src/editor/EditorOptionHandlers.js | 11 +++++++++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/editor/EditorManager.js b/src/editor/EditorManager.js index 0209610466f..577ec9ccab7 100644 --- a/src/editor/EditorManager.js +++ b/src/editor/EditorManager.js @@ -684,21 +684,8 @@ define(function (require, exports, module) { return result.promise(); } - /** - * @private - * Activates/Deactivates the automatic close brackets option - */ - function _toggleCloseBrackets() { - Editor.setCloseBrackets(!Editor.getCloseBrackets()); - CommandManager.get(Commands.TOGGLE_CLOSE_BRACKETS).setChecked(Editor.getCloseBrackets()); - } - - // Initialize: command handlers CommandManager.register(Strings.CMD_TOGGLE_QUICK_EDIT, Commands.TOGGLE_QUICK_EDIT, _toggleQuickEdit); - CommandManager.register(Strings.CMD_TOGGLE_CLOSE_BRACKETS, Commands.TOGGLE_CLOSE_BRACKETS, _toggleCloseBrackets) - .setChecked(Editor.getCloseBrackets()); - // Initialize: register listeners $(DocumentManager).on("currentDocumentChange", _onCurrentDocumentChange); diff --git a/src/editor/EditorOptionHandlers.js b/src/editor/EditorOptionHandlers.js index a5aba21f045..caa8fed7e38 100644 --- a/src/editor/EditorOptionHandlers.js +++ b/src/editor/EditorOptionHandlers.js @@ -62,15 +62,26 @@ define(function (require, exports, module) { CommandManager.get(Commands.TOGGLE_WORD_WRAP).setChecked(Editor.getWordWrap()); } + /** + * @private + * Activates/Deactivates the automatic close brackets option + */ + function _toggleCloseBrackets() { + Editor.setCloseBrackets(!Editor.getCloseBrackets()); + CommandManager.get(Commands.TOGGLE_CLOSE_BRACKETS).setChecked(Editor.getCloseBrackets()); + } + function _init() { CommandManager.get(Commands.TOGGLE_LINE_NUMBERS).setChecked(Editor.getShowLineNumbers()); CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine()); CommandManager.get(Commands.TOGGLE_WORD_WRAP).setChecked(Editor.getWordWrap()); + CommandManager.get(Commands.CMD_TOGGLE_CLOSE_BRACKETS).setChecked(Editor.getCloseBrackets()); } CommandManager.register(Strings.CMD_TOGGLE_LINE_NUMBERS, Commands.TOGGLE_LINE_NUMBERS, _toggleLineNumbers); CommandManager.register(Strings.CMD_TOGGLE_ACTIVE_LINE, Commands.TOGGLE_ACTIVE_LINE, _toggleActiveLine); CommandManager.register(Strings.CMD_TOGGLE_WORD_WRAP, Commands.TOGGLE_WORD_WRAP, _toggleWordWrap); + CommandManager.register(Strings.CMD_TOGGLE_CLOSE_BRACKETS, Commands.TOGGLE_CLOSE_BRACKETS, _toggleCloseBrackets); AppInit.htmlReady(_init); }); From 5f8e4e8dca4806243fe9f5b5ab960a07c9961c87 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Fri, 15 Mar 2013 15:23:28 -0700 Subject: [PATCH 5/9] Add back two strings being removed from merge. Fix all issues in Jason's review comments Refactor some of repeated lines in Editor.js to a private function. --- Gruntfile.js | 2 + src/editor/Editor.js | 66 +++++++++++--------------- src/editor/EditorOptionHandlers.js | 2 +- src/nls/root/strings.js | 2 + test/SpecRunner.html | 1 + test/spec/EditorOptionHandlers-test.js | 32 +++---------- 6 files changed, 40 insertions(+), 65 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index c1a7997bcef..0b7b95d463a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -76,6 +76,8 @@ module.exports = function (grunt) { 'src/thirdparty/CodeMirror2/lib/codemirror.js', 'src/thirdparty/CodeMirror2/lib/util/dialog.js', 'src/thirdparty/CodeMirror2/lib/util/searchcursor.js', + 'src/thirdparty/CodeMirror2/addon/edit/closetag.js', + 'src/thirdparty/CodeMirror2/addon/selection/active-line.js', 'src/thirdparty/mustache/mustache.js', 'src/thirdparty/path-utils/path-utils.min' ], diff --git a/src/editor/Editor.js b/src/editor/Editor.js index fa0f07b731b..b7d28a06c29 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1313,17 +1313,29 @@ define(function (require, exports, module) { // Global settings that affect all Editor instances (both currently open Editors as well as those created // in the future) + + /** + * @private + * Updates Editor option and the corresponding preference with the given value. Affects all Editors. + * @param {boolean | number} value + * @param {string} cmOption - CodeMirror option string + * @param {string} prefName - preference name string + */ + function _setEditorOptionAndPref(value, cmOption, prefName) { + _instances.forEach(function (editor) { + editor._codeMirror.setOption(cmOption, value); + }); + + _prefs.setValue(prefName, (typeof value === "boolean") ? Boolean(value) : value); + } + /** * Sets whether to use tab characters (vs. spaces) when inserting new text. Affects all Editors. * @param {boolean} value */ Editor.setUseTabChar = function (value) { _useTabChar = value; - _instances.forEach(function (editor) { - editor._codeMirror.setOption("indentWithTabs", _useTabChar); - }); - - _prefs.setValue("useTabChar", Boolean(_useTabChar)); + _setEditorOptionAndPref(value, "indentWithTabs", "useTabChar"); }; /** @type {boolean} Gets whether all Editors use tab characters (vs. spaces) when inserting new text */ @@ -1337,11 +1349,7 @@ define(function (require, exports, module) { */ Editor.setTabSize = function (value) { _tabSize = value; - _instances.forEach(function (editor) { - editor._codeMirror.setOption("tabSize", _tabSize); - }); - - _prefs.setValue("tabSize", _tabSize); + _setEditorOptionAndPref(value, "tabSize", "tabSize"); }; /** @type {number} Get indent unit */ @@ -1355,11 +1363,7 @@ define(function (require, exports, module) { */ Editor.setIndentUnit = function (value) { _indentUnit = value; - _instances.forEach(function (editor) { - editor._codeMirror.setOption("indentUnit", _indentUnit); - }); - - _prefs.setValue("indentUnit", _indentUnit); + _setEditorOptionAndPref(value, "indentUnit", "indentUnit"); }; /** @type {number} Get indentation width */ @@ -1373,11 +1377,7 @@ define(function (require, exports, module) { */ Editor.setCloseBrackets = function (value) { _closeBrackets = value; - _instances.forEach(function (editor) { - editor._codeMirror.setOption("autoCloseBrackets", _closeBrackets); - }); - - _prefs.setValue("closeBrackets", Boolean(_closeBrackets)); + _setEditorOptionAndPref(value, "autoCloseBrackets", "closeBrackets"); }; /** @type {boolean} Gets whether all Editors use auto close brackets */ @@ -1385,20 +1385,16 @@ define(function (require, exports, module) { return _closeBrackets; }; - /** + /** * Sets show line numbers option and reapply it to all open editors. * @param {boolean} value */ Editor.setShowLineNumbers = function (value) { _showLineNumbers = value; - _instances.forEach(function (editor) { - editor._codeMirror.setOption("lineNumbers", _showLineNumbers); - }); - - _prefs.setValue("showLineNumbers", Boolean(_showLineNumbers)); + _setEditorOptionAndPref(value, "lineNumbers", "showLineNumbers"); }; - /** @type {boolean} Gets whether all editors are showing line numbers */ + /** @type {boolean} Returns true if show line numbers is enabled for all editors */ Editor.getShowLineNumbers = function () { return _showLineNumbers; }; @@ -1409,14 +1405,10 @@ define(function (require, exports, module) { */ Editor.setShowActiveLine = function (value) { _styleActiveLine = value; - _instances.forEach(function (editor) { - editor._codeMirror.setOption("styleActiveLine", _styleActiveLine); - }); - - _prefs.setValue("styleActiveLine", Boolean(_styleActiveLine)); + _setEditorOptionAndPref(value, "styleActiveLine", "styleActiveLine"); }; - /** @type {boolean} Gets whether all editors are showing active line */ + /** @type {boolean} "Returns true if show active line is enabled for all editors */ Editor.getShowActiveLine = function () { return _styleActiveLine; }; @@ -1427,14 +1419,10 @@ define(function (require, exports, module) { */ Editor.setWordWrap = function (value) { _wordWrap = value; - _instances.forEach(function (editor) { - editor._codeMirror.setOption("lineWrapping", _wordWrap); - }); - - _prefs.setValue("wordWrap", Boolean(_wordWrap)); + _setEditorOptionAndPref(value, "lineWrapping", "wordWrap"); }; - /** @type {boolean} Gets whether all editors are enabled for word wrap */ + /** @type {boolean} Returns true if word wrap is enabled for all editors */ Editor.getWordWrap = function () { return _wordWrap; }; diff --git a/src/editor/EditorOptionHandlers.js b/src/editor/EditorOptionHandlers.js index caa8fed7e38..2535d42a0c7 100644 --- a/src/editor/EditorOptionHandlers.js +++ b/src/editor/EditorOptionHandlers.js @@ -22,7 +22,7 @@ */ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ -/*global define, window, $ */ +/*global define */ define(function (require, exports, module) { "use strict"; diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 4b1fb4b1bd0..5653a586a3b 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -213,6 +213,8 @@ define({ "CMD_RESTORE_FONT_SIZE" : "Restore Font Size", "CMD_SCROLL_LINE_UP" : "Scroll Line Up", "CMD_SCROLL_LINE_DOWN" : "Scroll Line Down", + "CMD_TOGGLE_LINE_NUMBERS" : "Show Line Numbers", + "CMD_TOGGLE_ACTIVE_LINE" : "Show Active Line", "CMD_TOGGLE_WORD_WRAP" : "Enable Word Wrap", "CMD_SORT_WORKINGSET_BY_ADDED" : "Sort by Added", "CMD_SORT_WORKINGSET_BY_NAME" : "Sort by Name", diff --git a/test/SpecRunner.html b/test/SpecRunner.html index 2ffccf96940..f566a43854d 100644 --- a/test/SpecRunner.html +++ b/test/SpecRunner.html @@ -39,6 +39,7 @@ + diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js index 152b375379c..9acc8cb1e98 100644 --- a/test/spec/EditorOptionHandlers-test.js +++ b/test/spec/EditorOptionHandlers-test.js @@ -173,19 +173,11 @@ define(function (require, exports, module) { }); runs(function () { - var openAndSelect = function (path) { - var doc, didOpen = false, gotError = false; - - // open file - runs(function () { - FileViewController.openAndSelectDocument(path, FileViewController.PROJECT_MANAGER) - .done(function () { didOpen = true; }) - .fail(function () { gotError = true; }); - }); - waitsFor(function () { return didOpen && !gotError; }, "FILE_OPEN on file timeout", 1000); - }; + // Open another document and bring it to the front + waitsForDone(FileViewController.openAndSelectDocument(HTML_FILE, FileViewController.PROJECT_MANAGER), + "FILE_OPEN on file timeout", 1000); - openAndSelect(HTML_FILE); +// openAndSelect(HTML_FILE); }); runs(function () { @@ -288,19 +280,9 @@ define(function (require, exports, module) { }); runs(function () { - var openAndSelect = function (path) { - var doc, didOpen = false, gotError = false; - - // open file - runs(function () { - FileViewController.openAndSelectDocument(path, FileViewController.PROJECT_MANAGER) - .done(function () { didOpen = true; }) - .fail(function () { gotError = true; }); - }); - waitsFor(function () { return didOpen && !gotError; }, "FILE_OPEN on file timeout", 1000); - }; - - openAndSelect(HTML_FILE); + // Open another document and bring it to the front + waitsForDone(FileViewController.openAndSelectDocument(HTML_FILE, FileViewController.PROJECT_MANAGER), + "FILE_OPEN on file timeout", 1000); }); runs(function () { From e51f24adaad1b96feb3b5aed5eaee2e24e4142bd Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Mon, 18 Mar 2013 09:43:31 -0700 Subject: [PATCH 6/9] Refactor some common code into a function. --- test/spec/EditorOptionHandlers-test.js | 86 +++++++++----------------- 1 file changed, 30 insertions(+), 56 deletions(-) diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js index 9acc8cb1e98..4f5b837df27 100644 --- a/test/spec/EditorOptionHandlers-test.js +++ b/test/spec/EditorOptionHandlers-test.js @@ -62,40 +62,48 @@ define(function (require, exports, module) { SpecRunnerUtils.closeTestWindow(); }); + function checkLineWrapping(firstPos, secondPos, shouldWrap, inlineEditor) { + runs(function () { + var firstLineBottom, + nextLineBottom, + editor = inlineEditor || EditorManager.getCurrentFullEditor(); + + expect(editor).toBeTruthy(); + + editor.setCursorPos(firstPos); + firstLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; + + editor.setCursorPos(secondPos); + nextLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; + if (shouldWrap) { + expect(firstLineBottom).toBeLessThan(nextLineBottom); + } else { + expect(firstLineBottom).toEqual(nextLineBottom); + } + }); + } + var CSS_FILE = testPath + "/test.css", HTML_FILE = testPath + "/test.html"; it("should wrap long lines in main editor by default", function () { var promise, - editor, - firstLineBottom, - nextLineBottom; + editor; runs(function () { promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: HTML_FILE}); waitsForDone(promise, "Open into working set"); - }); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - // Set the cursor at the beginning of the long line and get its bottom coordinate. - editor.setCursorPos({line: 8, ch: 0}); - firstLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; - - // Set the cursor somewhere on the long line that will be part of an extra line + // Use two cursor positions to detect line wrapping. First position at + // the beginning of a long line and the second position to be + // somewhere on the long line that will be part of an extra line // created by word-wrap and get its bottom coordinate. - editor.setCursorPos({line: 8, ch: 210}); - nextLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; - expect(firstLineBottom).toBeLessThan(nextLineBottom); + checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, true); }); }); it("should also wrap long lines in inline editor by default", function () { var promise, - firstLineBottom, - nextLineBottom, inlineEditor; runs(function () { @@ -113,23 +121,13 @@ define(function (require, exports, module) { inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; expect(inlineEditor).toBeTruthy(); - // Set the cursor at the beginning of the long line and get its bottom coordinate. - inlineEditor.setCursorPos({line: 0, ch: 0}); - firstLineBottom = inlineEditor._codeMirror.cursorCoords(null, "local").bottom; - - // Set the cursor somewhere on the long line that will be part of an extra line - // created by word-wrap and get its bottom coordinate. - inlineEditor.setCursorPos({line: 0, ch: 160}); - nextLineBottom = inlineEditor._codeMirror.cursorCoords(null, "local").bottom; - expect(firstLineBottom).toBeLessThan(nextLineBottom); + checkLineWrapping({line: 0, ch: 0}, {line: 0, ch: 160}, true, inlineEditor); }); }); it("should NOT wrap the long lines after turning off word-wrap", function () { var promise, - editor, - firstLineBottom, - nextLineBottom; + editor; // Turn off word-wrap runs(function () { @@ -140,18 +138,7 @@ define(function (require, exports, module) { runs(function () { promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: CSS_FILE}); waitsForDone(promise, "Open into working set"); - }); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - editor.setCursorPos({line: 0, ch: 1}); - firstLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; - - editor.setCursorPos({line: 0, ch: 180}); - nextLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; - expect(firstLineBottom).toEqual(nextLineBottom); + checkLineWrapping({line: 0, ch: 1}, {line: 0, ch: 180}, false); }); }); @@ -176,20 +163,7 @@ define(function (require, exports, module) { // Open another document and bring it to the front waitsForDone(FileViewController.openAndSelectDocument(HTML_FILE, FileViewController.PROJECT_MANAGER), "FILE_OPEN on file timeout", 1000); - -// openAndSelect(HTML_FILE); - }); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - editor.setCursorPos({line: 8, ch: 0}); - firstLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; - - editor.setCursorPos({line: 8, ch: 210}); - nextLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; - expect(firstLineBottom).toEqual(nextLineBottom); + checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, false); }); }); From 38e572a72dbe70a89fbac4c366d981b5ad467fdf Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Mon, 18 Mar 2013 16:50:04 -0700 Subject: [PATCH 7/9] Remove the extra quote. --- src/editor/Editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index b7d28a06c29..aa83e750bad 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1408,7 +1408,7 @@ define(function (require, exports, module) { _setEditorOptionAndPref(value, "styleActiveLine", "styleActiveLine"); }; - /** @type {boolean} "Returns true if show active line is enabled for all editors */ + /** @type {boolean} Returns true if show active line is enabled for all editors */ Editor.getShowActiveLine = function () { return _styleActiveLine; }; From 29e28f8c812c243276c490bf27e08f295fd30e77 Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Tue, 19 Mar 2013 15:59:59 -0700 Subject: [PATCH 8/9] Add back "var" that was accidentally removed when resolving the merge conflict. --- src/editor/Editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 32f7eaa5697..67ad7cf828e 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -72,7 +72,7 @@ define(function (require, exports, module) { TokenUtils = require("utils/TokenUtils"), ViewUtils = require("utils/ViewUtils"); - defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false, + var defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false, showLineNumbers: true, styleActiveLine: true, wordWrap: true }; /** Editor preferences */ From 9996e841c9a397f0515b2f0aa45063b64217e29d Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Tue, 19 Mar 2013 20:58:44 -0700 Subject: [PATCH 9/9] Fix a typo that is causing auto close brackets command to be undefined. --- src/editor/EditorOptionHandlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/EditorOptionHandlers.js b/src/editor/EditorOptionHandlers.js index 2535d42a0c7..d51776695c2 100644 --- a/src/editor/EditorOptionHandlers.js +++ b/src/editor/EditorOptionHandlers.js @@ -75,7 +75,7 @@ define(function (require, exports, module) { CommandManager.get(Commands.TOGGLE_LINE_NUMBERS).setChecked(Editor.getShowLineNumbers()); CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine()); CommandManager.get(Commands.TOGGLE_WORD_WRAP).setChecked(Editor.getWordWrap()); - CommandManager.get(Commands.CMD_TOGGLE_CLOSE_BRACKETS).setChecked(Editor.getCloseBrackets()); + CommandManager.get(Commands.TOGGLE_CLOSE_BRACKETS).setChecked(Editor.getCloseBrackets()); } CommandManager.register(Strings.CMD_TOGGLE_LINE_NUMBERS, Commands.TOGGLE_LINE_NUMBERS, _toggleLineNumbers);