-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Quick Edit result grouping #9614
Changes from 5 commits
3acf985
54c98fb
85fa143
e428ea9
8687f61
2e4402e
071cd33
f60710e
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 |
---|---|---|
|
@@ -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,50 @@ 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) | ||
*/ | ||
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 +296,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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1793,7 +1793,7 @@ define(function (require, exports, module) { | |
* Sets the height of an inline widget in this editor. | ||
* @param {!InlineWidget} inlineWidget The widget whose height should be set. | ||
* @param {!number} height The height of the widget. | ||
* @param {boolean} ensureVisible Whether to scroll the entire widget into view. | ||
* @param {?boolean} ensureVisible Whether to scroll the entire widget into view. Default false. | ||
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. Type annotation with default value should be 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. There's a subtle difference -- 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.
That is incorrect. According to this page: "Indicates that an argument in a function type is optional. An optional argument can be omitted from the function call. An optional argument cannot precede a non-optional argument in the argument list." (highlighting by me) 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. Interesting. There's some ambiguity there because it doesn't say whether it's talking about formal vs. actual parameters, but I think your interpretation is most likely correct. That disagrees with how some of our existing code uses (e.g. all of FileSystem), but since that usage now seems incorrect I'll change it to |
||
*/ | ||
Editor.prototype.setInlineWidgetHeight = function (inlineWidget, height, ensureVisible) { | ||
var self = this, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,7 @@ define(function (require, exports, module) { | |
/** | ||
* Update the inline editor's height when the number of lines change. The | ||
* base implementation of this method does nothing. | ||
* @param {boolean} force the editor to resize | ||
* @param {boolean} force the editor to resize (ignored) | ||
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. Method does nothing at all -- why did you feel it was necessary to indicate that the parameter is ignored? 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 I should just finish what I started and entirely remove this completely unused arg... |
||
*/ | ||
InlineTextEditor.prototype.sizeInlineWidgetToContents = function (force) { | ||
// brackets_codemirror_overrides.css adds height:auto to CodeMirror | ||
|
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