提交 54ca5101 编写于 作者: A Alex Dima

Fixes #32522: Set multiline flag on regex if replacing more than 1k matches

上级 3b76085a
......@@ -409,6 +409,18 @@ export class FindModelBoundToEditorModel {
return;
}
let searchRegex = searchData.regex;
if (!searchRegex.multiline) {
let mod = 'm';
if (searchRegex.ignoreCase) {
mod += 'i';
}
if (searchRegex.global) {
mod += 'g';
}
searchRegex = new RegExp(searchRegex.source, mod);
}
const model = this._editor.getModel();
const modelText = model.getValue(editorCommon.EndOfLinePreference.LF);
const fullModelRange = model.getFullModelRange();
......@@ -416,11 +428,11 @@ export class FindModelBoundToEditorModel {
const replacePattern = this._getReplacePattern();
let resultText: string;
if (replacePattern.hasReplacementPatterns) {
resultText = modelText.replace(searchData.regex, function () {
resultText = modelText.replace(searchRegex, function () {
return replacePattern.buildReplaceString(<string[]><any>arguments);
});
} else {
resultText = modelText.replace(searchData.regex, replacePattern.buildReplaceString(null));
resultText = modelText.replace(searchRegex, replacePattern.buildReplaceString(null));
}
let command = new ReplaceCommandThatPreservesSelection(fullModelRange, resultText, this._editor.getSelection());
......
......@@ -2004,6 +2004,29 @@ suite('FindModel', () => {
findState.dispose();
});
findTest('issue #32522 replaceAll with ^ on more than 1000 matches', (editor, cursor) => {
let initialText = '';
for (let i = 0; i < 1100; i++) {
initialText += 'line' + i + '\n';
}
editor.getModel().setValue(initialText);
let findState = new FindReplaceState();
findState.change({ searchString: '^', replaceString: 'a ', isRegex: true }, false);
let findModel = new FindModelBoundToEditorModel(editor, findState);
findModel.replaceAll();
let expectedText = '';
for (let i = 0; i < 1100; i++) {
expectedText += 'a line' + i + '\n';
}
expectedText += 'a ';
assert.equal(editor.getModel().getValue(), expectedText);
findModel.dispose();
findState.dispose();
});
findTest('issue #19740 Find and replace capture group/backreference inserts `undefined` instead of empty string', (editor, cursor) => {
let findState = new FindReplaceState();
findState.change({ searchString: 'hello(z)?', replaceString: 'hi$1', isRegex: true, matchCase: true }, false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册