From 21ee784ca1cc5158103671d838ddc3f94d934e00 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 17 Mar 2014 11:38:16 +0100 Subject: [PATCH] Add autoSelect option to auto completion By setting this to `false` no completion will be selected by default and pressing `Return` will simply insert a new line, rather than the first match. --- lib/ace/autocomplete.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index b243727f..155ffd0d 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -40,6 +40,7 @@ var snippetManager = require("./snippets").snippetManager; var Autocomplete = function() { this.autoInsert = true; + this.autoSelect = true; this.keyboardHandler = new HashHandler(); this.keyboardHandler.bindKeys(this.commands); @@ -69,8 +70,8 @@ var Autocomplete = function() { this.popup.setData(this.completions.filtered); var renderer = editor.renderer; + this.popup.setRow(this.autoSelect ? 0 : -1); if (!keepPopupPosition) { - this.popup.setRow(0); this.popup.setFontSize(editor.getFontSize()); var lineHeight = renderer.layerConfig.lineHeight; @@ -171,7 +172,13 @@ var Autocomplete = function() { "Esc": function(editor) { editor.completer.detach(); }, "Space": function(editor) { editor.completer.detach(); editor.insert(" ");}, - "Return": function(editor) { editor.completer.insertMatch(); }, + "Return": function(editor) { + if(editor.completer.popup.getRow() > -1) { + editor.completer.insertMatch(); + } else { + editor.insert("\n"); + } + }, "Shift-Return": function(editor) { editor.completer.insertMatch(true); }, "Tab": function(editor) { editor.completer.insertMatch(); },