Socket
Socket
Sign inDemoInstall

nuclide-commons-atom

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuclide-commons-atom - npm Package Compare versions

Comparing version 0.1.10 to 0.1.11

4

ContextMenu.js

@@ -178,3 +178,5 @@ 'use strict';

// https://github.com/atom/atom/blob/v1.15.0/src/main-process/context-menu.coffee#L17
return Array.isArray(event.detail) && event.detail[0] && event.detail[0].contextCommand;
return Array.isArray(event.detail) &&
// flowlint-next-line sketchy-null-mixed:off
event.detail[0] && event.detail[0].contextCommand;
}

@@ -181,0 +183,0 @@ }

{
"name": "nuclide-commons-atom",
"version": "0.1.10",
"version": "0.1.11",
"description": "Common Nuclide node modules (for use with Atom only).",

@@ -17,3 +17,3 @@ "license": "BSD-3-Clause",

"log4js": "1.1.1",
"nuclide-commons": "0.1.10",
"nuclide-commons": "0.1.11",
"rxjs": "5.3.1",

@@ -20,0 +20,0 @@ "semver": "5.3.0",

@@ -6,16 +6,82 @@ 'use strict';

});
exports.applyTextEdits = applyTextEdits;
exports.applyTextEditsToBuffer = applyTextEditsToBuffer;
exports.applyTextEditsForMultipleFiles = undefined;
var _textEditor;
var _asyncToGenerator = _interopRequireDefault(require('async-to-generator'));
function _load_textEditor() {
return _textEditor = require('./text-editor');
}
/**
* Attempts to apply the given patches for multiple files. Accepts a Map as input
* with file paths as keys and a corresponding array of TextEdits as values.
*
* It is an error to send overlapping text-edits. All text-edits describe changes
* made to the initial document version. The order of the edits does not matter
* as they will be sorted before they are applied.
*
* All changes will be applied to the buffers but not saved. If a file is not
* currently open, it will be opened.
*
* If a change is undone (Cmd+Z), only the changes of the current
* file will be undone. All of the changes for that file will be undone at once.
*
* Returns true if the application was successful, otherwise false. If any of
* the changes fail, for ANY file, then none of the changes are applied.
*/
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
*/
let applyTextEditsForMultipleFiles = exports.applyTextEditsForMultipleFiles = (() => {
var _ref = (0, _asyncToGenerator.default)(function* (changes) {
const paths = Array.from(changes.keys());
// NOTE: There is a race here. If the file contents change while the
// editors are being opened, then the ranges of the TextEdits will be off.
// However, currently this is only used to applyEdits to open files.
const editors = yield Promise.all(paths.map((() => {
var _ref2 = (0, _asyncToGenerator.default)(function* (path) {
return (0, (_goToLocation || _load_goToLocation()).goToLocation)(path);
});
return function (_x2) {
return _ref2.apply(this, arguments);
};
})()));
const checkpoints = editors.map(function (editor) {
if (!(editor != null)) {
throw new Error('Invariant violation: "editor != null"');
}
const buffer = editor.getBuffer();
return [buffer, buffer.createCheckpoint()];
});
const allOkay = paths.reduce(function (successSoFar, path) {
const edits = changes.get(path);
return successSoFar && edits != null && applyTextEdits(path, ...edits);
}, true);
if (!allOkay) {
checkpoints.forEach(function ([buffer, checkPoint]) {
buffer.revertToCheckpoint(checkPoint);
return false;
});
}
return allOkay;
});
return function applyTextEditsForMultipleFiles(_x) {
return _ref.apply(this, arguments);
};
})();
/**
* Attempts to apply the given patches to the given file.
*
* For best results, the edits should be non-overlapping and in order. That is, for every edit
* provided, the start of its range should be after the end of the previous edit's range.
* It is an error to send overlapping edits. The order of the edits does not
* matter (they will be sorted before they are applied).
*

@@ -28,3 +94,28 @@ * The file must be currently open in Atom, and the changes will be applied to the buffer but not

*/
exports.applyTextEdits = applyTextEdits;
exports.applyTextEditsToBuffer = applyTextEditsToBuffer;
var _textEditor;
function _load_textEditor() {
return _textEditor = require('./text-editor');
}
var _goToLocation;
function _load_goToLocation() {
return _goToLocation = require('./go-to-location');
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function applyTextEdits(path, ...edits) {
// Sort the edits to be in order (For every edit, the start of its range will
// be after the end of the previous edit's range.)
edits.sort((e1, e2) => e1.oldRange.compare(e2.oldRange));
if (editsOverlap(edits)) {
throw new Error('applyTextEdits cannot be called with overlapping edits.');
}
const editor = (0, (_textEditor || _load_textEditor()).existingEditorForUri)(path);

@@ -37,13 +128,3 @@

return applyTextEditsToBuffer(editor.getBuffer(), edits);
} /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
* @format
*/
}

@@ -95,2 +176,12 @@ function applyTextEditsToBuffer(buffer, edits) {

return true;
}
// Returns whether an array of sorted TextEdits contain an overlapping range.
function editsOverlap(sortedEdits) {
for (let i = 0; i < sortedEdits.length - 1; i++) {
if (sortedEdits[i].oldRange.intersectsWith(sortedEdits[i + 1].oldRange)) {
return true;
}
}
return false;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc