Merge "Search: Add option to search whole words"

This commit is contained in:
jenkins-bot 2019-05-19 18:21:54 +00:00 committed by Gerrit Code Review
commit 7c75285577
5 changed files with 12 additions and 1 deletions

View file

@ -165,6 +165,7 @@
"wikieditor-toolbar-tool-replace-replace",
"wikieditor-toolbar-tool-replace-case",
"wikieditor-toolbar-tool-replace-regex",
"wikieditor-toolbar-tool-replace-word",
"wikieditor-toolbar-tool-replace-button-findnext",
"wikieditor-toolbar-tool-replace-button-replace",
"wikieditor-toolbar-tool-replace-button-replaceall",

View file

@ -125,6 +125,7 @@
"wikieditor-toolbar-tool-replace-success": "$1 {{PLURAL:$1|replacement|replacements}} made.",
"wikieditor-toolbar-tool-replace-emptysearch": "You did not enter anything to search for.",
"wikieditor-toolbar-tool-replace-invalidregex": "The regular expression you entered is invalid: $1",
"wikieditor-toolbar-tool-replace-word": "Match whole word",
"wikieditor-toolbar-section-characters": "Special characters",
"wikieditor-toolbar-section-help": "Help",
"wikieditor-toolbar-help-heading-description": "Description",

View file

@ -151,6 +151,7 @@
"wikieditor-toolbar-tool-replace-success": "Parameter:\n* $1 - the number of replacements",
"wikieditor-toolbar-tool-replace-emptysearch": "Used in the \"search and replace\" dialog of the toolbar as hint after clicking the button",
"wikieditor-toolbar-tool-replace-invalidregex": "Parameters:\n* $1 - a browser-supplied error message, probably in English, possibly in the browser language.\n\nA \"regular expression\" is a syntax to find strings based on patterns, for more see [[wikipedia:Regular expression|the Wikipedia article]].\n\nRegular expressions are mostly a programmer tool, which is sometimes exposed to normal users too.\n\nIt's almost as a programming language, but it is used to describe different kinds of strings (sometimes also called patterns and pattern matching), and is often used to change (parts of) the strings too.",
"wikieditor-toolbar-tool-replace-word": "Used in \"search and replace\" dialog of the toolbar as a label for a search mode where there will be no search result if the search term is part of another word",
"wikieditor-toolbar-section-characters": "This will be a toolbar for special characters, like emoticons.\nFor more information, see https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization\n{{Identical|Special character}}",
"wikieditor-toolbar-section-help": "{{Identical|Help}}",
"wikieditor-toolbar-help-heading-description": "Header for the description column used in the help section of the toolbar\n{{Identical|Description}}",

View file

@ -846,7 +846,7 @@
// TODO: Find a cleaner way to share this function
$( this ).data( 'replaceCallback', function ( mode ) {
var offset, textRemainder, regex,
searchStr, replaceStr, flags, matchCase, isRegex,
searchStr, replaceStr, flags, matchCase, matchWord, isRegex,
$textarea, text, match,
actualReplacement,
start, end;
@ -873,6 +873,10 @@
if ( !isRegex ) {
searchStr = mw.RegExp.escape( searchStr );
}
matchWord = $( '#wikieditor-toolbar-replace-word' ).is( ':checked' );
if ( matchWord ) {
searchStr = '\\b(?:' + searchStr + ')\\b';
}
if ( mode === 'replaceAll' ) {
flags += 'g';
}

View file

@ -17,6 +17,10 @@
<input type="checkbox" id="wikieditor-toolbar-replace-case"/>
<label for="wikieditor-toolbar-replace-case" rel="wikieditor-toolbar-tool-replace-case"></label>
</div>
<div class="wikieditor-toolbar-field-wrapper">
<input type="checkbox" id="wikieditor-toolbar-replace-word"/>
<label for="wikieditor-toolbar-replace-word" rel="wikieditor-toolbar-tool-replace-word"></label>
</div>
<div class="wikieditor-toolbar-field-wrapper">
<input type="checkbox" id="wikieditor-toolbar-replace-regex"/>
<label for="wikieditor-toolbar-replace-regex" rel="wikieditor-toolbar-tool-replace-regex"></label>