motion
Version:
motion - moving development forward
109 lines (83 loc) • 3.06 kB
JavaScript
exports.__esModule = true;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _atomTextBufferPoint = require('atom-text-buffer-point');
var _atomTextBufferPoint2 = _interopRequireDefault(_atomTextBufferPoint);
var _sbEventKit = require('sb-event-kit');
var _autocomplete = require('./autocomplete');
var _autocomplete2 = _interopRequireDefault(_autocomplete);
var _libFns = require('../lib/fns');
var _helpers = require('./helpers');
'use babel';
var Editor = (function () {
function Editor() {
_classCallCheck(this, Editor);
this.subscriptions = new _sbEventKit.CompositeDisposable();
this.autocomplete = new _autocomplete2['default']();
this.subscriptions.add(this.autocomplete);
}
Editor.prototype.activate = function activate(bridge) {
var _this = this;
this.subscriptions.add(bridge.onMessage('editor:autocomplete', function (message) {
var suggestions = _this.complete(message.text, message.position);
bridge.broadcast('editor:autocomplete', { id: message.id, suggestions: suggestions });
}));
};
Editor.prototype.complete = function complete(text, position) {
var point = _atomTextBufferPoint2['default'].fromObject(position);
var positionInfo = undefined;
// Do not log syntax errors to console
try {
positionInfo = this.positionInfo(text, point);
} catch (_) {
if (typeof _.pos !== 'undefined') {
// Syntax error
return [];
} else throw _;
}
// Errors caught here are probably internal, log them so we can debug
try {
return this.autocomplete.complete(text, point, positionInfo);
} catch (_) {
_libFns.logError(_);
return [];
}
};
Editor.prototype.positionInfo = function positionInfo(text, position) {
var info = {
views: this.getViews(text),
active: null,
position: null
};
info.active = _helpers.getObjectAtPosition(info.views, position);
if (info.active) {
info.position = this.getPositionInfo(info.active, position);
}
return info;
};
Editor.prototype.getPositionInfo = function getPositionInfo(view, position) {
if (_helpers.getObjectAtPosition(view.els, position)) {
return _helpers.POSITION_TYPE.VIEW_JSX;
}
if (_helpers.getObjectAtPosition(view.styles, position)) {
return _helpers.POSITION_TYPE.STYLE;
}
return _helpers.POSITION_TYPE.VIEW_TOP;
};
Editor.prototype.getViews = function getViews(text) {
var views = {};
_helpers.transformText(text, {
onMeta: function onMeta(meta) {
views = meta.views;
}
});
return views;
};
Editor.prototype.dispose = function dispose() {
this.subscriptions.dispose();
};
return Editor;
})();
exports['default'] = Editor;
module.exports = exports['default'];
//# sourceMappingURL=index.js.map