Skip to content

Commit

Permalink
Let completion box reappear after mistyping and pressing backspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed May 8, 2012
1 parent c856e36 commit c5ad584
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions plugins-client/ext.language/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ module.exports = {

// Monkey patch
if(!oldCommandKey) {
oldCommandKey = ace.keyBinding.onCommandKey;
ace.keyBinding.onCommandKey = this.onKeyPress.bind(this);
oldCommandKey = ace.keyBinding.onCommandKey;
ace.keyBinding.onCommandKey = this.onKeyPress.bind(this);
oldOnTextInput = ace.keyBinding.onTextInput;
ace.keyBinding.onTextInput = this.onTextInput.bind(this);
}
Expand Down
17 changes: 12 additions & 5 deletions plugins-client/ext.language/keyhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ function composeHandlers(mainHandler, fallbackHandler) {
};
}

/*function typeAlongComplete(e) {
function typeAlongComplete(e) {
if(e.metaKey || e.altKey || e.ctrlKey)
return false;
if(editors.currentEditor.amlEditor.syntax !== "javascript")
return false;
var ch = String.fromCharCode(e.keyIdentifier ? parseInt(e.keyIdentifier.replace("U+", ""), 16) : e.keyCode);
console.log(e);
handleChar(ch);
if(e.keyCode === 8) {
var ext = require("ext/language/complete");
var editor = editors.currentEditor.amlEditor.$editor;
var pos = editor.getCursorPosition();
var line = editor.session.getDocument().getLine(pos.row);
if(!preceededByIdentifier(line, pos.column))
return false;
ext.deferredInvoke();
}
return false;
}*/
}

function typeAlongCompleteTextInput(text, pasted) {
if(editors.currentEditor.amlEditor.syntax !== "javascript")
Expand Down Expand Up @@ -91,6 +97,7 @@ function preceededByIdentifier(line, column, postfix) {
}

exports.typeAlongCompleteTextInput = typeAlongCompleteTextInput;
exports.typeAlongComplete = typeAlongComplete;
exports.composeHandlers = composeHandlers;
exports.inCompletableCodeContext = inCompletableCodeContext;
exports.preceededByIdentifier = preceededByIdentifier;
Expand Down
5 changes: 5 additions & 0 deletions plugins-client/ext.language/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = ext.register("ext/language/language", {
enabled : true,

defaultKeyHandler: null,
defaultCommandKeyHandler: null,

hook : function() {
var _self = this;
Expand Down Expand Up @@ -148,13 +149,17 @@ module.exports = ext.register("ext/language/language", {
if(enabled) {
if(!this.defaultKeyHandler) {
this.defaultKeyHandler = this.editor.keyBinding.onTextInput;
this.defaultCommandKeyHandler = this.editor.keyBinding.onCommandKey;
this.editor.keyBinding.onTextInput = keyhandler.composeHandlers(keyhandler.typeAlongCompleteTextInput, this.defaultKeyHandler.bind(this.editor.keyBinding));
this.editor.keyBinding.onCommandKey = keyhandler.composeHandlers(keyhandler.typeAlongComplete, this.defaultCommandKeyHandler.bind(this.editor.keyBinding));
}
}
else {
if(this.defaultKeyHandler) {
this.editor.keyBinding.onTextInput = this.defaultKeyHandler;
this.editor.keyBinding.onCommandKey = this.defaultCommandKeyHandler;
this.defaultKeyHandler = null;
this.defaultCommandKeyHandler = null;
}
}
},
Expand Down

0 comments on commit c5ad584

Please sign in to comment.