diff --git a/src/command/Commands.js b/src/command/Commands.js index 6f35a338b..145d2b7c8 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -73,7 +73,7 @@ define(function (require, exports, module) { exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen"; exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition"; exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine"; - exports.SHOW_INLINE_EDITOR = "navigate.showInlineEditor"; + exports.TOGGLE_QUICK_EDIT = "navigate.togleQuickEdit"; exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch"; exports.QUICK_EDIT_PREV_MATCH = "navigate.previousMatch"; diff --git a/src/command/Menus.js b/src/command/Menus.js index 294c507d3..74ba1fa1f 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -802,7 +802,7 @@ define(function (require, exports, module) { menu.addMenuItem(Commands.NAVIGATE_GOTO_DEFINITION, "Ctrl-T"); menu.addMenuDivider(); - menu.addMenuItem(Commands.SHOW_INLINE_EDITOR, "Ctrl-E"); + menu.addMenuItem(Commands.TOGGLE_QUICK_EDIT, "Ctrl-E"); menu.addMenuItem(Commands.QUICK_EDIT_PREV_MATCH, {key: "Alt-Up", displayKey: "Alt-\u2191"}); menu.addMenuItem(Commands.QUICK_EDIT_NEXT_MATCH, {key: "Alt-Down", displayKey: "Alt-\u2193"}); @@ -832,7 +832,7 @@ define(function (require, exports, module) { var project_cmenu = registerContextMenu(ContextMenuIds.PROJECT_MENU); var editor_cmenu = registerContextMenu(ContextMenuIds.EDITOR_MENU); - editor_cmenu.addMenuItem(Commands.SHOW_INLINE_EDITOR); + editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT); editor_cmenu.addMenuItem(Commands.EDIT_SELECT_ALL); /** diff --git a/src/editor/EditorManager.js b/src/editor/EditorManager.js index eefbbda36..fad857bc8 100644 --- a/src/editor/EditorManager.js +++ b/src/editor/EditorManager.js @@ -501,15 +501,20 @@ define(function (require, exports, module) { } /** - * Show Inline Editor command handler + * Toggle Quick Edit command handler + * @return {!Promise} A promise resolved with true if an inline editor + * is opened or false when closed. The promise is rejected if there + * is no current editor or an inline editor is not created. */ - function _showInlineEditor() { + function _toggleQuickEdit() { + var result = new $.Deferred(); + if (_currentEditor) { var inlineWidget = null, - result = getFocusedInlineWidget(); + focusedWidgetResult = getFocusedInlineWidget(); - if (result) { - inlineWidget = result.widget; + if (focusedWidgetResult) { + inlineWidget = focusedWidgetResult.widget; } if (inlineWidget) { @@ -519,18 +524,24 @@ define(function (require, exports, module) { PerfUtils.addMeasurement(PerfUtils.INLINE_EDITOR_CLOSE); // return a resolved promise to CommandManager - return new $.Deferred().resolve().promise(); + result.resolve(false); } else { // main editor has focus, so create an inline editor - return _openInlineWidget(_currentEditor); + _openInlineWidget(_currentEditor).done(function () { + result.resolve(true); + }).fail(function () { + result.reject(); + }); } + } else { + // Can not open an inline editor without a host editor + result.reject(); } - // Can not open an inline editor without a host editor - return new $.Deferred().reject().promise(); + return result.promise(); } - CommandManager.register(Strings.CMD_SHOW_INLINE_EDITOR, Commands.SHOW_INLINE_EDITOR, _showInlineEditor); + CommandManager.register(Strings.CMD_TOGGLE_QUICK_EDIT, Commands.TOGGLE_QUICK_EDIT, _toggleQuickEdit); // Initialize: register listeners $(DocumentManager).on("currentDocumentChange", _onCurrentDocumentChange); diff --git a/src/extensions/default/JavaScriptQuickEdit/unittests.js b/src/extensions/default/JavaScriptQuickEdit/unittests.js index 418fee884..51bd0ad75 100644 --- a/src/extensions/default/JavaScriptQuickEdit/unittests.js +++ b/src/extensions/default/JavaScriptQuickEdit/unittests.js @@ -111,10 +111,10 @@ define(function (require, exports, module) { if (openOffset !== undefined) { runs(function () { // open inline editor at specified offset index - waitsForDone(SpecRunnerUtils.openInlineEditorAtOffset( + waitsForDone(SpecRunnerUtils.toggleQuickEditAtOffset( EditorManager.getCurrentFullEditor(), spec.infos[openFile].offsets[openOffset] - ), "openInlineEditorAtOffset"); + ), "toggleQuickEditAtOffset"); }); } }; diff --git a/src/strings.js b/src/strings.js index bd937c9c1..d09d48126 100644 --- a/src/strings.js +++ b/src/strings.js @@ -137,7 +137,7 @@ define(function (require, exports, module) { exports.CMD_QUICK_OPEN = "Quick Open"; exports.CMD_GOTO_LINE = "Go to Line"; exports.CMD_GOTO_DEFINITION = "Go to Definition"; - exports.CMD_SHOW_INLINE_EDITOR = "Quick Edit"; + exports.CMD_TOGGLE_QUICK_EDIT = "Quick Edit"; exports.CMD_QUICK_EDIT_PREV_MATCH = "Previous Match"; exports.CMD_QUICK_EDIT_NEXT_MATCH = "Next Match"; exports.CMD_NEXT_DOC = "Next Document"; diff --git a/test/spec/Document-test.js b/test/spec/Document-test.js index 604a25dfa..d324989d2 100644 --- a/test/spec/Document-test.js +++ b/test/spec/Document-test.js @@ -80,7 +80,7 @@ define(function (require, exports, module) { }); runs(function () { // Open inline editor onto test.css's ".testClass" rule - promise = SpecRunnerUtils.openInlineEditorAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 4}); + promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 4}); waitsForDone(promise, "Open inline editor"); }); runs(function () { diff --git a/test/spec/InlineEditorProviders-test.js b/test/spec/InlineEditorProviders-test.js index be35816e8..ef7edfceb 100644 --- a/test/spec/InlineEditorProviders-test.js +++ b/test/spec/InlineEditorProviders-test.js @@ -134,13 +134,13 @@ define(function (require, exports, module) { var editor = EditorManager.getCurrentFullEditor(); // open inline editor at specified offset index - var inlineEditorResult = SpecRunnerUtils.openInlineEditorAtOffset( + var inlineEditorResult = SpecRunnerUtils.toggleQuickEditAtOffset( editor, spec.infos[openFile].offsets[openOffset] ); - inlineEditorResult.done(function () { - inlineOpened = true; + inlineEditorResult.done(function (isOpened) { + inlineOpened = isOpened; }).fail(function () { inlineOpened = false; }); diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index 927cf374c..d4ef02c2d 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -436,10 +436,10 @@ define(function (require, exports, module) { * @return {$.Promise} a promise that will be resolved when an inline * editor is created or rejected when no inline editors are available. */ - function openInlineEditorAtOffset(editor, offset) { + function toggleQuickEditAtOffset(editor, offset) { editor.setCursorPos(offset.line, offset.ch); - return testWindow.executeCommand(Commands.SHOW_INLINE_EDITOR); + return testWindow.executeCommand(Commands.TOGGLE_QUICK_EDIT); } /** @@ -474,7 +474,7 @@ define(function (require, exports, module) { exports.clickDialogButton = clickDialogButton; exports.loadProjectInTestWindow = loadProjectInTestWindow; exports.openProjectFiles = openProjectFiles; - exports.openInlineEditorAtOffset = openInlineEditorAtOffset; + exports.toggleQuickEditAtOffset = toggleQuickEditAtOffset; exports.saveFilesWithOffsets = saveFilesWithOffsets; exports.saveFilesWithoutOffsets = saveFilesWithoutOffsets; exports.saveFileWithoutOffsets = saveFileWithoutOffsets;