| author | Adrian Aichner | 2012-12-14 10:31:07 (EST) |
|---|---|---|
| committer | John Arthorne | 2012-12-14 10:31:07 (EST) |
| commit | 49230c53f7b4b1afc0cc73fd555d836107afe304 (patch) (side-by-side diff) | |
| tree | 424f03af88bbf7ad3aa4cba3d7404d8f037f5be9 | |
| parent | 2c69142ca155dc37553ee038a4dc2b8805e82152 (diff) | |
| download | org.eclipse.orion.client-49230c53f7b4b1afc0cc73fd555d836107afe304.zip org.eclipse.orion.client-49230c53f7b4b1afc0cc73fd555d836107afe304.tar.gz org.eclipse.orion.client-49230c53f7b4b1afc0cc73fd555d836107afe304.tar.bz2 | |
Bug 396224 - Regex replace all doesn't handle capture groups
| -rw-r--r-- | bundles/org.eclipse.orion.client.core/web/orion/searchAndReplace/textSearcher.js | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/searchAndReplace/textSearcher.js b/bundles/org.eclipse.orion.client.core/web/orion/searchAndReplace/textSearcher.js index 1d37424..cc137c9 100644 --- a/bundles/org.eclipse.orion.client.core/web/orion/searchAndReplace/textSearcher.js +++ b/bundles/org.eclipse.orion.client.core/web/orion/searchAndReplace/textSearcher.js @@ -348,6 +348,20 @@ orion.TextSearcher = (function() { } }, + _doReplace: function(start, end, searchStr, newStr) { + var editor = this._editor; + if (this._useRegExp) { + var newStrWithSubstitutions = editor.getText().substring(start, end).replace(new RegExp(searchStr), newStr); + if (newStrWithSubstitutions) { + editor.setText(newStrWithSubstitutions, start, end); + editor.setSelection(start, start + newStrWithSubstitutions.length, true); + } + } else { + editor.setText(newStr, start, end); + editor.setSelection(start, start + newStr.length, true); + } + }, + replace: function() { this.startUndo(); var newStr = document.getElementById("localSearchReplaceWith").value; //$NON-NLS-0$ @@ -370,16 +384,7 @@ orion.TextSearcher = (function() { start = result.start; end = result.end; } - } - if (this._useRegExp) { - var newStrWithSubstitutions = editor.getText().substring(start, end).replace(new RegExp(searchStr), newStr); - if (newStrWithSubstitutions) { - editor.setText(newStrWithSubstitutions, start, end) - editor.setSelection(start, start + newStrWithSubstitutions.length, true); - } - } else { - editor.setText(newStr, start, end); - editor.setSelection(start, start + newStr.length, true); + this._doReplace(start, end, searchStr, newStr); } this.endUndo(); if (this._findAfterReplace && searchStr){ @@ -463,8 +468,7 @@ orion.TextSearcher = (function() { self.startUndo(); } var selection = editor.getSelection(); - editor.setText(newStr, selection.start, selection.end); - editor.setSelection(selection.start , selection.start + newStr.length, true); + self._doReplace(selection.start, selection.end, searchStr, newStr); startPos = self.getSearchStartIndex(true, true); } if(number > 0) { |

