From d8d64c6a9146f42e54ae5cf57145ca34ae3dc071 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Wed, 9 Nov 2016 18:35:58 +0000 Subject: [PATCH] Submitting the goLine form should not add a newline Moved next and prev to findForm, where multiple results are possible Prevented the enter keypress event from being transferred to the editor --- lib/ui/BaseFindForm.js | 7 ------- lib/ui/FindForm.js | 9 +++++++++ lib/ui/GoLineForm.js | 12 ++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/ui/BaseFindForm.js b/lib/ui/BaseFindForm.js index 8844958..012c5ba 100644 --- a/lib/ui/BaseFindForm.js +++ b/lib/ui/BaseFindForm.js @@ -59,13 +59,6 @@ BaseFindForm.prototype._initHandlers = function () { }); textBuf.onDidChange(function () { self.find(textBuf.getText()); }); - self.findField.on('keypress', function (ch, key) { - var text = textBuf.getText(); - switch (self.resolveBinding(key)) { - case 'next': self.find(text, 1); return false; - case 'prev': self.find(text, -1); return false; - }; - }); return BaseForm.prototype._initHandlers.apply(self, arguments); }; diff --git a/lib/ui/FindForm.js b/lib/ui/FindForm.js index 084e46a..de8e4c5 100644 --- a/lib/ui/FindForm.js +++ b/lib/ui/FindForm.js @@ -96,6 +96,15 @@ FindForm.prototype._initHandlers = function () { } editor._updateContent(); }, self.options.perf.findThrottle)); + + self.findField.on('keypress', function (ch, key) { + var text = self.findField.textBuf.getText(); + switch (self.resolveBinding(key)) { + case 'next': self.find(text, 1); return false; + case 'prev': self.find(text, -1); return false; + }; + }); + return BaseFindForm.prototype._initHandlers.apply(self, arguments); }; diff --git a/lib/ui/GoLineForm.js b/lib/ui/GoLineForm.js index 78c445b..0507656 100644 --- a/lib/ui/GoLineForm.js +++ b/lib/ui/GoLineForm.js @@ -30,6 +30,18 @@ GoLineForm.prototype.__proto__ = BaseFindForm.prototype; GoLineForm.prototype._initHandlers = function () { var self = this; + + self.findField.on('keypress', function (ch, key) { + var lineNumber = self.findField.textBuf.getText(); + switch (self.resolveBinding(key)) { + // Use setTimeout as a horrible hack to prevent + // the keypress from being transferred to the editor, + // causing an unintentional extra linebreak. + case 'next': setTimeout(function(){ self.find(lineNumber, 1) }, 1); return false; + case 'submit': setTimeout(function(){ self.find(lineNumber, 1) }, 1); return false; + }; + }); + self.on('cancel', function () { self.resetEditor(); }); self.on('show', function () { self.findField.textBuf.setText(''); }); self.on('find', function (lineNumber, direction) {