diff options
author | Neil <nyamatongwe@gmail.com> | 2021-07-16 09:40:45 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2021-07-16 09:40:45 +1000 |
commit | 05f4d202fa25a9b6beb23e097cc15c16c2e51f96 (patch) | |
tree | 49d74f8669543cc173d205c564864dc2d6751b25 | |
parent | 7acc601f5818a46837baff31ccc231d1cc4b1ffe (diff) | |
download | scintilla-mirror-05f4d202fa25a9b6beb23e097cc15c16c2e51f96.tar.gz |
Feature [feature-requests:#1381] Fix position returned when in 2nd segment.
-rw-r--r-- | src/Document.cxx | 2 | ||||
-rw-r--r-- | test/unit/testDocument.cxx | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index b39779c54..6194f772e 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1999,7 +1999,7 @@ ptrdiff_t SplitFindChar(const SplitView &view, size_t start, size_t length, int } const char *match2 = static_cast<const char *>(memchr(view.segment2 + start, ch, length - range1Length)); if (match2) { - return match2 - view.segment2 + view.length1; + return match2 - view.segment2; } return -1; } diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx index a48ab3fcb..97db6d9a2 100644 --- a/test/unit/testDocument.cxx +++ b/test/unit/testDocument.cxx @@ -119,6 +119,12 @@ struct DocPlus { assert(*length == static_cast<Sci::Position>(needle.length())); return document.FindText(document.Length(), 0, needle.c_str(), options, length); } + void MoveGap(Sci::Position gapNew) { + // Move gap to gapNew by inserting + document.InsertString(gapNew, "!", 1); + // Remove insertion + document.DeleteChars(gapNew, 1); + } }; void TimeTrace(std::string_view sv, const Catch::Timer &tikka) { @@ -161,6 +167,19 @@ TEST_CASE("Document") { REQUIRE(location == -1); } + SECTION("SearchInBothSegments") { + DocPlus doc("ab-ab", 0); // a b - a b + std::string finding = "ab"; + for (int gapPos = 0; gapPos <= 5; gapPos++) { + doc.MoveGap(gapPos); + Sci::Position lengthFinding = finding.length(); + Sci::Position location = doc.document.FindText(0, doc.document.Length(), finding.c_str(), FindOption::MatchCase, &lengthFinding); + REQUIRE(location == 0); + location = doc.document.FindText(2, doc.document.Length(), finding.c_str(), FindOption::MatchCase, &lengthFinding); + REQUIRE(location == 3); + } + } + SECTION("InsensitiveSearchInLatin") { DocPlus doc("abcde", 0); // a b c d e std::string finding = "B"; |