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 all 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
2 changes: 1 addition & 1 deletion src/search/FindReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ define(function (require, exports, module) {

function getSearchCursor(cm, query, pos) {
// Heuristic: if the query string is all lowercase, do a case insensitive search.
return cm.getSearchCursor(query, pos, !$("#find-case-sensitive").is(".active"));
return cm.getSearchCursor(query, pos, !PreferencesManager.getViewState("caseSensitive"));
}

function _updateSearchBarFromPrefs() {
Expand Down
62 changes: 61 additions & 1 deletion test/spec/FindReplace-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ define(function (require, exports, module) {
}
expect(actualHighlights.length).toEqual(expectedDOMHighlightCount);
}
function expectFindNextSelections(selections) {
var i;
for (i = 0; i < selections.length; i++) {
expectSelection(selections[i]);
twCommandManager.execute(Commands.EDIT_FIND_NEXT);
}

// next find should wraparound
expectSelection(selections[0]);
}


function getSearchBar() {
Expand Down Expand Up @@ -407,6 +417,25 @@ define(function (require, exports, module) {
});
});

it("should Find Next after search bar closed, remembering case sensitivity state", function () {
runs(function () {
myEditor.setCursorPos(0, 0);

twCommandManager.execute(Commands.EDIT_FIND);

toggleCaseSensitive(true);
enterSearchText("Foo");
pressEscape();
expectHighlightedMatches([]);
});

waitsForSearchBarClose();

runs(function () {
expectFindNextSelections(capitalFooSelections);
});
});

it("shouldn't Find Next after search bar reopened", function () {
runs(function () {
myEditor.setCursorPos(0, 0);
Expand Down Expand Up @@ -668,6 +697,37 @@ define(function (require, exports, module) {
expectSelection(expectedSelections[0]);
});


it("should Find Next after search bar closed, remembering last used regexp", function () {
var expectedSelections = [
{start: {line: LINE_FIRST_REQUIRE + 1, ch: 8}, end: {line: LINE_FIRST_REQUIRE + 1, ch: 11}},
{start: {line: LINE_FIRST_REQUIRE + 1, ch: 31}, end: {line: LINE_FIRST_REQUIRE + 1, ch: 34}},
{start: {line: LINE_FIRST_REQUIRE + 2, ch: 8}, end: {line: LINE_FIRST_REQUIRE + 2, ch: 11}},
{start: {line: LINE_FIRST_REQUIRE + 2, ch: 31}, end: {line: LINE_FIRST_REQUIRE + 2, ch: 34}}
];

runs(function () {
myEditor.setCursorPos(0, 0);

twCommandManager.execute(Commands.EDIT_FIND);

toggleRegexp(true);
enterSearchText("Ba.");
pressEscape();
expectHighlightedMatches([]);
});

waitsForSearchBarClose();

runs(function () {
expectFindNextSelections(expectedSelections);

// explicitly clean up since we closed the search bar
twCommandManager.execute(Commands.EDIT_FIND);
toggleRegexp(false);
});
});

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

Expand Down Expand Up @@ -718,7 +778,7 @@ define(function (require, exports, module) {
expectHighlightedMatches(expectedSelections);
expectSelection(expectedSelections[0]);
});

it("shouldn't choke on invalid regexp", function () {
myEditor.setCursorPos(0, 0);

Expand Down