Skip to content

Commit f35fc75

Browse files
committed
fix: find replace integ tests
1 parent 7956302 commit f35fc75

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/search/FindReplace.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,9 @@ define(function (require, exports, module) {
619619
// 3rd arg: prefer to avoid scrolling if result is anywhere within view, since in this case user
620620
// is in the middle of typing, not navigating explicitly; viewport jumping would be distracting.
621621
findNext(editor, false, true, state.searchStartPos);
622+
} else {
623+
// Blank or invalid query: just jump back to initial pos
624+
editor._codeMirror.setCursor(state.searchStartPos);
622625
}
623626

624627
editor.lastParsedQuery = state.parsedQuery;

test/spec/FindReplace-integ-test.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,18 @@ define(function (require, exports, module) {
305305

306306
twCommandManager.execute(Commands.CMD_FIND);
307307
// The previous search term "b" was pre-filled, so the editor was centered there already
308-
expect(myEditor.centerOnCursor.calls.count()).toEql(1);
308+
expect(myEditor.centerOnCursor.calls.count()).toEql(0);
309309

310310
enterSearchText("foo");
311311
expectHighlightedMatches(fooExpectedMatches);
312312
expectSelection(fooExpectedMatches[0]);
313313
expectMatchIndex(0, 4);
314-
expect(myEditor.centerOnCursor.calls.count()).toEql(2);
314+
expect(myEditor.centerOnCursor.calls.count()).toEql(1);
315315

316316
twCommandManager.execute(Commands.CMD_FIND_NEXT);
317317
expectSelection(fooExpectedMatches[1]);
318318
expectMatchIndex(1, 4);
319-
expect(myEditor.centerOnCursor.calls.count()).toEql(3);
319+
expect(myEditor.centerOnCursor.calls.count()).toEql(2);
320320
twCommandManager.execute(Commands.CMD_FIND_NEXT);
321321
expectSelection(fooExpectedMatches[2]);
322322
expectMatchIndex(2, 4);
@@ -329,26 +329,26 @@ define(function (require, exports, module) {
329329
twCommandManager.execute(Commands.CMD_FIND_NEXT);
330330
expectSelection(fooExpectedMatches[0]);
331331
expectMatchIndex(0, 4);
332-
expect(myEditor.centerOnCursor.calls.count()).toEql(6);
332+
expect(myEditor.centerOnCursor.calls.count()).toEql(5);
333333
});
334334

335335
it("should find all case-insensitive matches with mixed-case text", async function () {
336336
myEditor.setCursorPos(0, 0);
337337

338338
twCommandManager.execute(Commands.CMD_FIND);
339339
// The previous search term "foo" was pre-filled, so the editor was centered there already
340-
expect(myEditor.centerOnCursor.calls.count()).toEql(1);
340+
expect(myEditor.centerOnCursor.calls.count()).toEql(0);
341341

342342
enterSearchText("Foo");
343343
expectHighlightedMatches(fooExpectedMatches);
344344
expectSelection(fooExpectedMatches[0]);
345345
expectMatchIndex(0, 4);
346-
expect(myEditor.centerOnCursor.calls.count()).toEql(2);
346+
expect(myEditor.centerOnCursor.calls.count()).toEql(1);
347347

348348
twCommandManager.execute(Commands.CMD_FIND_NEXT);
349349
expectSelection(fooExpectedMatches[1]);
350350
expectMatchIndex(1, 4);
351-
expect(myEditor.centerOnCursor.calls.count()).toEql(3);
351+
expect(myEditor.centerOnCursor.calls.count()).toEql(2);
352352
twCommandManager.execute(Commands.CMD_FIND_NEXT);
353353
expectSelection(fooExpectedMatches[2]);
354354
expectMatchIndex(2, 4);
@@ -361,7 +361,7 @@ define(function (require, exports, module) {
361361
twCommandManager.execute(Commands.CMD_FIND_NEXT);
362362
expectSelection(fooExpectedMatches[0]);
363363
expectMatchIndex(0, 4);
364-
expect(myEditor.centerOnCursor.calls.count()).toEql(6);
364+
expect(myEditor.centerOnCursor.calls.count()).toEql(5);
365365
});
366366

367367
it("should find all case-sensitive matches with mixed-case text", async function () {
@@ -454,7 +454,7 @@ define(function (require, exports, module) {
454454

455455
twCommandManager.execute(Commands.CMD_FIND);
456456
// The previous search term "Foo" was pre-filled, so the editor was centered there already
457-
expect(myEditor.centerOnCursor.calls.count()).toEql(1);
457+
expect(myEditor.centerOnCursor.calls.count()).toEql(0);
458458

459459
enterSearchText("foo");
460460
pressEscape();
@@ -463,12 +463,12 @@ define(function (require, exports, module) {
463463
await waitsForSearchBarClose();
464464

465465
expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: 8}, end: {line: LINE_FIRST_REQUIRE, ch: 11}});
466-
expect(myEditor.centerOnCursor.calls.count()).toEql(2);
466+
expect(myEditor.centerOnCursor.calls.count()).toEql(1);
467467

468468
// Simple linear Find Next
469469
twCommandManager.execute(Commands.CMD_FIND_NEXT);
470470
expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: 31}, end: {line: LINE_FIRST_REQUIRE, ch: 34}});
471-
expect(myEditor.centerOnCursor.calls.count()).toEql(3);
471+
expect(myEditor.centerOnCursor.calls.count()).toEql(2);
472472
twCommandManager.execute(Commands.CMD_FIND_NEXT);
473473
expectSelection({start: {line: 6, ch: 17}, end: {line: 6, ch: 20}});
474474
twCommandManager.execute(Commands.CMD_FIND_NEXT);
@@ -565,14 +565,16 @@ define(function (require, exports, module) {
565565
expectSearchBarOpen();
566566
expect(getSearchField().val()).toEql("Foo");
567567
expectHighlightedMatches(capitalFooSelections);
568+
// not select anything by default at start
569+
twCommandManager.execute(Commands.CMD_FIND_NEXT);
568570
expectSelection(capitalFooSelections[0]);
569571
expectMatchIndex(0, 3);
570-
expect(myEditor.centerOnCursor.calls.count()).toEql(3);
572+
expect(myEditor.centerOnCursor.calls.count()).toEql(2);
571573

572574
twCommandManager.execute(Commands.CMD_FIND_NEXT);
573575
expectSelection(capitalFooSelections[1]);
574576
expectMatchIndex(1, 3);
575-
});
577+
}, 100000);
576578

577579
it("should open search bar on Find Next with no previous search", async function () {
578580
// Make sure we have no previous query
@@ -806,6 +808,10 @@ define(function (require, exports, module) {
806808
myEditor.setCursorPos(LINE_FIRST_REQUIRE, 0);
807809

808810
twCommandManager.execute(Commands.CMD_FIND);
811+
// just executing find will load the search string from history(last search string) and it will not set
812+
// selection so that the user can press escape and carry on from his cursor. the selection is set only
813+
// on interacting with the find workflow
814+
twCommandManager.execute(Commands.CMD_FIND_NEXT);
809815
expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, end: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_PAREN}});
810816

811817
twCommandManager.execute(Commands.CMD_FIND_NEXT);

0 commit comments

Comments
 (0)