mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Revert "Merge pull request #3697 from jeffslofish/Issue-3676"
This reverts commit9e99101057, reversing changes made toa9e27717f4.
This commit is contained in:
1 parent
9e99101057
commit
53bf87ed22
35 files changed
+996
-104
No files matched your search
@@ -40,7 +40,8 @@ define(function (require, exports, module) {
|
||||
StringMatch = brackets.getModule("utils/StringMatch"),
|
||||
HintUtils = require("HintUtils"),
|
||||
ScopeManager = require("ScopeManager"),
|
||||
Session = require("Session");
|
||||
Session = require("Session"),
|
||||
Acorn = require("thirdparty/acorn/acorn");
|
||||
|
||||
var KeyboardPrefs = JSON.parse(require("text!keyboard.json"));
|
||||
|
||||
@@ -53,7 +54,6 @@ define(function (require, exports, module) {
|
||||
cachedToken = null, // the token used in the current hinting session
|
||||
matcher = null; // string matcher for hints
|
||||
|
||||
|
||||
/**
|
||||
* Get the value of current session.
|
||||
* Used for unit testing.
|
||||
@@ -210,18 +210,18 @@ define(function (require, exports, module) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token.type === null) {
|
||||
if (token.className === null) {
|
||||
token = session.getNextTokenOnLine(cursor);
|
||||
}
|
||||
|
||||
if (lastToken && lastToken.type === null) {
|
||||
if (lastToken && lastToken.className === null) {
|
||||
lastToken = session.getNextTokenOnLine(cachedCursor);
|
||||
}
|
||||
|
||||
// Both of the tokens should never be null (happens when token is off
|
||||
// the end of the line), so one is null then close the hints.
|
||||
if (!lastToken || !token ||
|
||||
token.type !== lastToken.type) {
|
||||
token.className !== lastToken.className) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -376,8 +376,46 @@ define(function (require, exports, module) {
|
||||
// if we were displaying a function type
|
||||
return false;
|
||||
}
|
||||
|
||||
if (session.getType().property) {
|
||||
// if we're inserting a property name, we need to make sure the
|
||||
// hint is a valid property name.
|
||||
// to check this, run the hint through Acorns tokenizer
|
||||
// it should result in one token, and that token should either be
|
||||
// a 'name' or a 'keyword', as javascript allows keywords as property names
|
||||
var tokenizer = Acorn.tokenize(completion);
|
||||
var currentToken = tokenizer(),
|
||||
invalidPropertyName = false;
|
||||
|
||||
// the name is invalid if the hint is not a 'name' or 'keyword' token
|
||||
if (currentToken.type !== Acorn.tokTypes.name && !currentToken.type.keyword) {
|
||||
invalidPropertyName = true;
|
||||
} else {
|
||||
// check for a second token - if there is one (other than 'eof')
|
||||
// then the hint isn't a valid property name either
|
||||
currentToken = tokenizer();
|
||||
if (currentToken.type !== Acorn.tokTypes.eof) {
|
||||
invalidPropertyName = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (invalidPropertyName) {
|
||||
// need to walk back to the '.' and replace
|
||||
// with '["<hint>"]
|
||||
var dotCursor = session.findPreviousDot();
|
||||
if (dotCursor) {
|
||||
completion = "[\"" + completion + "\"]";
|
||||
start.line = dotCursor.line;
|
||||
start.ch = dotCursor.ch - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Replace the current token with the completion
|
||||
session.editor.document.replaceRange(completion, start, end);
|
||||
// HACK (tracking adobe/brackets#1688): We talk to the private CodeMirror instance
|
||||
// directly to replace the range instead of using the Document, as we should. The
|
||||
// reason is due to a flaw in our current document synchronization architecture when
|
||||
// inline editors are open.
|
||||
session.editor._codeMirror.replaceRange(completion, start, end);
|
||||
|
||||
// Return false to indicate that another hinting session is not needed
|
||||
return false;
|
||||
@@ -392,11 +430,17 @@ define(function (require, exports, module) {
|
||||
* information, and reject any pending deferred requests.
|
||||
*
|
||||
* @param {Editor} editor - editor context to be initialized.
|
||||
* @param {boolean} primePump - true if the pump should be primed.
|
||||
*/
|
||||
function initializeSession(editor) {
|
||||
function initializeSession(editor, primePump) {
|
||||
ScopeManager.handleEditorChange(editor.document);
|
||||
session = new Session(editor);
|
||||
cachedHints = null;
|
||||
|
||||
// prime pump for hints so the first user request is fast
|
||||
if (primePump) {
|
||||
ScopeManager.requestHints(session, session.editor.document, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -412,7 +456,7 @@ define(function (require, exports, module) {
|
||||
cachedType = null;
|
||||
|
||||
if (editor && editor.getLanguageForSelection().getId() === HintUtils.LANGUAGE_ID) {
|
||||
initializeSession(editor);
|
||||
initializeSession(editor, true);
|
||||
$(editor)
|
||||
.on(HintUtils.eventName("change"), function () {
|
||||
ScopeManager.handleFileChange(editor.document);
|
||||
|
||||
Reference in new issue
Block a user