diff --git a/src/vs/editor/common/model/textModelSearch.ts b/src/vs/editor/common/model/textModelSearch.ts index 1ac1ea755ad402e761ef2cf04d932d8bd19efb29..74406abc45d44545544e0bdd65e5beb8a4d89b41 100644 --- a/src/vs/editor/common/model/textModelSearch.ts +++ b/src/vs/editor/common/model/textModelSearch.ts @@ -46,7 +46,7 @@ export class SearchParams { } const nextChCode = searchString.charCodeAt(i); - if (nextChCode === CharCode.n || nextChCode === CharCode.r) { + if (nextChCode === CharCode.n || nextChCode === CharCode.r || nextChCode === CharCode.W) { return true; } } diff --git a/src/vs/editor/test/common/model/textModelSearch.test.ts b/src/vs/editor/test/common/model/textModelSearch.test.ts index 175c90aac7fe9ba91a3b5557b9338601733fd777..50a260bc8375e4b2e8ecce69aa32b95da27969f1 100644 --- a/src/vs/editor/test/common/model/textModelSearch.test.ts +++ b/src/vs/editor/test/common/model/textModelSearch.test.ts @@ -633,4 +633,93 @@ suite('TextModelSearch', () => { assertParseSearchResult('foo\\r', true, false, null, new SearchData(/foo\r/gim, null, null)); assertParseSearchResult('foo\\\\r', true, false, null, new SearchData(/foo\\r/gi, null, null)); }); + + test('issue #53415. \W should match line break.', () => { + assertFindMatches( + [ + 'text', + '180702-', + '180703-180704' + ].join('\n'), + '\\d{6}-\\W', true, false, null, + [ + [2, 1, 3, 1] + ] + ); + + assertFindMatches( + [ + 'Just some text', + '', + 'Just' + ].join('\n'), + '\\W', true, false, null, + [ + [1, 5, 1, 6], + [1, 10, 1, 11], + [1, 15, 2, 1], + [2, 1, 3, 1] + ] + ); + + // Line break doesn't affect the result as we always use \n as line break when doing search + assertFindMatches( + [ + 'Just some text', + '', + 'Just' + ].join('\r\n'), + '\\W', true, false, null, + [ + [1, 5, 1, 6], + [1, 10, 1, 11], + [1, 15, 2, 1], + [2, 1, 3, 1] + ] + ); + + assertFindMatches( + [ + 'Just some text', + '\tJust', + 'Just' + ].join('\n'), + '\\W', true, false, null, + [ + [1, 5, 1, 6], + [1, 10, 1, 11], + [1, 15, 2, 1], + [2, 1, 2, 2], + [2, 6, 3, 1], + ] + ); + + // line break is seen as one non-word character + assertFindMatches( + [ + 'Just some text', + '', + 'Just' + ].join('\n'), + '\\W{2}', true, false, null, + [ + [1, 5, 1, 7], + [1, 16, 3, 1] + ] + ); + + // even if it's \r\n + assertFindMatches( + [ + 'Just some text', + '', + 'Just' + ].join('\r\n'), + '\\W{2}', true, false, null, + [ + [1, 5, 1, 7], + [1, 16, 3, 1] + ] + ); + }); });