From 5aa29604eac17d1c31b620d48a038d61803ef0aa Mon Sep 17 00:00:00 2001 From: Ian Wehrman Date: Wed, 15 May 2013 16:04:23 -0700 Subject: [PATCH 1/3] Add the font-family values directly defined by the CSS specification. --- src/extensions/default/CSSCodeHints/CSSProperties.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/default/CSSCodeHints/CSSProperties.json b/src/extensions/default/CSSCodeHints/CSSProperties.json index 91ddf4df36d..de1955bca89 100644 --- a/src/extensions/default/CSSCodeHints/CSSProperties.json +++ b/src/extensions/default/CSSCodeHints/CSSProperties.json @@ -90,7 +90,7 @@ "flex-wrap": {"values": ["nowrap", "wrap", "wrap-reverse"]}, "float": {"values": ["left", "right", "none", "inherit"]}, "font": {"values": []}, - "font-family": {"values": []}, + "font-family": {"values": ["cursive", "fantasy", "inherit", "monospace", "sans-serif", "serif"]}, "font-feature-settings": {"values": ["normal"]}, "font-kerning": {"values": ["auto", "none", "normal"]}, "font-language-override": {"values": ["normal"]}, From e3b8f862102f2f7f561cf532807d86d1602ad626 Mon Sep 17 00:00:00 2001 From: Ian Wehrman Date: Wed, 15 May 2013 16:34:17 -0700 Subject: [PATCH 2/3] Modify the CodeHintManager (API) so that a provider may return "true" to indicate that the current session should be closed, but that the CHM should immediately attempt to begin a new session. --- src/editor/CodeHintManager.js | 49 +++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/editor/CodeHintManager.js b/src/editor/CodeHintManager.js index 9649f5a1b6e..654344a89a8 100644 --- a/src/editor/CodeHintManager.js +++ b/src/editor/CodeHintManager.js @@ -118,10 +118,12 @@ * The method by which a provider provides hints for the editor context * associated with the current session. The getHints method is called only * if the provider asserted its willingness to provide hints in an earlier - * call to hasHints. The provider may return null, which indicates that - * the manager should end the current hinting session and close the hint - * list window. Otherwise, the provider should return a response object - * that contains three properties: + * call to hasHints. The provider may return null or false, which indicates + * that the manager should end the current hinting session and close the hint + * list window; or true, which indicates that the manager should end the + * current hinting session but immediately attempt to begin a new hinting + * session by querying registered providers. Otherwise, the provider should + * return a response object that contains three properties: * * 1. hints, a sorted array hints that the provider could later insert * into the editor; @@ -291,6 +293,8 @@ define(function (require, exports, module) { function _getProvidersForLanguageId(languageId) { return hintProviders[languageId] || hintProviders.all; } + + var _beginSession; /** * End the current hinting session @@ -348,23 +352,30 @@ define(function (require, exports, module) { if (!response) { // the provider wishes to close the session _endSession(); - } else if (response.hasOwnProperty("hints")) { // a synchronous response - if (hintList.isOpen()) { - // the session is open - hintList.update(response); - } else { - hintList.open(response); - } - } else { // response is a deferred - deferredHints = response; - response.done(function (hints) { + } else { + // if the response is true, end the session and begin another + if (response === true) { + var previousEditor = sessionEditor; + _endSession(); + _beginSession(previousEditor); + } else if (response.hasOwnProperty("hints")) { // a synchronous response if (hintList.isOpen()) { // the session is open - hintList.update(hints); + hintList.update(response); } else { - hintList.open(hints); + hintList.open(response); } - }); + } else { // response is a deferred + deferredHints = response; + response.done(function (hints) { + if (hintList.isOpen()) { + // the session is open + hintList.update(hints); + } else { + hintList.open(hints); + } + }); + } } } @@ -372,7 +383,7 @@ define(function (require, exports, module) { * Try to begin a new hinting session. * @param {Editor} editor */ - function _beginSession(editor) { + _beginSession = function (editor) { // Find a suitable provider, if any var language = editor.getLanguageForSelection(), enabledProviders = _getProvidersForLanguageId(language.getId()); @@ -403,7 +414,7 @@ define(function (require, exports, module) { } else { lastChar = null; } - } + }; /** * Handles keys related to displaying, searching, and navigating the hint list. From d337737baa8b6502fa553a0bb5db9980a08b59e2 Mon Sep 17 00:00:00 2001 From: Ian Wehrman Date: Wed, 15 May 2013 16:38:41 -0700 Subject: [PATCH 3/3] Update the CSS hinter so that it restarts the session when changing from property names to values to give other more specialized hinters (like EWF) a chance to intervene. --- src/extensions/default/CSSCodeHints/main.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/extensions/default/CSSCodeHints/main.js b/src/extensions/default/CSSCodeHints/main.js index 5e6fb7562d2..6eb75d3b10c 100644 --- a/src/extensions/default/CSSCodeHints/main.js +++ b/src/extensions/default/CSSCodeHints/main.js @@ -34,6 +34,10 @@ define(function (require, exports, module) { CSSProperties = require("text!CSSProperties.json"), properties = JSON.parse(CSSProperties); + // Context of the last request for hints: either CSSUtils.PROP_NAME, + // CSSUtils.PROP_VALUE or null. + var lastContext; + /** * @constructor */ @@ -63,6 +67,7 @@ define(function (require, exports, module) { this.editor = editor; var cursor = this.editor.getCursorPos(); + lastContext = null; this.info = CSSUtils.getInfoAtPos(editor, cursor); if (this.info.context !== CSSUtils.PROP_NAME && this.info.context !== CSSUtils.PROP_VALUE) { @@ -111,6 +116,14 @@ define(function (require, exports, module) { } if (context === CSSUtils.PROP_VALUE) { + // When switching from a NAME to a VALUE context, restart the session + // to give other more specialized providers a chance to intervene. + if (lastContext === CSSUtils.PROP_NAME) { + return true; + } else { + lastContext = CSSUtils.PROP_VALUE; + } + if (!properties[needle]) { return null; } @@ -133,6 +146,7 @@ define(function (require, exports, module) { selectInitial: selectInitial }; } else if (context === CSSUtils.PROP_NAME) { + lastContext = CSSUtils.PROP_NAME; needle = needle.substr(0, this.info.offset); result = $.map(properties, function (pvalues, pname) { if (pname.indexOf(needle) === 0) {