diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index 4cc29043..475daee1 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -180,12 +180,15 @@ var Autocomplete = function() { "Esc": function(editor) { editor.completer.detach(); }, "Space": function(editor) { editor.completer.detach(); editor.insert(" ");}, - "Return": function(editor) { - if (editor.completer.popup.getRow() == -1) - return false; - editor.completer.insertMatch(); - }, + "Return": function(editor) { return editor.completer.insertMatch(); }, "Shift-Return": function(editor) { editor.completer.insertMatch(true); }, + "Tab": function(editor) { + var result = editor.completer.insertMatch(); + if (!result && !editor.tabstopManager) + editor.completer.goTo("down"); + else + return result; + }, "PageUp": function(editor) { editor.completer.popup.gotoPageUp(); }, "PageDown": function(editor) { editor.completer.popup.gotoPageDown(); } @@ -207,16 +210,16 @@ var Autocomplete = function() { completer.getCompletions(editor, session, pos, prefix, function(err, results) { if (!err) matches = matches.concat(results); - // Fetch prefix again, because they may have changed by now - var pos = editor.getCursorPosition(); - var line = session.getLine(pos.row); - callback(null, { - prefix: util.retrievePrecedingIdentifier(line, pos.column, results.length > 0 ? results[0].identifierRegex : undefined), + // Fetch prefix again, because they may have changed by now + var pos = editor.getCursorPosition(); + var line = session.getLine(pos.row); + callback(null, { + prefix: util.retrievePrecedingIdentifier(line, pos.column, results[0] && results[0].identifierRegex), matches: matches, finished: (--total === 0) + }); }); }); - }); return true; }; @@ -268,17 +271,9 @@ var Autocomplete = function() { return this.detach(); }.bind(this); - // Calcul prefix var prefix = results.prefix; - - // Results matches var matches = results && results.matches; - if (!matches || !matches.length) - return this.detach(); - // TODO reenable this when we have proper change tracking - // if (matches.length == 1) - // return this.insertMatch(matches[0]); - + if (!matches || !matches.length) return doDetach(); @@ -323,6 +318,8 @@ Autocomplete.startCommand = { exec: function(editor) { if (!editor.completer) editor.completer = new Autocomplete(); + editor.completer.autoInsert = + editor.completer.autoSelect = true; editor.completer.showPopup(editor); // needed for firefox on mac editor.completer.cancelContextMenu(); diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index 39b1946a..1933b4ff 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -79,7 +79,7 @@ var expandSnippet = { if (!success) editor.execCommand("indent"); }, - bindKey: "tab" + bindKey: "Tab" }; var onChangeMode = function(e, editor) { @@ -122,17 +122,18 @@ var doLiveAutocomplete = function(e) { var line = editor.session.getLine(pos.row); var hasCompleter = editor.completer && editor.completer.activated; var prefix = util.retrievePrecedingIdentifier(line, pos.column); - //Try to find custom prefixes on the completors - completers.forEach(function(completer){ - if(completer.identifierRegexprs){ - completer.identifierRegexprs.forEach(function(identifierRegex){ - if(!prefix) { + + //Try to find custom prefixes on the completers + completers.forEach(function(completer) { + if (completer.identifierRegexps) { + completer.identifierRegexps.forEach(function(identifierRegex){ + if (!prefix) { prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex); } }); } }); - + // We don't want to autocomplete with no prefix if (e.command.name === "backspace" && !prefix) { if (hasCompleter) @@ -145,6 +146,7 @@ var doLiveAutocomplete = function(e) { // Create new autocompleter editor.completer = new Autocomplete(); // Disable autoInsert + editor.completer.autoSelect = false; editor.completer.autoInsert = false; } editor.completer.showPopup(editor); diff --git a/lib/ace/snippets.js b/lib/ace/snippets.js index f382f7ba..f09bba2c 100644 --- a/lib/ace/snippets.js +++ b/lib/ace/snippets.js @@ -379,7 +379,7 @@ var SnippetManager = function() { scope = scope.split("/").pop(); if (scope === "html" || scope === "php") { // PHP is actually HTML - if (scope === "php") + if (scope === "php" && !editor.session.$mode.inlinePhp) scope = "html"; var c = editor.getCursorPosition() var state = editor.session.getState(c.row);