Skip to content

Commit

Permalink
A few fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
WebsiteDeveloper committed Mar 26, 2013
1 parent 32f8988 commit 36241a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/extensions/default/HtmlSpecialCharsCodeHints/main.js
Expand Up @@ -31,6 +31,8 @@ define(function (require, exports, module) {
// Load dependent modules
var AppInit = brackets.getModule("utils/AppInit"),
CodeHintManager = brackets.getModule("editor/CodeHintManager"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
HTMLUtils = brackets.getModule("language/HTMLUtils"),
HtmlSpecialChars = require("text!SpecialChars.json"),
specialChars;

Expand Down Expand Up @@ -60,16 +62,14 @@ define(function (require, exports, module) {
* whether it is appropriate to do so.
*/
SpecialCharHints.prototype.hasHints = function (editor, implicitChar) {
var tagInfo,
query,
range;

this.editor = editor;

var query = this._getQuery();

if (implicitChar === null) {
return false;
return query !== null;
} else {
return implicitChar === "&";
return implicitChar === "&" || query !== null;
}
};

Expand All @@ -94,14 +94,19 @@ define(function (require, exports, module) {
var query,
result;

if (this.primaryTriggerKeys.indexOf(implicitChar) !== -1) {
if (this.primaryTriggerKeys.indexOf(implicitChar) !== -1 || implicitChar === null) {
this.currentQuery = query = this._getQuery();
result = $.map(specialChars, function (value, index) {
if (value.indexOf(query) === 0) {
return value + " <span style=\"float: right;\">" + value + ";</span>";
return value.replace("#", "&#35;") + " <span class='entity-display-character'>" + value + ";</span>";
}
}).sort();

}).sort(function (a, b) {
a = a.toLowerCase();
b = b.toLowerCase();
return (a === b) ? 0 : (a > b) ? 1 : -1;

This comment has been minimized.

Copy link
@TomMalbran

TomMalbran Mar 26, 2013

You could use return a.localeCompare(b). I am not sure if the > works as expected for strings. And you should remove the log from the next line.

This comment has been minimized.

Copy link
@WebsiteDeveloper

WebsiteDeveloper Mar 26, 2013

Author Owner

yeah i will remove that in the next commit.

});
console.log(result);
query = query.replace("#", "&#35;");
return {
hints: result,
match: query,
Expand Down Expand Up @@ -141,7 +146,11 @@ define(function (require, exports, module) {
}, this.editor.getCursorPos());
}

return query;
if (startChar !== -1 && HTMLUtils.getTagAttributes(this.editor, this.editor.getCursorPos()).length === 0) {
return query;
} else {
return null;
}
};

/**
Expand All @@ -163,6 +172,7 @@ define(function (require, exports, module) {
start.ch = cursor.ch - this.currentQuery.length;
end.ch = start.ch + this.currentQuery.length;
completion = completion.slice(0, completion.indexOf(" ")) + ";";
completion = completion.replace("&#35;", "#");
if (start.ch !== end.ch) {
this.editor.document.replaceRange(completion, start, end);
} else {
Expand All @@ -173,12 +183,13 @@ define(function (require, exports, module) {
};

AppInit.appReady(function () {
ExtensionUtils.loadStyleSheet(module, "styles.css");
// Parse JSON files
specialChars = JSON.parse(HtmlSpecialChars);

// Register code hint providers
var specialCharHints = new SpecialCharHints();

CodeHintManager.registerHintProvider(specialCharHints, ["html"], 0);
CodeHintManager.registerHintProvider(specialCharHints, ["html"], 1);
});
});
3 changes: 3 additions & 0 deletions src/extensions/default/HtmlSpecialCharsCodeHints/styles.css
@@ -0,0 +1,3 @@
span.entity-display-character {
float: right;
}

0 comments on commit 36241a5

Please sign in to comment.