From 32f89886b523b971bc4d1d9413093dbd499ceaa0 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Sun, 24 Mar 2013 17:09:29 +0100 Subject: [PATCH 01/10] Added HtmlSpecialCharsCodeHints as default extension --- .../SpecialChars.json | 104 ++++++++++ .../default/HtmlSpecialCharsCodeHints/main.js | 184 ++++++++++++++++++ 2 files changed, 288 insertions(+) create mode 100644 src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json create mode 100644 src/extensions/default/HtmlSpecialCharsCodeHints/main.js diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json b/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json new file mode 100644 index 00000000000..beeffcc54fa --- /dev/null +++ b/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json @@ -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", + + "!", + "#", "$", "%", + "'", "(", ")", "*", "+", ",", "-", ".", + ":", ";", + "=", + "?", "@", + "[", "\", "]", "^", "_", "`", + "{", "|", "}", "~", + "●", + "•" +] \ No newline at end of file diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/main.js b/src/extensions/default/HtmlSpecialCharsCodeHints/main.js new file mode 100644 index 00000000000..6f1a12834b5 --- /dev/null +++ b/src/extensions/default/HtmlSpecialCharsCodeHints/main.js @@ -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"; + 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 === "&"; + } + }; + + /** + * 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, 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 + " " + value + ";"; + } + }).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. + * + * @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); + }); +}); \ No newline at end of file From 36241a5d6cd8cb7a1ca2e7a539372f93ebf1d47d Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Tue, 26 Mar 2013 09:41:17 +0100 Subject: [PATCH 02/10] A few fixes after review --- .../default/HtmlSpecialCharsCodeHints/main.js | 35 ++++++++++++------- .../HtmlSpecialCharsCodeHints/styles.css | 3 ++ 2 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 src/extensions/default/HtmlSpecialCharsCodeHints/styles.css diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/main.js b/src/extensions/default/HtmlSpecialCharsCodeHints/main.js index 6f1a12834b5..bbea7f1c0e5 100644 --- a/src/extensions/default/HtmlSpecialCharsCodeHints/main.js +++ b/src/extensions/default/HtmlSpecialCharsCodeHints/main.js @@ -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; @@ -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; } }; @@ -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 + " " + value + ";"; + return value.replace("#", "#") + " " + value + ";"; } - }).sort(); - + }).sort(function (a, b) { + a = a.toLowerCase(); + b = b.toLowerCase(); + return (a === b) ? 0 : (a > b) ? 1 : -1; + }); + console.log(result); + query = query.replace("#", "#"); return { hints: result, match: query, @@ -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; + } }; /** @@ -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("#", "#"); if (start.ch !== end.ch) { this.editor.document.replaceRange(completion, start, end); } else { @@ -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); }); }); \ No newline at end of file diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/styles.css b/src/extensions/default/HtmlSpecialCharsCodeHints/styles.css new file mode 100644 index 00000000000..a0904516bb2 --- /dev/null +++ b/src/extensions/default/HtmlSpecialCharsCodeHints/styles.css @@ -0,0 +1,3 @@ +span.entity-display-character { + float: right; +} \ No newline at end of file From 41816aa9e14c32ac57601b8ae6a7f60e6bace822 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Tue, 26 Mar 2013 11:18:16 +0100 Subject: [PATCH 03/10] A bit cleanup --- .../SpecialChars.json | 278 ++++++++++++------ .../default/HtmlSpecialCharsCodeHints/main.js | 4 +- 2 files changed, 192 insertions(+), 90 deletions(-) diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json b/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json index beeffcc54fa..d781d935fdf 100644 --- a/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json +++ b/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json @@ -1,104 +1,206 @@ [ - "&lsquo", "&rsquo", "&sbquo", "&ldquo", "&rdquo", "&bdquo", - "&dagger", "&Dagger", - "&permil", - "&lsaquo", "&rsaquo", - "&spades", "&clubs", "&hearts", "&diams", - "&oline", - "&larr", "&uarr", "&rarr", "&darr", - "&trade", - """, + "{", + "|", + "}", + "~", + "!", + "#", + "$", + "%", + "'", + "(", + ")", + "*", + "+", + ",", + "-", + ".", + ":", + ";", + "=", + "?", + "@", + "•", + "[", + "\", + "]", + "^", + "_", + "`", + "●", + + "á", + "Á", + "â", + "Â", + "´", + "æ", + "Æ", + "à", + "À", + "&alpha", + "&Alpha", "&", + "å", + "Å", + "ã", + "Ã", + "ä", + "Ä", + "&bdquo", + "&beta", + "&Beta", + "¦", + "ç", + "Ç", + "¸", + "¢", + "&chi", + "&Chi", + "&clubs", + "©", + "¤", + "&dagger", + "&Dagger", + "&darr", + "°", + "&delta", + "&Delta", + "&diams", + "&die", + "÷", + "é", + "É", + "ê", + "Ê", + "è", + "È", + "&epsilon", + "&Epsilon", + "&eta", + "&Eta", + "ð", + "Ð", + "ë", + "Ë", + "½", + "¼", + "¾", "&frasl", - "<", + "&gamma", + "&Gamma", ">", + "&hearts", "&hellip", - "&ndash", "&mdash", - " ", + "í", + "Í", + "î", + "Î", "¡", - "¢", "£", "¤", "¥", - "¦", - "§", - "¨", - "&die", - "©", - "ª", + "ì", + "Ì", + "&iota", + "&Iota", + "¿", + "ï", + "Ï", + "&kappa", + "&Kappa", + "&lambda", + "&Lambda", "«", - "¬", - "­", - "®", + "&larr", + "&ldquo", + "&lsaquo", + "&lsquo", + "<", "¯", - "°", - "±", - "¹", "²", "³", - "´", + "&mdash", "µ", - "¶", "·", - "¸", - "º", - "»", - "¼", "½", "¾", - "¿", - "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", - "Ç", - "È", "É", "Ê", "Ë", - "Ì", "Í", "Î", "Ï", - "Ð", + "&mu", + "&Mu", + " ", + "&ndash", + "¬", + "ñ", "Ñ", - "Ò", "Ó", "Ô", "Õ", "Ö", - "×", + "&nu", + "&Nu", + "ó", + "Ó", + "ô", + "Ô", + "ò", + "Ò", + "&oline", + "&omega", + "&Omega", + "&omicron", + "&Omicron", + "ª", + "º", + "ø", "Ø", - "Ù", "Ú", "Û", "Ü", - "Ý", - "Þ", + "õ", + "Õ", + "ö", + "Ö", + "¶", + "&permil", + "&phi", + "&Phi", + "&pi", + "&Pi", + "±", + "£", + "&psi", + "&Psi", + """, + "»", + "&rarr", + "&rdquo", + "®", + "&rho", + "&Rho", + "&rsaquo", + "&rsquo", + "&sbquo", + "§", + "­", + "&sigma", + "&Sigma", + "&spades", + "¹", + "²", + "³", "ß", - "à", "á", "â", "ã", "ä", "å", "æ", - "ç", - "è", "é", "ê", "ë", - "ì", "í", "î", "ï", - "ð", - "ñ", - "ò", "ó", "ô", "õ", "ö", - "÷", - "ø", - "ù", "ú", "û", "ü", - "ý", + "&tau", + "&Tau", + "&theta", + "&Theta", "þ", + "Þ", + "×", + "&trade", + "ú", + "Ú", + "&uarr", + "û", + "Û", + "ù", + "Ù", + "¨", + "&upsilon", + "&Upsilon", + "ü", + "Ü", + "&xi", + "&Xi", + "ý", + "Ý", + "¥", "ÿ", - "&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", - - "!", - "#", "$", "%", - "'", "(", ")", "*", "+", ",", "-", ".", - ":", ";", - "=", - "?", "@", - "[", "\", "]", "^", "_", "`", - "{", "|", "}", "~", - "●", - "•" + "&zeta", + "&Zeta" ] \ No newline at end of file diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/main.js b/src/extensions/default/HtmlSpecialCharsCodeHints/main.js index bbea7f1c0e5..321d4f65c04 100644 --- a/src/extensions/default/HtmlSpecialCharsCodeHints/main.js +++ b/src/extensions/default/HtmlSpecialCharsCodeHints/main.js @@ -103,9 +103,9 @@ define(function (require, exports, module) { }).sort(function (a, b) { a = a.toLowerCase(); b = b.toLowerCase(); - return (a === b) ? 0 : (a > b) ? 1 : -1; + return a.localeCompare(b); }); - console.log(result); + query = query.replace("#", "#"); return { hints: result, From f93831446158aef5e3076b78d6a3b7b989d5d41e Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Tue, 26 Mar 2013 11:39:57 +0100 Subject: [PATCH 04/10] Workaround for a display bug --- src/extensions/default/HtmlSpecialCharsCodeHints/main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/main.js b/src/extensions/default/HtmlSpecialCharsCodeHints/main.js index 321d4f65c04..e6b4c645bd5 100644 --- a/src/extensions/default/HtmlSpecialCharsCodeHints/main.js +++ b/src/extensions/default/HtmlSpecialCharsCodeHints/main.js @@ -98,7 +98,8 @@ define(function (require, exports, module) { this.currentQuery = query = this._getQuery(); result = $.map(specialChars, function (value, index) { if (value.indexOf(query) === 0) { - return value.replace("#", "#") + " " + value + ";"; + var shownValue = (value.indexOf("#") === -1) ? value.replace("&", "&") : value.replace("#", "#"); + return shownValue + " " + value + ";"; } }).sort(function (a, b) { a = a.toLowerCase(); @@ -106,7 +107,7 @@ define(function (require, exports, module) { return a.localeCompare(b); }); - query = query.replace("#", "#"); + query = (query.indexOf("#") === -1) ? query.replace("&", "&") : query.replace("#", "#"); return { hints: result, match: query, @@ -172,7 +173,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("#", "#"); + completion = completion.replace("#", "#").replace("&", "&"); if (start.ch !== end.ch) { this.editor.document.replaceRange(completion, start, end); } else { From de474ba0b3c887ec65f85552e0b605dd8963b3d2 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Tue, 26 Mar 2013 12:19:42 +0100 Subject: [PATCH 05/10] Included a few missing special chars --- .../SpecialChars.json | 75 ++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json b/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json index d781d935fdf..82798f26c63 100644 --- a/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json +++ b/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json @@ -38,11 +38,15 @@ "Æ", "à", "À", + "&alefsym", "&alpha", "&Alpha", "&", + "&and", + "&ang", "å", "Å", + "&asyp", "ã", "Ã", "ä", @@ -51,18 +55,25 @@ "&beta", "&Beta", "¦", + "&bull", + "&cap", "ç", "Ç", "¸", "¢", "&chi", "&Chi", + "&circ", "&clubs", + "&cong", "©", + "&crarr", + "&cup", "¤", "&dagger", "&Dagger", "&darr", + "&dArr", "°", "&delta", "&Delta", @@ -75,21 +86,31 @@ "Ê", "è", "È", + "&empty", + "&emsp", + "&ensp", "&epsilon", "&Epsilon", + "&equiv", "&eta", "&Eta", "ð", "Ð", "ë", "Ë", + "&euro", + "&exists", + "&forall", "½", "¼", "¾", "&frasl", "&gamma", "&Gamma", + "&ge", ">", + "&harr", + "&hArr", "&hearts", "&hellip", "í", @@ -99,18 +120,30 @@ "¡", "ì", "Ì", + "&image", + "&infin", + "&int", "&iota", "&Iota", "¿", + "&isin", "ï", "Ï", "&kappa", "&Kappa", "&lambda", "&Lambda", + "&lang", "«", "&larr", + "&lArr", + "&lceil", "&ldquo", + "&le", + "&lfloor", + "&lowast", + "&loz", + "&lrm", "&lsaquo", "&lsquo", "<", @@ -118,11 +151,17 @@ "&mdash", "µ", "·", + "&minus", "&mu", "&Mu", + "&nabla", " ", "&ndash", + "&ne", + "&ni", "¬", + "¬in", + "&nsub", "ñ", "Ñ", "&nu", @@ -138,63 +177,96 @@ "&Omega", "&omicron", "&Omicron", + "&oplus", + "&or", "ª", "º", "ø", "Ø", "õ", "Õ", + "&otimes", "ö", "Ö", "¶", + "&part", "&permil", + "&perp", "&phi", "&Phi", "&pi", "&Pi", + "&piv", "±", "£", + "&prime", + "&Prime", + "&prod", + "&prop", "&psi", "&Psi", """, + "&radic", + "&rang", "»", "&rarr", + "&rArr", + "&rceil", "&rdquo", + "&real", "®", + "&rfloor", "&rho", "&Rho", + "&rlm", "&rsaquo", "&rsquo", "&sbquo", + "&Scaron", + "&scaron", + "&sdot", "§", "­", "&sigma", "&Sigma", + "&sim", "&spades", + "&sub", + "&sube", + "&sum", + "&sup", + "&supe", "¹", "²", "³", "ß", "&tau", "&Tau", + "&there4", "&theta", "&Theta", + "&thetasym", + "&thinsp", "þ", "Þ", "×", + "&tilde", "&trade", "ú", "Ú", "&uarr", + "&uArr", "û", "Û", "ù", "Ù", "¨", + "&upsih", "&upsilon", "&Upsilon", "ü", "Ü", + "&weierp", "&xi", "&Xi", "ý", @@ -202,5 +274,6 @@ "¥", "ÿ", "&zeta", - "&Zeta" + "&Zeta", + "&zwnj" ] \ No newline at end of file From 603fecb8fa5fb78128873deeab3b3118a512aeef Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Wed, 27 Mar 2013 18:52:10 +0100 Subject: [PATCH 06/10] Adressed issues after second review --- samples/de/Erste Schritte/Unbenannt/main.html | 0 .../SpecialChars.json | 12 ++-- .../main.js | 65 ++++++++++++++----- .../styles.css | 0 4 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 samples/de/Erste Schritte/Unbenannt/main.html rename src/extensions/default/{HtmlSpecialCharsCodeHints => HtmlEntityCodeHints}/SpecialChars.json (99%) rename src/extensions/default/{HtmlSpecialCharsCodeHints => HtmlEntityCodeHints}/main.js (77%) rename src/extensions/default/{HtmlSpecialCharsCodeHints => HtmlEntityCodeHints}/styles.css (100%) diff --git a/samples/de/Erste Schritte/Unbenannt/main.html b/samples/de/Erste Schritte/Unbenannt/main.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json b/src/extensions/default/HtmlEntityCodeHints/SpecialChars.json similarity index 99% rename from src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json rename to src/extensions/default/HtmlEntityCodeHints/SpecialChars.json index 82798f26c63..1a1868bc919 100644 --- a/src/extensions/default/HtmlSpecialCharsCodeHints/SpecialChars.json +++ b/src/extensions/default/HtmlEntityCodeHints/SpecialChars.json @@ -1,8 +1,4 @@ [ - "{", - "|", - "}", - "~", "!", "#", "$", @@ -20,13 +16,17 @@ "=", "?", "@", - "•", "[", "\", "]", "^", "_", "`", + "{", + "|", + "}", + "~", + "•", "●", "á", @@ -46,7 +46,6 @@ "&ang", "å", "Å", - "&asyp", "ã", "Ã", "ä", @@ -99,7 +98,6 @@ "ë", "Ë", "&euro", - "&exists", "&forall", "½", "¼", diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js similarity index 77% rename from src/extensions/default/HtmlSpecialCharsCodeHints/main.js rename to src/extensions/default/HtmlEntityCodeHints/main.js index e6b4c645bd5..32d9ef42728 100644 --- a/src/extensions/default/HtmlSpecialCharsCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -68,9 +68,9 @@ define(function (require, exports, module) { if (implicitChar === null) { return query !== null; - } else { - return implicitChar === "&" || query !== null; } + + return implicitChar === "&" || query !== null; }; /** @@ -92,22 +92,31 @@ define(function (require, exports, module) { */ SpecialCharHints.prototype.getHints = function (implicitChar) { var query, - result; + result, + self = this; if (this.primaryTriggerKeys.indexOf(implicitChar) !== -1 || implicitChar === null) { this.currentQuery = query = this._getQuery(); result = $.map(specialChars, function (value, index) { if (value.indexOf(query) === 0) { - var shownValue = (value.indexOf("#") === -1) ? value.replace("&", "&") : value.replace("#", "#"); - return shownValue + " " + value + ";"; + var shownValue = self._encodeValue(value); + return shownValue + "; " + value + ";"; } }).sort(function (a, b) { - a = a.toLowerCase(); - b = b.toLowerCase(); + a = self._decodeValue(a.slice(0, a.indexOf(" "))).toLowerCase(); + b = self._decodeValue(b.slice(0, b.indexOf(" "))).toLowerCase(); + if (a.indexOf("#") !== -1 && b.indexOf("#") !== -1) { + console.log(); + var num1 = parseInt(a.slice(a.indexOf("#") + 1, a.length - 1), 10), + num2 = parseInt(b.slice(b.indexOf("#") + 1, b.length - 1), 10); + + return (num1 === num2) ? 0 : (num1 > num2) ? 1 : -1; + } + return a.localeCompare(b); }); - query = (query.indexOf("#") === -1) ? query.replace("&", "&") : query.replace("#", "#"); + query = this._encodeValue(query); return { hints: result, match: query, @@ -118,6 +127,32 @@ define(function (require, exports, module) { return null; }; + /** + * Encodes the special Char value given. + * + * @param {String} value + * The value to encode + * + * @return {String} + * The encoded string + */ + SpecialCharHints.prototype._encodeValue = function (value) { + return (value.indexOf("#") === -1) ? value.replace("&", "&") : value.replace("&", "&").replace("#", "#"); + }; + + /** + * Decodes the special Char value given. + * + * @param {String} value + * The value to decode + * + * @return {String} + * The decoded string + */ + SpecialCharHints.prototype._decodeValue = function (value) { + return value.replace("#", "#").replace("&", "&").replace(";", ";"); + }; + /** * Returns a query for the Hints * @@ -146,18 +181,18 @@ define(function (require, exports, module) { ch: startChar }, this.editor.getCursorPos()); } - - if (startChar !== -1 && HTMLUtils.getTagAttributes(this.editor, this.editor.getCursorPos()).length === 0) { + console.log(HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos())); + if (startChar !== -1 && HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos()).tagName === "") { return query; - } else { - return null; } + + return null; }; /** * Inserts a given HtmlSpecialChar hint into the current editor context. * - * @param {String} hint + * @param {String} completition * The hint to be inserted into the editor context. * * @return {Boolean} @@ -172,8 +207,8 @@ define(function (require, exports, module) { 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(" ")) + ";"; - completion = completion.replace("#", "#").replace("&", "&"); + completion = completion.slice(0, completion.indexOf(" ")); + completion = this._decodeValue(completion); if (start.ch !== end.ch) { this.editor.document.replaceRange(completion, start, end); } else { diff --git a/src/extensions/default/HtmlSpecialCharsCodeHints/styles.css b/src/extensions/default/HtmlEntityCodeHints/styles.css similarity index 100% rename from src/extensions/default/HtmlSpecialCharsCodeHints/styles.css rename to src/extensions/default/HtmlEntityCodeHints/styles.css From 8a8d29c42ae8ce3cfee2a925022596f31c27fd44 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Wed, 27 Mar 2013 18:55:30 +0100 Subject: [PATCH 07/10] Addressed issues after second review --- src/extensions/default/HtmlEntityCodeHints/main.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/extensions/default/HtmlEntityCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js index 32d9ef42728..616fcf43412 100644 --- a/src/extensions/default/HtmlEntityCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -106,7 +106,6 @@ define(function (require, exports, module) { a = self._decodeValue(a.slice(0, a.indexOf(" "))).toLowerCase(); b = self._decodeValue(b.slice(0, b.indexOf(" "))).toLowerCase(); if (a.indexOf("#") !== -1 && b.indexOf("#") !== -1) { - console.log(); var num1 = parseInt(a.slice(a.indexOf("#") + 1, a.length - 1), 10), num2 = parseInt(b.slice(b.indexOf("#") + 1, b.length - 1), 10); @@ -181,7 +180,7 @@ define(function (require, exports, module) { ch: startChar }, this.editor.getCursorPos()); } - console.log(HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos())); + if (startChar !== -1 && HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos()).tagName === "") { return query; } From b2fa0b8a07d65317a413fac8b3731381d02aabf9 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Wed, 27 Mar 2013 19:04:36 +0100 Subject: [PATCH 08/10] Fixed two typos --- src/extensions/default/HtmlEntityCodeHints/SpecialChars.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/extensions/default/HtmlEntityCodeHints/SpecialChars.json b/src/extensions/default/HtmlEntityCodeHints/SpecialChars.json index 1a1868bc919..3c1493d216a 100644 --- a/src/extensions/default/HtmlEntityCodeHints/SpecialChars.json +++ b/src/extensions/default/HtmlEntityCodeHints/SpecialChars.json @@ -46,6 +46,7 @@ "&ang", "å", "Å", + "&asymp", "ã", "Ã", "ä", @@ -98,6 +99,7 @@ "ë", "Ë", "&euro", + "&exist", "&forall", "½", "¼", From 8f914fbb2ac8eea0549d0a611dd47bbbda5adb60 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Wed, 27 Mar 2013 19:21:40 +0100 Subject: [PATCH 09/10] Fixed an error while committing --- samples/de/Erste Schritte/Unbenannt/main.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 samples/de/Erste Schritte/Unbenannt/main.html diff --git a/samples/de/Erste Schritte/Unbenannt/main.html b/samples/de/Erste Schritte/Unbenannt/main.html deleted file mode 100644 index e69de29bb2d..00000000000 From a9e89cfa2ec1700c1e575994e467550584852de5 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Wed, 27 Mar 2013 20:39:49 +0100 Subject: [PATCH 10/10] Fixed issues after third review --- .../default/HtmlEntityCodeHints/main.js | 77 +++++++++++-------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/src/extensions/default/HtmlEntityCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js index 616fcf43412..5f51e481560 100644 --- a/src/extensions/default/HtmlEntityCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -36,6 +36,32 @@ define(function (require, exports, module) { HtmlSpecialChars = require("text!SpecialChars.json"), specialChars; + /** + * Encodes the special Char value given. + * + * @param {String} value + * The value to encode + * + * @return {String} + * The encoded string + */ + function _encodeValue(value) { + return (value.indexOf("#") === -1) ? value.replace("&", "&") : value.replace("&", "&").replace("#", "#"); + } + + /** + * Decodes the special Char value given. + * + * @param {String} value + * The value to decode + * + * @return {String} + * The decoded string + */ + function _decodeValue(value) { + return value.replace("#", "#").replace("&", "&").replace(";", ";"); + } + /** * @constructor */ @@ -92,30 +118,18 @@ define(function (require, exports, module) { */ SpecialCharHints.prototype.getHints = function (implicitChar) { var query, - result, - self = this; + result; if (this.primaryTriggerKeys.indexOf(implicitChar) !== -1 || implicitChar === null) { this.currentQuery = query = this._getQuery(); result = $.map(specialChars, function (value, index) { if (value.indexOf(query) === 0) { - var shownValue = self._encodeValue(value); + var shownValue = _encodeValue(value); return shownValue + "; " + value + ";"; } - }).sort(function (a, b) { - a = self._decodeValue(a.slice(0, a.indexOf(" "))).toLowerCase(); - b = self._decodeValue(b.slice(0, b.indexOf(" "))).toLowerCase(); - if (a.indexOf("#") !== -1 && b.indexOf("#") !== -1) { - var num1 = parseInt(a.slice(a.indexOf("#") + 1, a.length - 1), 10), - num2 = parseInt(b.slice(b.indexOf("#") + 1, b.length - 1), 10); - - return (num1 === num2) ? 0 : (num1 > num2) ? 1 : -1; - } - - return a.localeCompare(b); - }); + }).sort(this._internalSort); - query = this._encodeValue(query); + query = _encodeValue(query); return { hints: result, match: query, @@ -127,20 +141,7 @@ define(function (require, exports, module) { }; /** - * Encodes the special Char value given. - * - * @param {String} value - * The value to encode - * - * @return {String} - * The encoded string - */ - SpecialCharHints.prototype._encodeValue = function (value) { - return (value.indexOf("#") === -1) ? value.replace("&", "&") : value.replace("&", "&").replace("#", "#"); - }; - - /** - * Decodes the special Char value given. + * Sort function used internally when sorting the Hints * * @param {String} value * The value to decode @@ -148,8 +149,18 @@ define(function (require, exports, module) { * @return {String} * The decoded string */ - SpecialCharHints.prototype._decodeValue = function (value) { - return value.replace("#", "#").replace("&", "&").replace(";", ";"); + SpecialCharHints.prototype._internalSort = function (a, b) { + a = _decodeValue(a.slice(0, a.indexOf(" "))).toLowerCase(); + b = _decodeValue(b.slice(0, b.indexOf(" "))).toLowerCase(); + + if (a.indexOf("#") !== -1 && b.indexOf("#") !== -1) { + var num1 = parseInt(a.slice(a.indexOf("#") + 1, a.length - 1), 10), + num2 = parseInt(b.slice(b.indexOf("#") + 1, b.length - 1), 10); + + return (num1 === num2) ? 0 : (num1 > num2) ? 1 : -1; + } + + return a.localeCompare(b); }; /** @@ -207,7 +218,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 = this._decodeValue(completion); + completion = _decodeValue(completion); if (start.ch !== end.ch) { this.editor.document.replaceRange(completion, start, end); } else {