Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,42 +151,44 @@ define(function (require, exports, module) {
// in the modules since they would run in context of the unit test window,
// and would not have access to the app html/css.
brackets.test = {
PreferencesManager : PreferencesManager,
ProjectManager : ProjectManager,
CodeHintManager : CodeHintManager,
CodeInspection : CodeInspection,
CommandManager : CommandManager,
Commands : Commands,
CSSUtils : require("language/CSSUtils"),
DefaultDialogs : DefaultDialogs,
Dialogs : Dialogs,
DocumentCommandHandlers : DocumentCommandHandlers,
FileViewController : FileViewController,
DocumentManager : DocumentManager,
DOMAgent : require("LiveDevelopment/Agents/DOMAgent"),
DragAndDrop : DragAndDrop,
EditorManager : EditorManager,
Commands : Commands,
WorkingSetView : WorkingSetView,
PerfUtils : PerfUtils,
JSUtils : JSUtils,
CommandManager : CommandManager,
ExtensionLoader : ExtensionLoader,
ExtensionUtils : ExtensionUtils,
FileFilters : require("search/FileFilters"),
FileSyncManager : FileSyncManager,
FileSystem : FileSystem,
Menus : Menus,
FileViewController : FileViewController,
FindInFiles : require("search/FindInFiles"),
HTMLInstrumentation : require("language/HTMLInstrumentation"),
Inspector : require("LiveDevelopment/Inspector/Inspector"),
InstallExtensionDialog : require("extensibility/InstallExtensionDialog"),
JSUtils : JSUtils,
KeyBindingManager : KeyBindingManager,
CodeHintManager : CodeHintManager,
Dialogs : Dialogs,
DefaultDialogs : DefaultDialogs,
DragAndDrop : DragAndDrop,
CodeInspection : CodeInspection,
CSSUtils : require("language/CSSUtils"),
LanguageManager : LanguageManager,
LiveDevelopment : require("LiveDevelopment/LiveDevelopment"),
LiveDevServerManager : require("LiveDevelopment/LiveDevServerManager"),
DOMAgent : require("LiveDevelopment/Agents/DOMAgent"),
Inspector : require("LiveDevelopment/Inspector/Inspector"),
Menus : Menus,
MultiRangeInlineEditor : require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor,
NativeApp : NativeApp,
ExtensionLoader : ExtensionLoader,
ExtensionUtils : ExtensionUtils,
UpdateNotification : require("utils/UpdateNotification"),
InstallExtensionDialog : require("extensibility/InstallExtensionDialog"),
PerfUtils : PerfUtils,
PreferencesManager : PreferencesManager,
ProjectManager : ProjectManager,
RemoteAgent : require("LiveDevelopment/Agents/RemoteAgent"),
HTMLInstrumentation : require("language/HTMLInstrumentation"),
MultiRangeInlineEditor : require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor,
LanguageManager : LanguageManager,
FindInFiles : require("search/FindInFiles"),
FileFilters : require("search/FileFilters"),
ScrollTrackMarkers : require("search/ScrollTrackMarkers"),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that adding ScrollTrackMarkers was the only logical change here -- the rest was ordering alphabetically to make it easier to see what's in list.

UpdateNotification : require("utils/UpdateNotification"),
WorkingSetView : WorkingSetView,

doneLoading : false
};

Expand Down
18 changes: 13 additions & 5 deletions src/search/ScrollTrackMarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,17 @@ define(function (require, exports, module) {
marks = marks.concat(posArray);
_renderMarks(posArray);
}


exports.clear = clear;
exports.setVisible = setVisible;
exports.addTickmarks = addTickmarks;

// Private helper for unit tests
function _getMarks() {
return marks;
}


// For unit tests
exports._getMarks = _getMarks;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: shouldn't we call it _getTickmarks since we have another one called addTickmarks below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


exports.clear = clear;
exports.setVisible = setVisible;
exports.addTickmarks = addTickmarks;
});
102 changes: 100 additions & 2 deletions test/spec/FindReplace-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ define(function (require, exports, module) {
'use strict';

var Commands = require("command/Commands"),
FindReplace = require("search/FindReplace"),
KeyEvent = require("utils/KeyEvent"),
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
FindReplace = require("search/FindReplace");
SpecRunnerUtils = require("spec/SpecRunnerUtils");

var defaultContent = "/* Test comment */\n" +
"define(function (require, exports, module) {\n" +
Expand Down Expand Up @@ -552,6 +552,20 @@ define(function (require, exports, module) {
expectSelection(capitalFooSelections[0]);
});

it("should have a scroll track marker for every match", function () {
twCommandManager.execute(Commands.EDIT_FIND);

enterSearchText("foo");
expectHighlightedMatches(fooExpectedMatches);

var marks = testWindow.brackets.test.ScrollTrackMarkers._getMarks();
expect(marks.length).toEqual(fooExpectedMatches.length);

marks.forEach(function (mark, index) {
expect(mark.line).toEqual(fooExpectedMatches[index].start.line);
});
});

it("toggling case-sensitive option should update results immediately", function () {
myEditor.setCursorPos(0, 0);

Expand Down Expand Up @@ -787,6 +801,26 @@ define(function (require, exports, module) {
expectSelection(barExpectedMatches[0]);
});

it("should use empty initial query for single cursor selection", function () {
myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START});
twCommandManager.execute(Commands.EDIT_FIND);
expect(getSearchField().val()).toEqual("");
});

it("should use empty initial query for multiple cursor selection", function () {
myEditor.setSelections([{start: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, end: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, primary: true},
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}}]);
twCommandManager.execute(Commands.EDIT_FIND);
expect(getSearchField().val()).toEqual("");
});

it("should get single selection as initial query", function () {
myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START},
{line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_PAREN});
twCommandManager.execute(Commands.EDIT_FIND);
expect(getSearchField().val()).toEqual("require");
});

