From 2529832286df90b8c37da89e81ba2a431d1cc68e Mon Sep 17 00:00:00 2001 From: comzyh Date: Mon, 2 Nov 2020 02:10:35 +0800 Subject: [PATCH 1/3] Accumulate the width of glyphs to calculate the coordinate of matched words. fix #8121 --- src/buffer/out/textBuffer.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/buffer/out/textBuffer.cpp b/src/buffer/out/textBuffer.cpp index 2c24936c2bd..a9c3610960e 100644 --- a/src/buffer/out/textBuffer.cpp +++ b/src/buffer/out/textBuffer.cpp @@ -8,6 +8,7 @@ #include "../types/inc/utils.hpp" #include "../types/inc/convert.hpp" +#include "../../types/inc/GlyphWidth.hpp" #pragma hdrstop @@ -2428,9 +2429,19 @@ PointTree TextBuffer::GetPatterns(const size_t firstRow, const size_t lastRow) c // when we find a match, the prefix is text that is between this // match and the previous match, so we use the size of the prefix // along with the size of the match to determine the locations - const auto prefixSize = i->prefix().str().size(); + size_t prefixSize = 0; + + for (const auto chr : i->prefix().str()) + { + prefixSize += IsGlyphFullWidth(chr) ? 2 : 1; + } const auto start = lenUpToThis + prefixSize; - const auto end = start + i->str().size(); + size_t matchSize = 0; + for (const auto chr : i->str()) + { + matchSize += IsGlyphFullWidth(chr) ? 2 : 1; + } + const auto end = start + matchSize; lenUpToThis = end; const til::point startCoord{ gsl::narrow(start % rowSize), gsl::narrow(start / rowSize) }; From 085507936f96e1912dd868ff6099da17e1b8703f Mon Sep 17 00:00:00 2001 From: comzyh Date: Mon, 2 Nov 2020 03:02:28 +0800 Subject: [PATCH 2/3] code format --- src/buffer/out/textBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/buffer/out/textBuffer.cpp b/src/buffer/out/textBuffer.cpp index a9c3610960e..8cf40e5b4ac 100644 --- a/src/buffer/out/textBuffer.cpp +++ b/src/buffer/out/textBuffer.cpp @@ -2430,7 +2430,7 @@ PointTree TextBuffer::GetPatterns(const size_t firstRow, const size_t lastRow) c // match and the previous match, so we use the size of the prefix // along with the size of the match to determine the locations size_t prefixSize = 0; - + for (const auto chr : i->prefix().str()) { prefixSize += IsGlyphFullWidth(chr) ? 2 : 1; From 2ec81af65873c5e4ca5d06d8c1ee2d31774b9a9a Mon Sep 17 00:00:00 2001 From: comzyh Date: Mon, 2 Nov 2020 21:30:57 +0800 Subject: [PATCH 3/3] fix spelling --- src/buffer/out/textBuffer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/buffer/out/textBuffer.cpp b/src/buffer/out/textBuffer.cpp index 8cf40e5b4ac..24ef10da53c 100644 --- a/src/buffer/out/textBuffer.cpp +++ b/src/buffer/out/textBuffer.cpp @@ -2431,15 +2431,15 @@ PointTree TextBuffer::GetPatterns(const size_t firstRow, const size_t lastRow) c // along with the size of the match to determine the locations size_t prefixSize = 0; - for (const auto chr : i->prefix().str()) + for (const auto ch : i->prefix().str()) { - prefixSize += IsGlyphFullWidth(chr) ? 2 : 1; + prefixSize += IsGlyphFullWidth(ch) ? 2 : 1; } const auto start = lenUpToThis + prefixSize; size_t matchSize = 0; - for (const auto chr : i->str()) + for (const auto ch : i->str()) { - matchSize += IsGlyphFullWidth(chr) ? 2 : 1; + matchSize += IsGlyphFullWidth(ch) ? 2 : 1; } const auto end = start + matchSize; lenUpToThis = end;