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

Commit 04d518e

Browse files
committed
move html url hinting to a new hint provider
1 parent 799b3ef commit 04d518e

5 files changed

Lines changed: 481 additions & 185 deletions

File tree

src/extensions/default/HTMLCodeHints/HtmlAttributes.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
"headers": { "attribOption": [] },
139139
"height": { "attribOption": [] },
140140
"high": { "attribOption": [] },
141-
"href": { "attribOption": [], "type": "url" },
141+
"href": { "attribOption": [] },
142142
"hreflang": { "attribOption": [] },
143143
"hspace": { "attribOption": [] },
144144
"http-equiv": { "attribOption": ["content-type", "default-style", "refresh"] },
@@ -197,7 +197,7 @@
197197
"size": { "attribOption": [] },
198198
"sizes": { "attribOption": ["any"] },
199199
"span": { "attribOption": [] },
200-
"src": { "attribOption": [], "type": "url" },
200+
"src": { "attribOption": [] },
201201
"srcdoc": { "attribOption": [] },
202202
"srclang": { "attribOption": [] },
203203
"standby": { "attribOption": [] },

src/extensions/default/HTMLCodeHints/main.js

Lines changed: 1 addition & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ define(function (require, exports, module) {
162162
function AttrHints() {
163163
this.globalAttributes = this.readGlobalAttrHints();
164164
this.cachedHints = null;
165-
166-
// Used in URL hinting to keep the popup list open
167-
// by setting this to false.
168-
this.closeOnSelect = true;
169165
}
170166

171167
/**
@@ -181,162 +177,6 @@ define(function (require, exports, module) {
181177
});
182178
};
183179

184-
/**
185-
* Helper function for search(). Create a list of urls to existing files based on the query.
186-
* @param {{queryStr: string}} query -- a query object, used to filter the code hints
187-
* @return {Array.<string>}
188-
*/
189-
AttrHints.prototype._getUrlList = function (query) {
190-
var doc,
191-
result = [];
192-
193-
// site-root relative links are not yet supported, so filter them out
194-
if (query.queryStr.length > 0 && query.queryStr[0] === "/") {
195-
return result;
196-
}
197-
198-
// get path to current document
199-
doc = DocumentManager.getCurrentDocument();
200-
if (!doc || !doc.file) {
201-
return result;
202-
}
203-
204-
var docUrl = window.PathUtils.parseUrl(doc.file.fullPath);
205-
if (!docUrl) {
206-
return result;
207-
}
208-
209-
var docDir = docUrl.domain + docUrl.directory;
210-
211-
// get relative path from query string
212-
// TODO: handle site-root relative
213-
var queryDir = "";
214-
var queryUrl = window.PathUtils.parseUrl(query.queryStr);
215-
if (queryUrl) {
216-
queryDir = queryUrl.directory;
217-
}
218-
219-
// build target folder path
220-
var targetDir = docDir + decodeURI(queryDir);
221-
222-
// get list of files from target folder
223-
var unfiltered = [];
224-
225-
// Getting the file/folder info is an asynch operation, so it works like this:
226-
//
227-
// The initial pass initiates the asynchronous retrieval of data and returns an
228-
// empty list, so no code hints are displayed. In the async callback, the code
229-
// hints and the original query are stored in a cache, and then the process to
230-
// show code hints is re-initiated.
231-
//
232-
// During the next pass, there should now be code hints cached from the initial
233-
// pass, but user may have typed while file/folder info was being retrieved from
234-
// disk, so we need to make sure code hints still apply to current query. If so,
235-
// display them, otherwise, clear cache and start over.
236-
//
237-
// As user types within a folder, the same unfiltered file/folder list is still
238-
// valid and re-used from cache. Filtering based on user input is done outside
239-
// of this method. When user moves to a new folder, then the cache is deleted,
240-
// and file/folder info for new folder is then retrieved.
241-
242-
if (this.cachedHints) {
243-
// url hints have been cached, so determine if they're stale
244-
if (!this.cachedHints.query ||
245-
this.cachedHints.query.tag !== query.tag ||
246-
this.cachedHints.query.attrName !== query.attrName ||
247-
this.cachedHints.queryDir !== queryDir ||
248-
this.cachedHints.docDir !== docDir) {
249-
250-
// delete stale cache
251-
this.cachedHints = null;
252-
}
253-
}
254-
255-
if (this.cachedHints) {
256-
// use cached hints
257-
unfiltered = this.cachedHints.unfiltered;
258-
259-
} else {
260-
var self = this,
261-
origEditor = EditorManager.getFocusedEditor();
262-
263-
if (self.cachedHints && self.cachedHints.deferred) {
264-
self.cachedHints.deferred.reject();
265-
}
266-
// create empty object so we can detect "waiting" state
267-
self.cachedHints = {};
268-
self.cachedHints.deferred = $.Deferred();
269-
self.cachedHints.unfiltered = [];
270-
271-
NativeFileSystem.requestNativeFileSystem(targetDir, function (fs) {
272-
fs.root.createReader().readEntries(function (entries) {
273-
274-
entries.forEach(function (entry) {
275-
if (ProjectManager.shouldShow(entry)) {
276-
// convert to doc relative path
277-
var entryStr = entry.fullPath.replace(docDir, "");
278-
279-
// code hints show the same strings that are inserted into text,
280-
// so strings in list will be encoded. wysiwyg, baby!
281-
unfiltered.push(encodeURI(entryStr));
282-
}
283-
});
284-
285-
self.cachedHints.unfiltered = unfiltered;
286-
self.cachedHints.query = query;
287-
self.cachedHints.queryDir = queryDir;
288-
self.cachedHints.docDir = docDir;
289-
290-
if (!self.cachedHints.deferred.isRejected()) {
291-
var currentDeferred = self.cachedHints.deferred;
292-
// Since we've cached the results, the next call to _getUrlList should be synchronous.
293-
// If it isn't, we've got a problem and should reject both the current deferred
294-
// and any new deferred that got created on the call.
295-
var syncResults = self._getUrlList(query);
296-
if (syncResults instanceof Array) {
297-
currentDeferred.resolveWith(self, [syncResults]);
298-
} else {
299-
if (currentDeferred && !currentDeferred.isResolved() && !currentDeferred.isRejected()) {
300-
currentDeferred.reject();
301-
}
302-
303-
if (self.cachedHints.deferred &&
304-
!self.cachedHints.deferred.isResolved() &&
305-
!self.cachedHints.deferred.isRejected()) {
306-
self.cachedHints.deferred.reject();
307-
self.cachedHints.deferred = null;
308-
}
309-
}
310-
}
311-
});
312-
});
313-
314-
return self.cachedHints.deferred;
315-
}
316-
317-
// build list
318-
319-
// without these entries, typing "../" will not display entries for containing folder
320-
if (queryUrl.filename === ".") {
321-
result.push(queryDir + ".");
322-
} else if (queryUrl.filename === "..") {
323-
result.push(queryDir + "..");
324-
}
325-
326-
// add file/folder entries
327-
unfiltered.forEach(function (item) {
328-
result.push(item);
329-
});
330-
331-
// TODO: filter by desired file type based on tag, type attr, etc.
332-
333-
// TODO: add list item to top of list to popup modal File Finder dialog
334-
// New string: "Browse..." or "Choose a File..."
335-
// Command: Commands.FILE_OPEN
336-
337-
return result;
338-
};
339-
340180
/**
341181
* Helper function that determins the possible value hints for a given html tag/attribute name pair
342182
*
@@ -367,11 +207,6 @@ define(function (require, exports, module) {
367207
if (attrInfo) {
368208
if (attrInfo.type === "boolean") {
369209
hints = ["false", "true"];
370-
} else if (attrInfo.type === "url") {
371-
// Default behavior for url hints is do not close on select.
372-
this.closeOnSelect = false;
373-
hints = this._getUrlList(query);
374-
sortFunc = StringUtils.urlSort;
375210
} else if (attrInfo.attribOption) {
376211
hints = attrInfo.attribOption;
377212
}
@@ -498,8 +333,6 @@ define(function (require, exports, module) {
498333
hints = [],
499334
sortFunc = null;
500335

501-
this.closeOnSelect = true;
502-
503336
if (attrName) {
504337
var hintsAndSortFunc = this._getValueHintsForAttr(query, tagName, attrName);
505338
hints = hintsAndSortFunc.hints;
@@ -573,13 +406,7 @@ define(function (require, exports, module) {
573406
}
574407
} else if (tokenType === HTMLUtils.ATTR_VALUE) {
575408
charCount = tagInfo.attr.value.length;
576-
577-
// Special handling for URL hinting -- if the completion is a file name
578-
// and not a folder, then close the code hint list.
579-
if (!this.closeOnSelect && completion.match(/\/$/) === null) {
580-
this.closeOnSelect = true;
581-
}
582-
409+
583410
if (!tagInfo.attr.hasEndQuote) {
584411
endQuote = tagInfo.attr.quoteChar;
585412
if (endQuote) {
@@ -604,15 +431,6 @@ define(function (require, exports, module) {
604431
}
605432
}
606433

607-
if (!this.closeOnSelect) {
608-
// If we append the missing quote, then we need to adjust the cursor postion
609-
// to keep the code hint list open.
610-
if (tokenType === HTMLUtils.ATTR_VALUE && !tagInfo.attr.hasEndQuote) {
611-
this.editor.setCursorPos(start.line, start.ch + completion.length - 1);
612-
}
613-
return true;
614-
}
615-
616434
if (insertedName) {
617435
this.editor.setCursorPos(start.line, start.ch + completion.length - 1);
618436

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"background-image": {"values": [] },
3+
"border-image": {"values": [] },
4+
"list-style-image": {"values": [] }
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"href": { "attribOption": [] },
3+
"src": { "attribOption": [] }
4+
}

0 commit comments

Comments
 (0)