nuclide-commons-atom
Advanced tools
Comparing version 0.1.9 to 0.1.10
{ | ||
"name": "nuclide-commons-atom", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "Common Nuclide node modules (for use with Atom only).", | ||
@@ -15,4 +15,5 @@ "license": "BSD-3-Clause", | ||
"async-to-generator": "1.1.0", | ||
"escape-string-regexp": "1.0.5", | ||
"log4js": "1.1.1", | ||
"nuclide-commons": "0.1.9", | ||
"nuclide-commons": "0.1.10", | ||
"rxjs": "5.3.1", | ||
@@ -19,0 +20,0 @@ "semver": "5.3.0", |
34
range.js
@@ -18,2 +18,8 @@ 'use strict'; | ||
/** | ||
* Finds the word at the position. You can either provide a word regex yourself, | ||
* or have Atom use the word regex in force at the scopes at that position, | ||
* in which case it uses the optional includeNonWordCharacters, default true. | ||
* (I know that's a weird default but it follows Atom's convention...) | ||
*/ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
@@ -30,9 +36,25 @@ * All rights reserved. | ||
function wordAtPosition(editor, position, wordRegex_) { | ||
let wordRegex = wordRegex_; | ||
if (!wordRegex) { | ||
wordRegex = editor.getLastCursor().wordRegExp(); | ||
function wordAtPosition(editor, position, wordRegex) { | ||
let wordRegex_; | ||
if (wordRegex instanceof RegExp) { | ||
wordRegex_ = wordRegex; | ||
} else { | ||
// What is the word regex associated with the position? We'd like to use | ||
// atom$Cursor.wordRegExp, except that function gets the regex associated | ||
// with the editor's current cursor while we want the regex associated with | ||
// the specific position. So we re-implement it ourselves... | ||
const scopeDescriptor = editor.scopeDescriptorForBufferPosition(position); | ||
const nonWordChars = editor.getNonWordCharacters(scopeDescriptor); | ||
const escaped = nonWordChars.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); | ||
// We copied this escaping regex from atom$Cursor.wordRegexp, rather than | ||
// using the library function 'escapeStringRegExp'. That's because the | ||
// library function doesn't escape the hyphen character and so is | ||
// unsuitable for use inside a range. | ||
let r = `^[\t ]*$|[^\\s${escaped}]+`; | ||
if (wordRegex == null || wordRegex.includeNonWordCharacters) { | ||
r += `|[${escaped}]+`; | ||
} | ||
wordRegex_ = new RegExp(r, 'g'); | ||
} | ||
const buffer = editor.getBuffer(); | ||
return (0, (_range || _load_range()).wordAtPositionFromBuffer)(buffer, position, wordRegex); | ||
return (0, (_range || _load_range()).wordAtPositionFromBuffer)(editor.getBuffer(), position, wordRegex_); | ||
} | ||
@@ -39,0 +61,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
164147
7
1977
+ Addedescape-string-regexp@1.0.5
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addednuclide-commons@0.1.10(transitive)
- Removednuclide-commons@0.1.9(transitive)
Updatednuclide-commons@0.1.10