From 990fe399abda2a2725d692b40fbd09bcedf170a5 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Thu, 4 Apr 2013 09:49:11 +0200 Subject: [PATCH 1/7] Logic fix --- src/extensions/default/HtmlEntityCodeHints/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/default/HtmlEntityCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js index 5f51e481560..7a1305ffed1 100644 --- a/src/extensions/default/HtmlEntityCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -192,7 +192,7 @@ define(function (require, exports, module) { }, this.editor.getCursorPos()); } - if (startChar !== -1 && HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos()).tagName === "") { + if (startChar !== -1 && HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos()).tagName === "" && endChar < startChar) { return query; } From edab6b81f4c02ad7692386104d43fd32c439fe95 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Thu, 4 Apr 2013 20:36:12 +0200 Subject: [PATCH 2/7] A few other cleanup fixes --- .../default/HtmlEntityCodeHints/main.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/extensions/default/HtmlEntityCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js index 7a1305ffed1..e29263f6452 100644 --- a/src/extensions/default/HtmlEntityCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -96,7 +96,7 @@ define(function (require, exports, module) { return query !== null; } - return implicitChar === "&" || query !== null; + return query !== null; }; /** @@ -120,7 +120,7 @@ define(function (require, exports, module) { var query, result; - if (this.primaryTriggerKeys.indexOf(implicitChar) !== -1 || implicitChar === null) { + if (implicitChar === null || this.primaryTriggerKeys.indexOf(implicitChar) !== -1) { this.currentQuery = query = this._getQuery(); result = $.map(specialChars, function (value, index) { if (value.indexOf(query) === 0) { @@ -129,7 +129,10 @@ define(function (require, exports, module) { } }).sort(this._internalSort); - query = _encodeValue(query); + if (query !== null) { + query = _encodeValue(query); + } + return { hints: result, match: query, @@ -170,6 +173,10 @@ define(function (require, exports, module) { * The Query for which to search */ SpecialCharHints.prototype._getQuery = function () { + if (HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos()).tagName !== "") { + return null; + } + var query, lineContent, startChar, @@ -192,7 +199,7 @@ define(function (require, exports, module) { }, this.editor.getCursorPos()); } - if (startChar !== -1 && HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos()).tagName === "" && endChar < startChar) { + if (startChar !== -1 && endChar < startChar) { return query; } From 5ae84c4c970270de911a67fc9b628b8c0630c8c8 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Fri, 5 Apr 2013 09:47:56 +0200 Subject: [PATCH 3/7] Fixed replacement when currently in Entity --- .../default/HtmlEntityCodeHints/main.js | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/extensions/default/HtmlEntityCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js index e29263f6452..99218e7304f 100644 --- a/src/extensions/default/HtmlEntityCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -173,30 +173,31 @@ define(function (require, exports, module) { * The Query for which to search */ SpecialCharHints.prototype._getQuery = function () { - if (HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos()).tagName !== "") { - return null; - } - var query, lineContent, startChar, - endChar; + endChar, + cursor = this.editor.getCursorPos(); + + if (HTMLUtils.getTagInfo(this.editor, cursor).tagName !== "") { + return null; + } query = "&"; lineContent = this.editor.document.getRange({ - line: this.editor.getCursorPos().line, + line: cursor.line, ch: 0 - }, this.editor.getCursorPos()); + }, cursor); startChar = lineContent.lastIndexOf("&"); endChar = lineContent.lastIndexOf(";"); if (endChar < startChar) { query = this.editor.document.getRange({ - line: this.editor.getCursorPos().line, + line: cursor.line, ch: startChar - }, this.editor.getCursorPos()); + }, cursor); } if (startChar !== -1 && endChar < startChar) { @@ -219,11 +220,19 @@ define(function (require, exports, module) { SpecialCharHints.prototype.insertHint = function (completion) { var start = {line: -1, ch: -1}, end = {line: -1, ch: -1}, - cursor = this.editor.getCursorPos(); + cursor = this.editor.getCursorPos(), + match; end.line = start.line = cursor.line; start.ch = cursor.ch - this.currentQuery.length; + match = this.editor.document.getLine(cursor.line).slice(cursor.ch); end.ch = start.ch + this.currentQuery.length; + + if (match.indexOf(";") !== -1 && /^(#*[0-9]+)|([a-zA-Z]+)$/.test(match.slice(0, match.indexOf(";")))) { + console.log("In Entity"); + end.ch = this.editor.document.getLine(cursor.line).indexOf(";", start.ch) + 1; + } + completion = completion.slice(0, completion.indexOf(" ")); completion = _decodeValue(completion); if (start.ch !== end.ch) { From 087fa43f5e05f318bdc6cdc166c02570f7b449f7 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Mon, 8 Apr 2013 20:34:11 +0200 Subject: [PATCH 4/7] A bit cleanup --- src/extensions/default/HtmlEntityCodeHints/main.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/extensions/default/HtmlEntityCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js index 99218e7304f..0a75bd795ff 100644 --- a/src/extensions/default/HtmlEntityCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -92,10 +92,6 @@ define(function (require, exports, module) { var query = this._getQuery(); - if (implicitChar === null) { - return query !== null; - } - return query !== null; }; @@ -182,8 +178,6 @@ define(function (require, exports, module) { if (HTMLUtils.getTagInfo(this.editor, cursor).tagName !== "") { return null; } - - query = "&"; lineContent = this.editor.document.getRange({ line: cursor.line, @@ -200,7 +194,7 @@ define(function (require, exports, module) { }, cursor); } - if (startChar !== -1 && endChar < startChar) { + if (endChar < startChar) { return query; } From b2002599346ad4dfdfb73b6a0d8ebe3914ddabe7 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Mon, 8 Apr 2013 20:50:36 +0200 Subject: [PATCH 5/7] Fix after review --- src/extensions/default/HtmlEntityCodeHints/main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/extensions/default/HtmlEntityCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js index 0a75bd795ff..8164fa51fc6 100644 --- a/src/extensions/default/HtmlEntityCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -170,7 +170,7 @@ define(function (require, exports, module) { */ SpecialCharHints.prototype._getQuery = function () { var query, - lineContent, + lineContentBeforeCursor, startChar, endChar, cursor = this.editor.getCursorPos(); @@ -179,13 +179,13 @@ define(function (require, exports, module) { return null; } - lineContent = this.editor.document.getRange({ + lineContentBeforeCursor = this.editor.document.getRange({ line: cursor.line, ch: 0 }, cursor); - startChar = lineContent.lastIndexOf("&"); - endChar = lineContent.lastIndexOf(";"); + startChar = lineContentBeforeCursor.lastIndexOf("&"); + endChar = lineContentBeforeCursor.lastIndexOf(";"); if (endChar < startChar) { query = this.editor.document.getRange({ From cd9004af49af34c8f2ddfd1b5016d7b30d2dd47b Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Mon, 8 Apr 2013 22:06:20 +0200 Subject: [PATCH 6/7] Fixes after first review --- .../default/HtmlEntityCodeHints/main.js | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/extensions/default/HtmlEntityCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js index 8164fa51fc6..4b86c4cd751 100644 --- a/src/extensions/default/HtmlEntityCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -46,7 +46,7 @@ define(function (require, exports, module) { * The encoded string */ function _encodeValue(value) { - return (value.indexOf("#") === -1) ? value.replace("&", "&") : value.replace("&", "&").replace("#", "#"); + return value.replace("&", "&").replace("#", "#"); } /** @@ -59,7 +59,7 @@ define(function (require, exports, module) { * The decoded string */ function _decodeValue(value) { - return value.replace("#", "#").replace("&", "&").replace(";", ";"); + return value.replace("&", "&").replace("#", "#"); } /** @@ -121,7 +121,7 @@ define(function (require, exports, module) { result = $.map(specialChars, function (value, index) { if (value.indexOf(query) === 0) { var shownValue = _encodeValue(value); - return shownValue + "; " + value + ";"; + return shownValue + "; " + value + ";"; } }).sort(this._internalSort); @@ -187,18 +187,17 @@ define(function (require, exports, module) { startChar = lineContentBeforeCursor.lastIndexOf("&"); endChar = lineContentBeforeCursor.lastIndexOf(";"); - if (endChar < startChar) { - query = this.editor.document.getRange({ - line: cursor.line, - ch: startChar - }, cursor); - } - - if (endChar < startChar) { - return query; + // If no startChar was found or the endChar is greater than the startChar then it is no entity + if (startChar === -1 || endChar > startChar) { + return null; } - - return null; + + query = this.editor.document.getRange({ + line: cursor.line, + ch: startChar + }, cursor); + + return query; }; /** @@ -223,7 +222,6 @@ define(function (require, exports, module) { end.ch = start.ch + this.currentQuery.length; if (match.indexOf(";") !== -1 && /^(#*[0-9]+)|([a-zA-Z]+)$/.test(match.slice(0, match.indexOf(";")))) { - console.log("In Entity"); end.ch = this.editor.document.getLine(cursor.line).indexOf(";", start.ch) + 1; } From e63ec5f9fce7e4dd3950d8f3a4b1af5827013309 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Tue, 9 Apr 2013 06:35:26 +0200 Subject: [PATCH 7/7] Fixes after second review --- src/extensions/default/HtmlEntityCodeHints/main.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/extensions/default/HtmlEntityCodeHints/main.js b/src/extensions/default/HtmlEntityCodeHints/main.js index 4b86c4cd751..4a8221afe72 100644 --- a/src/extensions/default/HtmlEntityCodeHints/main.js +++ b/src/extensions/default/HtmlEntityCodeHints/main.js @@ -89,10 +89,8 @@ define(function (require, exports, module) { */ SpecialCharHints.prototype.hasHints = function (editor, implicitChar) { this.editor = editor; - - var query = this._getQuery(); - return query !== null; + return this._getQuery() !== null; }; /** @@ -156,7 +154,7 @@ define(function (require, exports, module) { 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 (num1 - num2); } return a.localeCompare(b); @@ -214,14 +212,16 @@ define(function (require, exports, module) { var start = {line: -1, ch: -1}, end = {line: -1, ch: -1}, cursor = this.editor.getCursorPos(), - match; + match, + matchSemicolonPos; end.line = start.line = cursor.line; start.ch = cursor.ch - this.currentQuery.length; match = this.editor.document.getLine(cursor.line).slice(cursor.ch); + matchSemicolonPos = match.indexOf(";"); end.ch = start.ch + this.currentQuery.length; - if (match.indexOf(";") !== -1 && /^(#*[0-9]+)|([a-zA-Z]+)$/.test(match.slice(0, match.indexOf(";")))) { + if (matchSemicolonPos !== -1 && /^(#*[0-9]+)|([a-zA-Z]+)$/.test(match.slice(0, matchSemicolonPos))) { end.ch = this.editor.document.getLine(cursor.line).indexOf(";", start.ch) + 1; }