This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Quick Edit result grouping #9614
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3acf985
Initial implementation of Quick Edit grouping the results list by fil…
peterflynn 54c98fb
Quick Edit grouping fixes:
peterflynn 85fa143
Merge remote-tracking branch 'origin/master' into pflynn/quick-edit-g…
peterflynn e428ea9
- Consistently sort files: CSS below preprocessors, then sorted by pa…
peterflynn 8687f61
- Simplify code that renders the rule list (esp _createListItem(), which
peterflynn 2e4402e
Merge remote-tracking branch 'origin/master' into pflynn/quick-edit-g…
peterflynn 071cd33
- Quick Edit: if user expands collapsed section and nothing selected …
peterflynn f60710e
Quick Edit: don't show filename on each result item anymore, since it's
peterflynn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,9 @@ define(function (require, exports, module) { | |
DocumentManager = require("document/DocumentManager"), | ||
EditorManager = require("editor/EditorManager"), | ||
Editor = require("editor/Editor").Editor, | ||
LanguageManager = require("language/LanguageManager"), | ||
ProjectManager = require("project/ProjectManager"), | ||
FileUtils = require("file/FileUtils"), | ||
HTMLUtils = require("language/HTMLUtils"), | ||
MultiRangeInlineEditor = require("editor/MultiRangeInlineEditor"), | ||
Strings = require("strings"), | ||
|
@@ -146,7 +148,7 @@ define(function (require, exports, module) { | |
/** Item renderer for stylesheet-picker dropdown */ | ||
function _stylesheetListRenderer(item) { | ||
var html = "<span class='stylesheet-name'>" + _.escape(item.name); | ||
if (item.subDirStr.length) { | ||
if (item.subDirStr) { | ||
html += "<span class='stylesheet-dir'> — " + _.escape(item.subDirStr) + "</span>"; | ||
} | ||
html += "</span>"; | ||
|
@@ -240,65 +242,52 @@ define(function (require, exports, module) { | |
|
||
/** | ||
* @private | ||
* Sort fileInfo objects by name then sub-directory | ||
* Sort files with LESS/SCSS above CSS, and then within each grouping sort by path & filename | ||
* (the same order we use for Find in Files) | ||
* @param {!File} a, b | ||
* @return {number} | ||
*/ | ||
function _sortFileInfos(a, b) { | ||
var nameComparison = a.name.localeCompare(b.name); | ||
if (nameComparison !== 0) { | ||
return nameComparison; | ||
function _fileComparator(a, b) { | ||
var aIsCSS = LanguageManager.getLanguageForPath(a.fullPath).getId() === "css", | ||
bIsCSS = LanguageManager.getLanguageForPath(b.fullPath).getId() === "css"; | ||
if (aIsCSS && !bIsCSS) { | ||
return 1; | ||
} else if (!aIsCSS && bIsCSS) { | ||
return -1; | ||
} else { | ||
return FileUtils.comparePaths(a.fullPath, b.fullPath); | ||
} | ||
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. FYI, the next version of JSLint flags an error when there is no default return statement (which I generally agree with), so I think this should be changed to: if (aIsCSS && !bIsCSS) {
return 1;
} else if (!aIsCSS && bIsCSS) {
return -1;
}
return FileUtils.comparePaths(a.fullPath, b.fullPath); 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. I think that's one of the reasons we chose not to update to that version :-) Personally, I prefer the structure the way it is so all return cases have matching indent... |
||
return a.subDirStr.localeCompare(b.subDirStr); | ||
} | ||
|
||
/** | ||
* @private | ||
* Prepare file list for display | ||
*/ | ||
function _prepFileList(fileInfos) { | ||
var i, j, firstDupeIndex, | ||
displayPaths = [], | ||
dupeList = []; | ||
function _prepFileList(files) { | ||
// First, sort list (the same ordering we use for the results list) | ||
files.sort(_fileComparator); | ||
|
||
// Add subdir field to each entry | ||
fileInfos.forEach(function (fileInfo) { | ||
fileInfo.subDirStr = ""; | ||
}); | ||
|
||
// Add directory path to files with the same name so they can be | ||
// distinguished in list. Start with list sorted by name. | ||
fileInfos.sort(_sortFileInfos); | ||
|
||
// For identical names, add a subdir | ||
for (i = 1; i < fileInfos.length; i++) { | ||
if (_sortFileInfos(fileInfos[i - 1], fileInfos[i]) === 0) { | ||
// Duplicates found | ||
firstDupeIndex = i - 1; | ||
dupeList.push(fileInfos[i - 1]); | ||
dupeList.push(fileInfos[i]); | ||
|
||
// Lookahead for more dupes | ||
while (++i < fileInfos.length && | ||
_sortFileInfos(dupeList[0], fileInfos[i]) === 0) { | ||
dupeList.push(fileInfos[i]); | ||
} | ||
|
||
// Get minimum subdir to make each unique | ||
displayPaths = ViewUtils.getDirNamesForDuplicateFiles(dupeList); | ||
|
||
// Add a subdir to each dupe entry | ||
for (j = 0; j < displayPaths.length; j++) { | ||
fileInfos[firstDupeIndex + j].subDirStr = displayPaths[j]; | ||
} | ||
|
||
// Release memory | ||
dupeList = []; | ||
// Find any files that share the same name (with different path) | ||
var fileNames = {}; | ||
files.forEach(function (file) { | ||
if (!fileNames[file.name]) { | ||
fileNames[file.name] = []; | ||
} | ||
} | ||
fileNames[file.name].push(file); | ||
}); | ||
|
||
// Sort by name again, so paths are sorted | ||
fileInfos.sort(_sortFileInfos); | ||
// For any duplicate filenames, set subDirStr to a path snippet the helps | ||
// the user distinguish each file in the list. | ||
_.forEach(fileNames, function (files) { | ||
if (files.length > 1) { | ||
var displayPaths = ViewUtils.getDirNamesForDuplicateFiles(files); | ||
files.forEach(function (file, i) { | ||
file.subDirStr = displayPaths[i]; | ||
}); | ||
} | ||
}); | ||
|
||
return fileInfos; | ||
return files; | ||
} | ||
|
||
function _onHostEditorScroll() { | ||
|
@@ -309,7 +298,8 @@ define(function (require, exports, module) { | |
.done(function (rules) { | ||
var inlineEditorDeferred = new $.Deferred(); | ||
cssInlineEditor = new MultiRangeInlineEditor.MultiRangeInlineEditor(CSSUtils.consolidateRules(rules), | ||
_getNoRulesMsg, CSSUtils.getRangeSelectors); | ||
_getNoRulesMsg, CSSUtils.getRangeSelectors, | ||
_fileComparator); | ||
cssInlineEditor.load(hostEditor); | ||
cssInlineEditor.$htmlContent | ||
.on("focusin", _updateCommands) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
No
@return
annotation