jenkins-bot has submitted this change and it was merged.

Change subject: Rewrite of getCurrentWord
......................................................................


Rewrite of getCurrentWord

Should be more resistant against special characters.

Bug: T127721
Change-Id: I45c8afdb9343757c426a0d3609aef35261bf40bc
---
M wikibase/codemirror/addon/hint/wikibase-rdf-hint.js
1 file changed, 16 insertions(+), 19 deletions(-)

Approvals:
  Smalyshev: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/wikibase/codemirror/addon/hint/wikibase-rdf-hint.js 
b/wikibase/codemirror/addon/hint/wikibase-rdf-hint.js
index e69d5b0..42b7786 100755
--- a/wikibase/codemirror/addon/hint/wikibase-rdf-hint.js
+++ b/wikibase/codemirror/addon/hint/wikibase-rdf-hint.js
@@ -127,29 +127,26 @@
        }
 
        function getCurrentWord( line, position ) {
-               // TODO This will not work for terms containing a slash, for 
example 'TCP/IP'
-               var leftColon = line.substring( 0, position ).lastIndexOf( ':' 
),
-                       left = line.substring( 0, leftColon ).lastIndexOf( ' ' 
),
-                       rightSlash = line.indexOf( '/', position ),
-                       rightSpace = line.indexOf( ' ', position ),
-                       right,
-                       word;
+               var pos = position -1,
+                       colon = false;
 
-               if ( rightSlash === -1 || rightSlash > rightSpace ) {
-                       right = rightSpace;
-               } else {
-                       right = rightSlash;
-               }
+               while( line.charAt( pos ).match( /\w/ ) ||
+                       ( line.charAt( pos ) === ' ' && colon === false ) ||
+                       ( line.charAt( pos ) === ':' && colon === false ) ){
 
-               if ( left === -1 ) {
-                       left = 0;
-               } else {
-                       left += 1;
+                       if( line.charAt( pos ) === ':' )
+                               colon = true;
+                       pos--;
                }
-               if ( right === -1 ) {
-                       right = line.length;
+               var left = pos + 1;
+
+               pos = position;
+               while( line.charAt( pos ).match( /\w/ ) ){
+                       pos++;
                }
-               word = line.substring( left, right );
+               var right = pos;
+
+               var word = line.substring( left, right );
                return { word: word, start: left, end: right };
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/272755
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I45c8afdb9343757c426a0d3609aef35261bf40bc
Gerrit-PatchSet: 5
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to