Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

Commit

Permalink
Auto activate content assist on '.' fixed #63
Browse files Browse the repository at this point in the history
This is now implemented, with the following notes:

1. Content assist will only be auto activated in .js files
2. We should consider making this configurable and using a notion of content types (see #147
3. auto activation defaults to 500ms
4. auto activation can be configured using the ui.auto_activation configuration in .scripted.
5. I changed auto activation for the drop-down menus to use this property as well.
  • Loading branch information
Andrew Eisenberg committed Jan 24, 2013
1 parent fd87a64 commit 378728b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .scripted
Expand Up @@ -44,8 +44,8 @@
"font_size":18,
"content_assist_font_size":14,
"navigator": false,
// time in ms before history menu drops down (default 500ms)
"history_drop_down_auto_activation": 500
// time in ms before content assist auto activates and history menu drops down (default 500ms)
"auto_activation": 500
}

EXEC configuration examples:
Expand Down
34 changes: 33 additions & 1 deletion client/scripts/orion/editor/contentAssist.js
Expand Up @@ -12,9 +12,18 @@
/*global define */
/*jslint maxerr:150 browser:true devel:true */

define("orion/editor/contentAssist", ['i18n!orion/editor/nls/messages', 'orion/textview/keyBinding', 'orion/textview/eventTarget', 'scripted/keybindings/keybinder'],
define("orion/editor/contentAssist", ['i18n!orion/editor/nls/messages', 'orion/textview/keyBinding', 'orion/textview/eventTarget', 'scripted/keybindings/keybinder'],
function(messages, mKeyBinding, mEventTarget, mKeybinder) {


// SCRIPTED
var autoActivation = (window.scripted &&
window.scripted.config &&
window.scripted.config.ui &&
window.scripted.config.ui.auto_activation)
|| 500;
// SCRIPTED end

/**
* Set of styles available for proposals. The key corresponds to the value of the 'style'
* property of the proposal. The value corresponds to a css class for styling that proposal.
Expand Down Expand Up @@ -116,7 +125,30 @@ function(messages, mKeyBinding, mEventTarget, mKeybinder) {
this.showContentAssist(true);
return true;
}.bind(this));

// SCRIPTED automatically open content assist after delay
var filepath = this.editor.getFilePath();
if (filepath.substr(filepath.length-3, 3) === ".js") {
this.textView.addEventListener("Verify", this.autoActivate.bind(this));
}
// SCRIPTED end
},

// SCRIPTED
/** @private */
autoActivate : function(e) {
if (e.text === '.' && !this.activationRequest) {
this.activationRequest = setTimeout(function() {
this.showContentAssist(true);
this.activationRequest = null;
}.bind(this), autoActivation);
} else if (this.activationRequest) {
clearTimeout(this.activationRequest);
this.activationRequest = null;
}
},
// SCRIPTED end

/** @private */
cancel: function() {
this.showContentAssist(false);
Expand Down
2 changes: 1 addition & 1 deletion client/scripts/scripted/editor/editorPane.js
Expand Up @@ -78,7 +78,7 @@ function(mKeybinder, mEditor, mPaneFactory, mNavHistory, mKeyBinding, mPageState
var autoActivation = (window.scripted &&
window.scripted.config &&
window.scripted.config.ui &&
window.scripted.config.ui.history_drop_down_auto_activation)
window.scripted.config.ui.auto_activation)
|| 500;

var root = window.fsroot;
Expand Down
8 changes: 4 additions & 4 deletions client/scripts/scripted/editor/scriptedEditor.js
Expand Up @@ -511,6 +511,10 @@ define([
domNode: domNode
});

editor.getFilePath = function(){
return filePath;
};

editor.jsContentAssistant = jsContentAssistant;

editor.addEventListener("DirtyChanged", function(evt) {
Expand Down Expand Up @@ -544,10 +548,6 @@ define([
postSave(text);
};

editor.getFilePath = function(){
return filePath;
};

editor.findDefinition = function(offset) {
if (isJS) {
var text = editor.getTextView().getText();
Expand Down

0 comments on commit 378728b

Please sign in to comment.