-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix for Issue 3339 #3340
Fix for Issue 3339 #3340
Changes from 6 commits
990fe39
edab6b8
5ae84c4
087fa43
b200259
cd9004a
e63ec5f
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 |
---|---|---|
|
@@ -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("#", "#"); | ||
} | ||
|
||
/** | ||
|
@@ -92,11 +92,7 @@ define(function (require, exports, module) { | |
|
||
var query = this._getQuery(); | ||
|
||
if (implicitChar === null) { | ||
return query !== null; | ||
} | ||
|
||
return implicitChar === "&" || query !== null; | ||
return query !== null; | ||
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. Original comment seemed to be buried in a hidden "Outdated Diff", so adding again. Sorry for the dupe. Don't need query var, so this can be simplified more:
|
||
}; | ||
|
||
/** | ||
|
@@ -120,16 +116,19 @@ 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) { | ||
var shownValue = _encodeValue(value); | ||
return shownValue + "; <span class='entity-display-character'>" + value + ";</span>"; | ||
return shownValue + "; <span class='entity-display-character'>" + value + ";</span>"; | ||
} | ||
}).sort(this._internalSort); | ||
|
||
query = _encodeValue(query); | ||
if (query !== null) { | ||
query = _encodeValue(query); | ||
} | ||
|
||
return { | ||
hints: result, | ||
match: query, | ||
|
@@ -171,32 +170,34 @@ define(function (require, exports, module) { | |
*/ | ||
SpecialCharHints.prototype._getQuery = function () { | ||
var query, | ||
lineContent, | ||
lineContentBeforeCursor, | ||
startChar, | ||
endChar; | ||
endChar, | ||
cursor = this.editor.getCursorPos(); | ||
|
||
query = "&"; | ||
if (HTMLUtils.getTagInfo(this.editor, cursor).tagName !== "") { | ||
return null; | ||
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. The variable name 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. |
||
} | ||
|
||
lineContent = this.editor.document.getRange({ | ||
line: this.editor.getCursorPos().line, | ||
lineContentBeforeCursor = this.editor.document.getRange({ | ||
line: cursor.line, | ||
ch: 0 | ||
}, this.editor.getCursorPos()); | ||
}, cursor); | ||
|
||
startChar = lineContent.lastIndexOf("&"); | ||
endChar = lineContent.lastIndexOf(";"); | ||
startChar = lineContentBeforeCursor.lastIndexOf("&"); | ||
endChar = lineContentBeforeCursor.lastIndexOf(";"); | ||
|
||
if (endChar < startChar) { | ||
query = this.editor.document.getRange({ | ||
line: this.editor.getCursorPos().line, | ||
ch: startChar | ||
}, this.editor.getCursorPos()); | ||
} | ||
|
||
if (startChar !== -1 && HTMLUtils.getTagInfo(this.editor, this.editor.getCursorPos()).tagName === "") { | ||
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; | ||
}; | ||
|
||
/** | ||
|
@@ -212,11 +213,18 @@ 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(";")))) { | ||
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.
|
||
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) { | ||
|
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.
This method now returns
query !== null
in all cases, so remove this block: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.
Fixed.
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.
Sorry, but now that you made that change, I can see that you don't need query var, and this can simply be: