all files / lib/ui/ GoLineForm.js

60% Statements 18/30
16.67% Branches 1/6
40% Functions 2/5
72% Lines 18/25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                            
var _ = require('lodash');
 
var BaseWidget = require('base-widget');
 
var Slap = require('./Slap');
var BaseFindForm = require('./BaseFindForm');
 
GoLineForm._label = " line number: ";
function GoLineForm (opts) {
  var self = this;
 
  Iif (!(self instanceof GoLineForm)) return new GoLineForm(opts);
 
  BaseFindForm.call(self, _.merge({
    findField: {left: GoLineForm._label.length}
  }, Slap.global.options.form.goLine, opts));
 
  self.goLineLabel = new BaseWidget(_.merge({
    parent: self,
    tags: true,
    content: GoLineForm._label,
    top: 0,
    height: 1,
    left: 0,
    width: GoLineForm._label.length,
    style: self.options.style
  }, self.options.goLineLabel));
}
GoLineForm.prototype.__proto__ = BaseFindForm.prototype;
 
GoLineForm.prototype._initHandlers = function () {
  var self = this;
  self.on('cancel', function () { self.resetEditor(); });
  self.on('show', function () { self.findField.textBuf.setText(''); });
  self.on('find', function (lineNumber, direction) {
    lineNumber = Number(lineNumber) - 1;
    if (lineNumber !== lineNumber) return; // isNaN(lineNumber)
    var selection = self.pane.editor.selection;
    selection.setHeadPosition([lineNumber, 0]);
    selection.clearTail();
    if (direction) self.hide();
    return self;
  });
  return BaseFindForm.prototype._initHandlers.apply(self, arguments);
};
 
module.exports = GoLineForm;