Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

url hinting support #1747

Merged
merged 8 commits into from
Oct 5, 2012
Merged

url hinting support #1747

merged 8 commits into from
Oct 5, 2012

Conversation

redmunds
Copy link
Contributor

@redmunds redmunds commented Oct 2, 2012

Added a new code hinting type of "url".

Retrieving directory info is asynchronous, so had to cache results and re-initiate code hints. Also use cached info as long as query is in same folder, so very performant.

Current support:

  • page relative urls
  • filter on input
  • "../" path support
  • use Tab key for "select and continue hinting"
  • fix sorting for Windows (i.e. folders first, then files)

Not yet supported (https://trello.com/c/nZx8Z3Ti):

  • filter by desired file type based on tag, type attr, etc.
    • e.g. only show .css, .less, etc. files for
  • add list item to popup modal File Finder dialog
  • make code hints window wider
  • site-root relative urls

@ghost ghost assigned RaymondLim Oct 3, 2012
@RaymondLim
Copy link
Contributor

Reviewing....

@@ -274,6 +402,8 @@ define(function (require, exports, module) {
if (attrInfo) {
if (attrInfo.type === "boolean") {
unfiltered = ["false", "true"];
} else if (attrInfo.type === "url") {
unfiltered = this._getUrlList(query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see you encoding the path for unsafe characters like '(', ')', or space character in _getUrlList. If you're not going to show encoded urls in code hints, then at least you have to encode it before insertion. You also need to decode query before passing it to _getUrlList so that it can match to items in code hint list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The encoded url is shown in the list and inserted in the page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I prefer the other solution. But I think it is acceptable to show encoded url in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to implement what you described, but it's too hard to get filtering correct. Part of the reason is that it implies you can, for example, filter by typing a space char when %20 will get inserted in page, which is a conflict . I think it's best to show user encoded url and they learn how they should really look, so I think this is the best solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite if we have to consider double-byte characters and high-ascii characters. Anyway, we can leave it for users who can't stand to read encoded url to log an issue.

@RaymondLim
Copy link
Contributor

Done initial review.

@@ -285,6 +415,7 @@ define(function (require, exports, module) {
}

if (unfiltered.length) {
console.assert(!result.length);
result = $.map(unfiltered, function (item) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For folder and file sorting you need to call your custom sort() function here instead of $.map().sort().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I pass a custom sorting function to sort().

@redmunds
Copy link
Contributor Author

redmunds commented Oct 5, 2012

Changes for code review pushed.

// create empty object so we can detect "waiting" state
self.cachedHints = {};
self.cachedHints.unfiltered = [];
self.cachedHints.waiting = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see you checking on this boolean cachedHints.waiting. If you don't need it anymore, then you should remove all instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed. I ran into a problem where the waiting flag got stuck on so cache was never cleared. Now, we just return the list whether it had items or not.


// code hints show the same strings that are inserted into text,
// so strings in list will be encoded. wysiwyg, baby!
unfiltered.push(encodeURI(entryStr));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encodeURI won't encode '?' and ';' that can be used in filenames. We may have to consider encodeURIComponent or a combination of escape and encodeURI. I can't remember what we did for our default brackets folder path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just encoding existing file and folder names retrieved from disk. So, there won't be any '?' or ';' chars. This is not user input.

Maybe I do not understand your concern.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an existing filename or folder name has these characters, then we won't be encoding them after url insertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same encoding function we use every where in Brackets so I'm not sure why it's an issue for this feature. Since this is just a bonus feature, can we add this issue to the followup user story?
https://trello.com/c/nZx8Z3Ti

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. I'm just trying to help you making this bonus feature better. I will try to find the potential issue with these characters later in Brackets.

@RaymondLim
Copy link
Contributor

Done reviewing new changes.

RaymondLim added a commit that referenced this pull request Oct 5, 2012
@RaymondLim RaymondLim merged commit a856faa into master Oct 5, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants