Added HtmlSpecialCharsCodeHints as default extension #3237
Changes from 1 commit
32f8988
36241a5
41816aa
f938314
de474ba
603fecb
8a8d29c
b2fa0b8
8f914fb
a9e89cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
[ | ||
"&lsquo", "&rsquo", "&sbquo", "&ldquo", "&rdquo", "&bdquo", | ||
"&dagger", "&Dagger", | ||
"&permil", | ||
"&lsaquo", "&rsaquo", | ||
"&spades", "&clubs", "&hearts", "&diams", | ||
"&oline", | ||
"&larr", "&uarr", "&rarr", "&darr", | ||
"&trade", | ||
""", | ||
"&", | ||
"&frasl", | ||
"<", | ||
">", | ||
"&hellip", | ||
"&ndash", "&mdash", | ||
" ", | ||
"¡", | ||
"¢", "£", "¤", "¥", | ||
"¦", | ||
"§", | ||
"¨", | ||
"&die", | ||
"©", | ||
"ª", | ||
"«", | ||
"¬", | ||
"­", | ||
"®", | ||
"¯", | ||
"°", | ||
"±", | ||
"¹", "²", "³", | ||
"´", | ||
"µ", | ||
"¶", | ||
"·", | ||
"¸", | ||
"º", | ||
"»", | ||
"¼", "½", "¾", | ||
"¿", | ||
"À", "Á", "Â", "Ã", "Ä", "Å", "Æ", | ||
"Ç", | ||
"È", "É", "Ê", "Ë", | ||
"Ì", "Í", "Î", "Ï", | ||
"Ð", | ||
"Ñ", | ||
"Ò", "Ó", "Ô", "Õ", "Ö", | ||
"×", | ||
"Ø", | ||
"Ù", "Ú", "Û", "Ü", | ||
"Ý", | ||
"Þ", | ||
"ß", | ||
"à", "á", "â", "ã", "ä", "å", "æ", | ||
"ç", | ||
"è", "é", "ê", "ë", | ||
"ì", "í", "î", "ï", | ||
"ð", | ||
"ñ", | ||
"ò", "ó", "ô", "õ", "ö", | ||
"÷", | ||
"ø", | ||
"ù", "ú", "û", "ü", | ||
"ý", | ||
"þ", | ||
"ÿ", | ||
"&Alpha", "&alpha", | ||
"&Beta", "&beta", | ||
"&Gamma", "&gamma", | ||
"&Delta", "&delta", | ||
"&Epsilon", "&epsilon", | ||
"&Zeta", "&zeta", | ||
"&Eta", "&eta", | ||
"&Theta", "&theta", | ||
"&Iota", "&iota", | ||
"&Kappa", "&kappa", | ||
"&Lambda", "&lambda", | ||
"&Mu", "&mu", | ||
"&Nu", "&nu", | ||
"&Xi", "&xi", | ||
"&Omicron", "&omicron", | ||
"&Pi", "&pi", | ||
"&Rho", "&rho", | ||
"&Sigma", "&sigma", | ||
"&Tau", "&tau", | ||
"&Upsilon", "&upsilon", | ||
"&Phi", "&phi", | ||
"&Chi", "&chi", | ||
"&Psi", "&psi", | ||
"&Omega", "&omega", | ||
|
||
"!", | ||
"#", "$", "%", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
"'", "(", ")", "*", "+", ",", "-", ".", | ||
":", ";", | ||
"=", | ||
"?", "@", | ||
"[", "\", "]", "^", "_", "`", | ||
"{", "|", "}", "~", | ||
"●", | ||
"•" | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/* | ||
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ | ||
/*global define, brackets, $ */ | ||
|
||
define(function (require, exports, module) { | ||
"use strict"; | ||
|
||
// Load dependent modules | ||
var AppInit = brackets.getModule("utils/AppInit"), | ||
CodeHintManager = brackets.getModule("editor/CodeHintManager"), | ||
HtmlSpecialChars = require("text!SpecialChars.json"), | ||
specialChars; | ||
|
||
/** | ||
* @constructor | ||
*/ | ||
function SpecialCharHints() { | ||
this.primaryTriggerKeys = "&ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#0123456789"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think "&" is the only trigger key that you need here, since that's the first char of every entity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those other keys have to be in there because otherwise the hinting sesssion would stop after typing another character after the ampersand. |
||
this.currentQuery = ""; | ||
} | ||
|
||
/** | ||
* Determines whether HtmlSpecialChar hints are available in the current editor | ||
* context. | ||
* | ||
* @param {Editor} editor | ||
* A non-null editor object for the active window. | ||
* | ||
* @param {String} implicitChar | ||
* Either null, if the hinting request was explicit, or a single character | ||
* that represents the last insertion and that indicates an implicit | ||
* hinting request. | ||
* | ||
* @return {Boolean} | ||
* Determines whether the current provider is able to provide hints for | ||
* the given editor context and, in case implicitChar is non- null, | ||
* whether it is appropriate to do so. | ||
*/ | ||
SpecialCharHints.prototype.hasHints = function (editor, implicitChar) { | ||
var tagInfo, | ||
query, | ||
range; | ||
|
||
this.editor = editor; | ||
|
||
if (implicitChar === null) { | ||
return false; | ||
} else { | ||
return implicitChar === "&"; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need
|
||
}; | ||
|
||
/** | ||
* Returns a list of avaliable HtmlSpecialChar hints if possible for the current | ||
* editor context. | ||
* | ||
* @param {String} implicitChar | ||
* Either null, if the hinting request was explicit, or a single character | ||
* that represents the last insertion and that indicates an implicit | ||
* hinting request. | ||
* | ||
* @return {Object<hints: Array<(String + jQuery.Obj)>, match: String, selectInitial: Boolean>} | ||
* Null if the provider wishes to end the hinting session. Otherwise, a | ||
* response object that provides 1. a sorted array hints that consists | ||
* of strings; 2. a string match that is used by the manager to emphasize | ||
* matching substrings when rendering the hint list; and 3. a boolean that | ||
* indicates whether the first result, if one exists, should be selected | ||
* by default in the hint list window. | ||
*/ | ||
SpecialCharHints.prototype.getHints = function (implicitChar) { | ||
var query, | ||
result; | ||
|
||
if (this.primaryTriggerKeys.indexOf(implicitChar) !== -1) { | ||
this.currentQuery = query = this._getQuery(); | ||
result = $.map(specialChars, function (value, index) { | ||
if (value.indexOf(query) === 0) { | ||
return value + " <span style=\"float: right;\">" + value + ";</span>"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a class and apply class to span tag, instead of inline css. Also, the code looks cleaner if you nest single-quotes inside of double-quotes:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, you should create a CSS file in your extension directory and load it with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i added that. |
||
} | ||
}).sort(); | ||
|
||
return { | ||
hints: result, | ||
match: query, | ||
selectInitial: true | ||
}; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
/** | ||
* Returns a query for the Hints | ||
* | ||
* @return {String} | ||
* The Query for which to search | ||
*/ | ||
SpecialCharHints.prototype._getQuery = function () { | ||
var query, | ||
lineContent, | ||
startChar, | ||
endChar; | ||
|
||
query = "&"; | ||
|
||
lineContent = this.editor.document.getRange({ | ||
line: this.editor.getCursorPos().line, | ||
ch: 0 | ||
}, this.editor.getCursorPos()); | ||
|
||
startChar = lineContent.lastIndexOf("&"); | ||
endChar = lineContent.lastIndexOf(";"); | ||
|
||
if (endChar < startChar) { | ||
query = this.editor.document.getRange({ | ||
line: this.editor.getCursorPos().line, | ||
ch: startChar | ||
}, this.editor.getCursorPos()); | ||
} | ||
|
||
return query; | ||
}; | ||
|
||
/** | ||
* Inserts a given HtmlSpecialChar hint into the current editor context. | ||
* | ||
* @param {String} hint | ||
* The hint to be inserted into the editor context. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameter name is |
||
* | ||
* @return {Boolean} | ||
* Indicates whether the manager should follow hint insertion with an | ||
* additional explicit hint request. | ||
*/ | ||
SpecialCharHints.prototype.insertHint = function (completion) { | ||
var start = {line: -1, ch: -1}, | ||
end = {line: -1, ch: -1}, | ||
cursor = this.editor.getCursorPos(); | ||
|
||
end.line = start.line = cursor.line; | ||
start.ch = cursor.ch - this.currentQuery.length; | ||
end.ch = start.ch + this.currentQuery.length; | ||
completion = completion.slice(0, completion.indexOf(" ")) + ";"; | ||
if (start.ch !== end.ch) { | ||
this.editor.document.replaceRange(completion, start, end); | ||
} else { | ||
this.editor.document.replaceRange(completion, start); | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
AppInit.appReady(function () { | ||
// Parse JSON files | ||
specialChars = JSON.parse(HtmlSpecialChars); | ||
|
||
// Register code hint providers | ||
var specialCharHints = new SpecialCharHints(); | ||
|
||
CodeHintManager.registerHintProvider(specialCharHints, ["html"], 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm seeing a weird problem in this case:
Results: It might have something to do with using a priority of 0 to register these hints, which is the default priority. On the other hand, there should be no conflicts with the HTML hints, so not really sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually it the problem is, that the HTML tags hint provider can also provide hints for those and gets called before the specialCharHints, but when i changed the priority to one plus a few other tweaks in the has hints function it worked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That problem is fixed, but I'm seeing another problem I think it related. Code hints work correctly inside of a tag, but if I type a "raw" & I don't get the hints. For example:
|
||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be easier to manage this list if it's a single column sorted alphabetically