it("should get primary selection as initial query", function () {
myEditor.setSelections([{start: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, end: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_PAREN}, primary: true},
{start: {line: 1, ch: 0}, end: {line: 1, ch: 1}}]);
Expand Down Expand Up @@ -1087,6 +1121,36 @@ define(function (require, exports, module) {
expect(/bar/i.test(myEditor.getSelectedText())).toBe(true);
});
});

it("should find and skip then replace string", function () {
runs(function () {
twCommandManager.execute(Commands.EDIT_REPLACE);
enterSearchText("foo");
enterReplaceText("bar");

expectSelection(fooExpectedMatches[0]);
expect(/foo/i.test(myEditor.getSelectedText())).toBe(true);

// Skip first
expect(tw$("#find-next").is(":enabled")).toBe(true);
tw$("#find-next").click();

expectSelection(fooExpectedMatches[1]);
expect(/foo/i.test(myEditor.getSelectedText())).toBe(true);

// Replace second
expect(tw$("#replace-yes").is(":enabled")).toBe(true);
tw$("#replace-yes").click();

expectSelection(fooExpectedMatches[2]);

myEditor.setSelection(fooExpectedMatches[0].start, fooExpectedMatches[0].end);
expect(/foo/i.test(myEditor.getSelectedText())).toBe(true);

myEditor.setSelection(fooExpectedMatches[1].start, fooExpectedMatches[1].end);
expect(/bar/i.test(myEditor.getSelectedText())).toBe(true);
});
});

it("should use replace keyboard shortcut for single Replace while search bar open", function () {
runs(function () {
Expand Down Expand Up @@ -1267,6 +1331,40 @@ define(function (require, exports, module) {


describe("Search -> Replace All", function () {
it("should find and replace all", function () {
runs(function () {
var searchText = "require",
replaceText = "brackets.getModule";
twCommandManager.execute(Commands.EDIT_REPLACE);
enterSearchText(searchText);
enterReplaceText(replaceText);

expectSelection({start: {line: 1, ch: 17}, end: {line: 1, ch: 17 + searchText.length}});
expect(myEditor.getSelectedText()).toBe(searchText);

expect(tw$("#replace-all").is(":enabled")).toBe(true);
tw$("#replace-all").click();
tw$(".replace-checked").click();

myEditor.setSelection({line: 1, ch: 17}, {line: 1, ch: 17 + replaceText.length});
expect(myEditor.getSelectedText()).toBe(replaceText);

// Note: LINE_FIRST_REQUIRE and CH_REQUIRE_START refer to first call to "require",
// but not first instance of "require" in text
myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START},
{line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START + replaceText.length});
expect(myEditor.getSelectedText()).toBe(replaceText);

myEditor.setSelection({line: LINE_FIRST_REQUIRE + 1, ch: CH_REQUIRE_START},
{line: LINE_FIRST_REQUIRE + 1, ch: CH_REQUIRE_START + replaceText.length});
expect(myEditor.getSelectedText()).toBe(replaceText);

myEditor.setSelection({line: LINE_FIRST_REQUIRE + 2, ch: CH_REQUIRE_START},
{line: LINE_FIRST_REQUIRE + 2, ch: CH_REQUIRE_START + replaceText.length});
expect(myEditor.getSelectedText()).toBe(replaceText);
});
});

it("should find all regexps and replace them with $n", function () {
runs(function () {
twCommandManager.execute(Commands.EDIT_REPLACE);
Expand Down