Permalink
Browse files

Merge pull request #775 from adobe/glenn/issue-768

Factor out a generic MultiRangeInlineEditor from CSSInlineEditor
  • Loading branch information...
2 parents 4ce734f + a84e133 commit ffad3db87809795c058545c0cfc98895fd75af4a @peterflynn peterflynn committed May 1, 2012
View
@@ -208,8 +208,8 @@ define(function (require, exports, module) {
// Navigate
{"Ctrl-Shift-O": Commands.NAVIGATE_QUICK_OPEN},
{"Ctrl-E": Commands.SHOW_INLINE_EDITOR},
- {"Alt-Up": Commands.PREVIOUS_CSS_RULE},
- {"Alt-Down": Commands.NEXT_CSS_RULE},
+ {"Alt-Up": Commands.QUICK_EDIT_PREV_MATCH},
+ {"Alt-Down": Commands.QUICK_EDIT_NEXT_MATCH},
// DEBUG
{"F5": Commands.DEBUG_REFRESH_WINDOW, "platform": "win"},
@@ -63,10 +63,10 @@ define(function (require, exports, module) {
exports.VIEW_HIDE_SIDEBAR = "view.hideSidebar";
// Navigate
- exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen";
- exports.SHOW_INLINE_EDITOR = "navigate.showInlineEditor";
- exports.NEXT_CSS_RULE = "navigate.nextCssRule";
- exports.PREVIOUS_CSS_RULE = "navigate.previousCssRule";
+ exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen";
+ exports.SHOW_INLINE_EDITOR = "navigate.showInlineEditor";
+ exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch";
+ exports.QUICK_EDIT_PREV_MATCH = "navigate.previousMatch";
exports.DEBUG_REFRESH_WINDOW = "debug.refreshWindow"; // string must MATCH string in native code (brackets_extensions)
exports.DEBUG_SHOW_DEVELOPER_TOOLS = "debug.showDeveloperTools";
@@ -68,8 +68,8 @@ define(function (require, exports, module) {
// Navigate
"menu-navigate-quick-open": Commands.NAVIGATE_QUICK_OPEN,
"menu-navigate-quick-edit": Commands.SHOW_INLINE_EDITOR,
- "menu-navigate-next-css-rule": Commands.NEXT_CSS_RULE,
- "menu-navigate-previous-css-rule": Commands.PREVIOUS_CSS_RULE,
+ "menu-navigate-next-match": Commands.QUICK_EDIT_NEXT_MATCH,
+ "menu-navigate-previous-match": Commands.QUICK_EDIT_PREV_MATCH,
// Debug
"menu-debug-refresh-window": Commands.DEBUG_REFRESH_WINDOW,
Oops, something went wrong.
@@ -22,6 +22,7 @@
*/
+// FUTURE: Merge part (or all) of this class with MultiRangeInlineEditor
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, CodeMirror, window */
Oops, something went wrong.
View
@@ -149,8 +149,8 @@
<li><a href="#" id="menu-navigate-go-to-symbol">Go to Symbol</a></li>
<li><hr class="divider"></li>
<li><a href="#" id="menu-navigate-quick-edit">Quick Edit</a></li>
- <li><a href="#" id="menu-navigate-previous-css-rule">Previous CSS Rule</a></li>
- <li><a href="#" id="menu-navigate-next-css-rule">Next CSS Rule</a></li>
+ <li><a href="#" id="menu-navigate-previous-match">Previous Match</a></li>
+ <li><a href="#" id="menu-navigate-next-match">Next Match</a></li>
</ul>
</li>
@@ -280,7 +280,7 @@ define(function (require, exports, module) {
function _addSelectorsToResults(resultSelectors, selectorsToAdd, sourceDoc, lineOffset) {
selectorsToAdd.forEach(function (selectorInfo) {
resultSelectors.push({
- selector: selectorInfo.selector,
+ name: selectorInfo.selector,
document: sourceDoc,
lineStart: selectorInfo.ruleStartLine + lineOffset,
lineEnd: selectorInfo.declListEndLine + lineOffset
View
@@ -49,7 +49,7 @@ define(function (require, exports, module) {
require("spec/CodeHintUtils-test.js");
require("spec/CSSUtils-test.js");
require("spec/InlineEditorProviders-test.js");
- require("spec/CSSInlineEditor-test.js");
+ require("spec/MultiRangeInlineEditor-test.js");
require("spec/LiveDevelopment-test.js");
require("spec/ViewUtils-test.js");
@@ -28,16 +28,16 @@
define(function (require, exports, module) {
'use strict';
- var CSSInlineEditor = require("editor/CSSInlineEditor").CSSInlineEditor,
- InlineTextEditor = require("editor/InlineTextEditor").InlineTextEditor,
- InlineWidget = require("editor/InlineWidget").InlineWidget,
- Editor = require("editor/Editor").Editor,
- EditorManager = require("editor/EditorManager"),
- SpecRunnerUtils = require("./SpecRunnerUtils.js");
+ var MultiRangeInlineEditor = require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor,
+ InlineTextEditor = require("editor/InlineTextEditor").InlineTextEditor,
+ InlineWidget = require("editor/InlineWidget").InlineWidget,
+ Editor = require("editor/Editor").Editor,
+ EditorManager = require("editor/EditorManager"),
+ SpecRunnerUtils = require("./SpecRunnerUtils.js");
- describe("CSSInlineEditor", function () {
+ describe("MultiRangeInlineEditor", function () {
- var cssInlineEditor,
+ var inlineEditor,
$editorHolder,
hostEditor;
@@ -57,205 +57,205 @@ define(function (require, exports, module) {
});
it("should initialize to a default state", function () {
- cssInlineEditor = new CSSInlineEditor([]);
+ inlineEditor = new MultiRangeInlineEditor([]);
- expect(cssInlineEditor instanceof InlineTextEditor).toBe(true);
- expect(cssInlineEditor instanceof InlineWidget).toBe(true);
- expect(cssInlineEditor.editors.length).toBe(0);
- expect(cssInlineEditor.htmlContent instanceof HTMLElement).toBe(true);
- expect(cssInlineEditor.height).toBe(0);
- expect(cssInlineEditor.id).toBeNull();
- expect(cssInlineEditor.hostEditor).toBeNull();
+ expect(inlineEditor instanceof InlineTextEditor).toBe(true);
+ expect(inlineEditor instanceof InlineWidget).toBe(true);
+ expect(inlineEditor.editors.length).toBe(0);
+ expect(inlineEditor.htmlContent instanceof HTMLElement).toBe(true);
+ expect(inlineEditor.height).toBe(0);
+ expect(inlineEditor.id).toBeNull();
+ expect(inlineEditor.hostEditor).toBeNull();
});
it("should load a single rule and initialize htmlContent and editor", function () {
var inlineDoc = SpecRunnerUtils.createMockDocument("inlineDoc\nstartLine\nendLine\n");
- var mockRule = {
+ var mockRange = {
document: inlineDoc,
lineStart: 1,
lineEnd: 2
};
- cssInlineEditor = new CSSInlineEditor([mockRule]);
- cssInlineEditor.load(hostEditor);
+ inlineEditor = new MultiRangeInlineEditor([mockRange]);
+ inlineEditor.load(hostEditor);
- expect(cssInlineEditor.editors.length).toBe(1);
- expect(cssInlineEditor.editors[0].document).toBe(inlineDoc);
+ expect(inlineEditor.editors.length).toBe(1);
+ expect(inlineEditor.editors[0].document).toBe(inlineDoc);
});
it("should contain a rule list widget displaying info for each rule", function () {
var inlineDoc = SpecRunnerUtils.createMockDocument("div{}\n.foo{}\n");
- var mockRules = [
+ var mockRanges = [
{
document: inlineDoc,
- selector: "div",
+ name: "div",
lineStart: 0,
lineEnd: 0
},
{
document: inlineDoc,
- selector: ".foo",
+ name: ".foo",
lineStart: 1,
lineEnd: 1
}
];
- cssInlineEditor = new CSSInlineEditor(mockRules);
- cssInlineEditor.load(hostEditor);
+ inlineEditor = new MultiRangeInlineEditor(mockRanges);
+ inlineEditor.load(hostEditor);
- var $ruleListItems = $(cssInlineEditor.htmlContent).find("li");
+ var $ruleListItems = $(inlineEditor.htmlContent).find("li");
expect($($ruleListItems.get(0)).text()).toBe("div _unitTestDummyFile_.js : 1");
expect($($ruleListItems.get(1)).text()).toBe(".foo _unitTestDummyFile_.js : 2");
});
it("should change selection to the next rule", function () {
var inlineDoc = SpecRunnerUtils.createMockDocument("div{}\n.foo{}\n");
- var mockRules = [
+ var mockRanges = [
{
document: inlineDoc,
- selector: "div",
+ name: "div",
lineStart: 0,
lineEnd: 0
},
{
document: inlineDoc,
- selector: ".foo",
+ name: ".foo",
lineStart: 1,
lineEnd: 1
}
];
- cssInlineEditor = new CSSInlineEditor(mockRules);
- cssInlineEditor.load(hostEditor);
- cssInlineEditor.nextRule();
+ inlineEditor = new MultiRangeInlineEditor(mockRanges);
+ inlineEditor.load(hostEditor);
+ inlineEditor._selectNextRange();
- var $selection = $(cssInlineEditor.htmlContent).find(".selection");
- var $ruleListItems = $(cssInlineEditor.htmlContent).find("li");
+ var $selection = $(inlineEditor.htmlContent).find(".selection");
+ var $ruleListItems = $(inlineEditor.htmlContent).find("li");
expect($selection.position().top).toBe($($ruleListItems.get(0)).position().top);
});
it("should change selection to the previous rule", function () {
var inlineDoc = SpecRunnerUtils.createMockDocument("div{}\n.foo{}\n");
- var mockRules = [
+ var mockRanges = [
{
document: inlineDoc,
- selector: "div",
+ name: "div",
lineStart: 0,
lineEnd: 0
},
{
document: inlineDoc,
- selector: ".foo",
+ name: ".foo",
lineStart: 1,
lineEnd: 1
}
];
- cssInlineEditor = new CSSInlineEditor(mockRules);
- cssInlineEditor.load(hostEditor);
+ inlineEditor = new MultiRangeInlineEditor(mockRanges);
+ inlineEditor.load(hostEditor);
// select .foo
- cssInlineEditor.setSelectedRule(1);
+ inlineEditor.setSelectedIndex(1);
// verify selection moves
- var $selection = $(cssInlineEditor.htmlContent).find(".selection");
- var $ruleListItems = $(cssInlineEditor.htmlContent).find("li");
+ var $selection = $(inlineEditor.htmlContent).find(".selection");
+ var $ruleListItems = $(inlineEditor.htmlContent).find("li");
expect($selection.position().top).toBe($($ruleListItems.get(1)).position().top);
// select div
- cssInlineEditor.previousRule();
+ inlineEditor._selectPreviousRange();
// verify selection moves again
expect($selection.position().top).toBe($($ruleListItems.get(0)).position().top);
});
- function expectResultItemToEqual(resultItem, mockRule) {
- expect(resultItem.selector).toBe(mockRule.selector);
- expect(resultItem.textRange.startLine).toBe(mockRule.lineStart);
- expect(resultItem.textRange.endLine).toBe(mockRule.lineEnd);
+ function expectResultItemToEqual(resultItem, mockRange) {
+ expect(resultItem.name).toBe(mockRange.name);
+ expect(resultItem.textRange.startLine).toBe(mockRange.lineStart);
+ expect(resultItem.textRange.endLine).toBe(mockRange.lineEnd);
}
it("should retreive all rules", function () {
var inlineDoc = SpecRunnerUtils.createMockDocument("div{}\n.foo{}\n");
- var mockRules = [
+ var mockRanges = [
{
document: inlineDoc,
- selector: "div",
+ name: "div",
lineStart: 0,
lineEnd: 0
},
{
document: inlineDoc,
- selector: ".foo",
+ name: ".foo",
lineStart: 1,
lineEnd: 1
}
];
- cssInlineEditor = new CSSInlineEditor(mockRules);
+ inlineEditor = new MultiRangeInlineEditor(mockRanges);
- expect(cssInlineEditor.getRules().length).toEqual(mockRules.length);
- expectResultItemToEqual(cssInlineEditor.getRules()[0], mockRules[0]);
- expectResultItemToEqual(cssInlineEditor.getRules()[1], mockRules[1]);
+ expect(inlineEditor._getRanges().length).toEqual(mockRanges.length);
+ expectResultItemToEqual(inlineEditor._getRanges()[0], mockRanges[0]);
+ expectResultItemToEqual(inlineEditor._getRanges()[1], mockRanges[1]);
});
it("should retreive the selected rule", function () {
var inlineDoc = SpecRunnerUtils.createMockDocument("div{}\n.foo{}\n");
- var mockRules = [
+ var mockRanges = [
{
document: inlineDoc,
- selector: "div",
+ name: "div",
lineStart: 0,
lineEnd: 0
},
{
document: inlineDoc,
- selector: ".foo",
+ name: ".foo",
lineStart: 1,
lineEnd: 1
}
];
- cssInlineEditor = new CSSInlineEditor(mockRules);
- cssInlineEditor.load(hostEditor);
+ inlineEditor = new MultiRangeInlineEditor(mockRanges);
+ inlineEditor.load(hostEditor);
// "div" rule should be selected by default
- expectResultItemToEqual(cssInlineEditor.getSelectedRule(), mockRules[0]);
+ expectResultItemToEqual(inlineEditor._getSelectedRange(), mockRanges[0]);
// select ".foo" rule - should be next
- cssInlineEditor.nextRule();
- expectResultItemToEqual(cssInlineEditor.getSelectedRule(), mockRules[1]);
+ inlineEditor._selectNextRange();
+ expectResultItemToEqual(inlineEditor._getSelectedRange(), mockRanges[1]);
});
it("should close and return to the host editor", function () {
var inlineDoc = SpecRunnerUtils.createMockDocument("div{}\n.foo{}\n");
- var mockRules = [
+ var mockRanges = [
{
document: inlineDoc,
- selector: "div",
+ name: "div",
lineStart: 0,
lineEnd: 0
}
];
- cssInlineEditor = new CSSInlineEditor(mockRules);
- cssInlineEditor.load(hostEditor);
+ inlineEditor = new MultiRangeInlineEditor(mockRanges);
+ inlineEditor.load(hostEditor);
// add widget directly, bypass _openInlineWidget
- hostEditor.addInlineWidget({line: 0, ch: 0}, cssInlineEditor);
+ hostEditor.addInlineWidget({line: 0, ch: 0}, inlineEditor);
// verify it was added
expect(hostEditor.hasFocus()).toBe(false);
expect(hostEditor.getInlineWidgets().length).toBe(1);
// close the inline editor directly, should call EditorManager and removeInlineWidget
- cssInlineEditor.close();
+ inlineEditor.close();
// verify no editors
expect(hostEditor.getInlineWidgets().length).toBe(0);

0 comments on commit ffad3db

Please sign in to comment.