-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conversation
Also added fixes for two other cases @peterflynn mentioned. |
@peterflynn also added code to replace the entire token, when invoking the in hints inside a token. |
unit tests will be added in a separate pull after this got merged. |
We should really add unit tests here too -- both for some entity hinting cases and for the tag hinting cases that are currently broken (and which the existing tag hinting tests haven't caught). |
Oops sorry, just saw the above note about adding unit tests later. Ideally we like to do it all in one pull request, but this seems ok since we definitely need to get the fix part landed ASAP before sprint end. |
thats what i thougth ;) |
@@ -96,7 +96,7 @@ define(function (require, exports, module) { | |||
return query !== null; | |||
} | |||
|
|||
return implicitChar === "&" || query !== null; | |||
return query !== null; |
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:
if (implicitChar === null) {
return query !== null;
}
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:
return this._getQuery() !== null;
|
||
query = "&"; | ||
if (HTMLUtils.getTagInfo(this.editor, cursor).tagName !== "") { | ||
return null; |
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.
The variable name lineContent
should be more accurate so code is easier to understand, so rename to something like lineContentBeforeCursor
.
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.
Although you haven't changed it in this pull request, I just noticed this function:
There's no need to search for "#" because replace will do nothing if it's not found:
Question: Why is the semi-colon (;) not also encoded since it is decoded in the associated _decodeValue() function? In general, encode/decode functions should do the exact opposite of each other. |
Please don't push any changes until I say "review is complete". I'm looking at the code in both the github pull request diff and in Brackets, so it's making it difficult for me to keep them in sync. Thanks. |
sorry i'll certainly do so. function _encodeValue(value) {
return value.replace("&", "&").replace("#", "#").replace(";", ";");
} we would break the whole functionality because the replace would replace the semi-colons from the previous entities. function _encodeValue(value) {
return value.replace("&", "&").replace(";", ";").replace("#", "#");
} the hash of the semi-colon entity would be replaced. |
startChar = lineContent.lastIndexOf("&"); | ||
endChar = lineContent.lastIndexOf(";"); | ||
startChar = lineContentBeforeCursor.lastIndexOf("&"); | ||
endChar = lineContentBeforeCursor.lastIndexOf(";"); | ||
|
||
if (endChar < startChar) { |
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.
The logic here needs some cleanup:
if (endChar < startChar) {
query = this.editor.document.getRange({
line: cursor.line,
ch: startChar
}, cursor);
}
if (endChar < startChar) {
return query;
}
return null;
- No need to check for
(endChar < startChar)
twice. - The
(endChar < startChar)
condition relies on the fact that "not found" is represented by -1 so it seems a bit cryptic. Please reverse the logic and add a comment. - There was a check that startChar was found that got dropped. Maybe that was (cryptically) handled by the
endChar === startChar
case, but I think you need it here:
// If no startChar, or endChar is found after startChar, then not in an entity
if (startChar === -1 || endChar > startChar) {
return null;
}
query = this.editor.document.getRange({
line: cursor.line,
ch: startChar
}, cursor);
return query;
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.
you're right thats much more understandable.
Regarding "encoding the semi-colon": Unfortunately, it's not easy to do, but, if it's required, you just have to be smarter about it. In this code, I don't think it's required because |
Done with initial review. |
actually |
@redmunds fixes pushed. |
In the sorting function, I noticed this after I merged the original code: this line of code:
Can be simplified to:
This is because sort functions aren't limited to returning only -1, 0, or 1. They just need to return 0 if equal, or a positive or negative number to indicate greater than or less than. |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
match.indexOf(";")
is called twice, so it should be put in a var.
Done with second review. |
@redmunds changes pushed. |
Looks good. Merging. |
Fix #3339