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

Commit 5a05eaa

Browse files
committed
Merge pull request #9507 from adobe/jeff/wsv-perf-mods
Working Performance Set Improvements
2 parents a77e34b + bd8bc11 commit 5a05eaa

File tree

5 files changed

+174
-81
lines changed

5 files changed

+174
-81
lines changed

src/editor/EditorManager.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,15 @@ define(function (require, exports, module) {
470470
* Semi-private: should only be called within this module or by Document.
471471
* @param {!Document} document Document whose main/full Editor to create
472472
* @param {!Pane} pane Pane in which the editor will be hosted
473+
* @return {!Editor}
473474
*/
474475
function _createFullEditorForDocument(document, pane) {
475476
// Create editor; make it initially invisible
476477
var editor = _createEditorForDocument(document, true, pane.$content);
477478
editor.setVisible(false);
478479
pane.addView(editor);
479480
$(exports).triggerHandler("_fullEditorCreatedForDocument", [document, editor, pane.id]);
481+
return editor;
480482
}
481483

482484

@@ -535,32 +537,31 @@ define(function (require, exports, module) {
535537
editor = document._masterEditor;
536538

537539
if (!editor) {
538-
createdNewEditor = true;
539-
540540
// Performance (see #4757) Chrome wastes time messing with selection
541541
// that will just be changed at end, so clear it for now
542542
if (window.getSelection && window.getSelection().empty) { // Chrome
543543
window.getSelection().empty();
544544
}
545545

546546
// Editor doesn't exist: populate a new Editor with the text
547-
_createFullEditorForDocument(document, pane);
548-
} else if (editor.$el.parent() !== pane.$el) {
547+
editor = _createFullEditorForDocument(document, pane);
548+
createdNewEditor = true;
549+
} else if (editor.$el.parent()[0] !== pane.$content[0]) {
549550
// editor does exist but is not a child of the pane so add it to the
550551
// pane (which will switch the view's container as well)
551552
pane.addView(editor);
552553
}
553554

554555
// show the view
555-
pane.showView(document._masterEditor);
556+
pane.showView(editor);
556557

557558
if (MainViewManager.getActivePaneId() === pane.id) {
558559
// give it focus
559-
document._masterEditor.focus();
560+
editor.focus();
560561
}
561562

562563
if (createdNewEditor) {
563-
_restoreEditorViewState(document._masterEditor);
564+
_restoreEditorViewState(editor);
564565
}
565566
}
566567

src/project/FileViewController.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ define(function (require, exports, module) {
129129
return;
130130
}
131131

132-
_fileSelectionFocus = fileSelectionFocus;
133-
$(exports).triggerHandler("fileViewFocusChange");
132+
if (_fileSelectionFocus !== fileSelectionFocus) {
133+
_fileSelectionFocus = fileSelectionFocus;
134+
$(exports).triggerHandler("fileViewFocusChange");
135+
}
134136
}
135137

136138
/**

src/project/WorkingSetView.js

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ define(function (require, exports, module) {
3434
"use strict";
3535

3636
// Load dependent modules
37-
var DocumentManager = require("document/DocumentManager"),
37+
var AppInit = require("utils/AppInit"),
38+
DocumentManager = require("document/DocumentManager"),
3839
MainViewManager = require("view/MainViewManager"),
3940
CommandManager = require("command/CommandManager"),
4041
Commands = require("command/Commands"),
@@ -69,6 +70,12 @@ define(function (require, exports, module) {
6970
var _classProviders = [];
7071

7172

73+
/**
74+
* #working-set-list-container
75+
* @type {jQuery}
76+
*/
77+
var $workingFilesContainer;
78+
7279
/**
7380
* Constants for event.which values
7481
* @enum {number}
@@ -97,6 +104,12 @@ define(function (require, exports, module) {
97104
BELOWVIEW = "belowview",
98105
ABOVEVIEW = "aboveview";
99106

107+
/**
108+
* Drag an item has to move 3px before dragging starts
109+
* @constant
110+
*/
111+
var _DRAG_MOVE_DETECTION_START = 3;
112+
100113
/**
101114
* Refreshes all Pane View List Views
102115
*/
@@ -129,7 +142,6 @@ define(function (require, exports, module) {
129142
*/
130143
function _updateListItemSelection(listItem, selectedFile) {
131144
var shouldBeSelected = (selectedFile && $(listItem).data(_FILE_KEY).fullPath === selectedFile.fullPath);
132-
133145
ViewUtils.toggleClass($(listItem), "selected", shouldBeSelected);
134146
}
135147

@@ -263,19 +275,43 @@ define(function (require, exports, module) {
263275
dragged = false,
264276
startPageY = e.pageY,
265277
lastPageY = startPageY,
266-
itemHeight = $el.height(),
278+
lastHit = { where: NOMANSLAND },
267279
tryClosing = $(e.target).hasClass("can-close"),
268-
offset = $el.offset(),
269-
$copy = $el.clone(),
270-
$ghost = $("<div class='open-files-container wsv-drag-ghost' style='overflow: hidden; display: inline-block;'>").append($("<ul>").append($copy).css("padding", "0")),
271-
sourceView = _viewFromEl($el),
272280
currentFile = MainViewManager.getCurrentlyViewedFile(),
273281
activePaneId = MainViewManager.getActivePaneId(),
274282
activeView = _views[activePaneId],
275-
draggingCurrentFile = ($el.hasClass("selected") && sourceView.paneId === activePaneId),
276-
startingIndex = MainViewManager.findInWorkingSet(sourceView.paneId, sourceFile.fullPath),
283+
sourceView = _viewFromEl($el),
277284
currentView = sourceView,
278-
lastHit = { where: NOMANSLAND };
285+
startingIndex = $el.index(),
286+
itemHeight,
287+
offset,
288+
$copy,
289+
$ghost,
290+
draggingCurrentFile;
291+
292+
function initDragging() {
293+
itemHeight = $el.height();
294+
offset = $el.offset();
295+
$copy = $el.clone();
296+
$ghost = $("<div class='open-files-container wsv-drag-ghost' style='overflow: hidden; display: inline-block;'>").append($("<ul>").append($copy).css("padding", "0"));
297+
draggingCurrentFile = ($el.hasClass("selected") && sourceView.paneId === activePaneId);
298+
299+
// setup our ghost element as position absolute
300+
// so we can put it wherever we want to while dragging
301+
if (draggingCurrentFile && _hasSelectionFocus()) {
302+
$ghost.addClass("dragging-current-file");
303+
}
304+
305+
$ghost.css({
306+
top: offset.top,
307+
left: offset.left,
308+
width: $el.width() + 8
309+
});
310+
311+
// this will give the element the appearence that it's ghosted if the user
312+
// drags the element out of the view and goes off into no mans land
313+
$ghost.appendTo($("body"));
314+
}
279315

280316
// Switches the view context to match the hit context
281317
function updateContext(hit) {
@@ -294,7 +330,6 @@ define(function (require, exports, module) {
294330
hasScroller = false,
295331
onTopScroller = false,
296332
onBottomScroller = false,
297-
$workingFilesContainer = $("#working-set-list-container"),
298333
$container,
299334
$hit,
300335
$item,
@@ -564,7 +599,7 @@ define(function (require, exports, module) {
564599
// The drag function
565600
function drag(e) {
566601
if (!dragged) {
567-
602+
initDragging();
568603
// sort redraw and scroll shadows
569604
// cause problems during drag so disable them
570605
_suppressSortRedrawForAllViews(true);
@@ -576,7 +611,7 @@ define(function (require, exports, module) {
576611
_deactivateAllViews(true);
577612

578613
// add a "dragging" class to the outer container
579-
$("#working-set-list-container").addClass("dragging");
614+
$workingFilesContainer.addClass("dragging");
580615

581616
// add a class to the element we're dragging if
582617
// it's the currently selected file so that we
@@ -654,13 +689,15 @@ define(function (require, exports, module) {
654689
}
655690
}
656691

657-
// move the drag affordance
658-
$ghost.css("top", $ghost.offset().top + (e.pageY - lastPageY));
659-
692+
// Reposition the drag affordance if we've started dragging
693+
if ($ghost) {
694+
$ghost.css("top", $ghost.offset().top + (e.pageY - lastPageY));
695+
}
696+
660697
// if we have't started dragging yet then we wait until
661698
// the mouse has moved 3 pixels before we start dragging
662699
// to avoid the item moving when clicked or double clicked
663-
if (dragged || Math.abs(e.pageY - startPageY) > 3) {
700+
if (dragged || Math.abs(e.pageY - startPageY) > _DRAG_MOVE_DETECTION_START) {
664701
drag(e);
665702
}
666703

@@ -681,19 +718,21 @@ define(function (require, exports, module) {
681718

682719
// Close down the drag operation
683720
function preDropCleanup() {
684-
$("#working-set-list-container").removeClass("dragging");
685-
$("#working-set-list-container .drag-show-as-selected").removeClass("drag-show-as-selected");
686-
endScroll($el);
687-
// re-activate the views (adds the "active" class to the view that was previously active)
688-
_deactivateAllViews(false);
689-
// turn scroll wheel back on
690721
window.onmousewheel = window.document.onmousewheel = null;
691722
$(window).off(".wsvdragging");
692-
$ghost.remove();
693-
$el.css("opacity", "");
723+
if (dragged) {
724+
$workingFilesContainer.removeClass("dragging");
725+
$workingFilesContainer.find(".drag-show-as-selected").removeClass("drag-show-as-selected");
726+
endScroll($el);
727+
// re-activate the views (adds the "active" class to the view that was previously active)
728+
_deactivateAllViews(false);
729+
// turn scroll wheel back on
730+
$ghost.remove();
731+
$el.css("opacity", "");
694732

695-
if (dragged && $el.next().length === 0) {
696-
scrollCurrentViewToBottom();
733+
if ($el.next().length === 0) {
734+
scrollCurrentViewToBottom();
735+
}
697736
}
698737
}
699738

@@ -800,21 +839,7 @@ define(function (require, exports, module) {
800839
return;
801840
}
802841

803-
// setup our ghost element as position absolute
804-
// so we can put it wherever we want to while dragging
805-
if (draggingCurrentFile && _hasSelectionFocus()) {
806-
$ghost.addClass("dragging-current-file");
807-
}
808842

809-
$ghost.css({
810-
top: offset.top,
811-
left: offset.left,
812-
width: $el.width() + 8
813-
});
814-
815-
// this will give the element the appearence that it's ghosted if the user
816-
// drags the element out of the view and goes off into no mans land
817-
$ghost.appendTo($("body"));
818843

819844
e.stopPropagation();
820845
});
@@ -1435,6 +1460,11 @@ define(function (require, exports, module) {
14351460
refresh(true);
14361461
}
14371462

1463+
AppInit.htmlReady(function () {
1464+
$workingFilesContainer = $("#working-set-list-container");
1465+
});
1466+
1467+
14381468
// Public API
14391469
exports.createWorkingSetViewForPane = createWorkingSetViewForPane;
14401470
exports.refresh = refresh;

src/view/MainViewManager.js

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,8 @@ define(function (require, exports, module) {
370370
oldPaneId]);
371371

372372
_makePaneMostRecent(_activePaneId);
373+
focusActivePane();
373374
}
374-
375-
focusActivePane();
376375
}
377376

378377
/**
@@ -1128,24 +1127,27 @@ define(function (require, exports, module) {
11281127
* Do not use this API unless you have a document object without a file object
11291128
* @param {!string} paneId - id of the pane in which to open the document
11301129
* @param {!Document} doc - document to edit
1131-
* @param {{noPaneActivate:boolean}=} optionsIn - options
1130+
* @param {{noPaneActivate:boolean=, noPaneRedundancyCheck:boolean=}=} optionsIn - options
11321131
* @private
11331132
*/
11341133
function _edit(paneId, doc, optionsIn) {
1135-
var currentPaneId = _getPaneIdForPath(doc.file.fullPath),
1136-
options = optionsIn || {};
1137-
1138-
1134+
var options = optionsIn || {},
1135+
currentPaneId;
1136+
1137+
if (options.noPaneRedundancyCheck) {
1138+
// This flag is for internal use only to improve performance
1139+
// Don't check for the file to have been opened in another pane pane which could be time
1140+
// consuming. should only be used when passing an actual paneId (not a special paneId)
1141+
// and the caller has already done a redundancy check.
1142+
currentPaneId = _getPaneIdForPath(doc.file.fullPath);
1143+
}
1144+
11391145
if (currentPaneId) {
1140-
// If the doc is open in another pane
1141-
// then switch to that pane and call open document
1142-
// which will really just show the view as it has always done
1143-
// we could just do pane.showView(doc._masterEditor) in that
1144-
// case but Editor Manager may do some state syncing
1146+
// If the doc is open in another pane then switch to that pane and call open document
1147+
// which will really just show the view as it has always done we could just
1148+
// do pane.showView(doc._masterEditor) in that case but Editor Manager may do some
1149+
// state syncing
11451150
paneId = currentPaneId;
1146-
if (!options.noPaneActivate) {
1147-
setActivePaneId(paneId);
1148-
}
11491151
}
11501152

11511153
var pane = _getPane(paneId);
@@ -1159,21 +1161,31 @@ define(function (require, exports, module) {
11591161
// open document will show the editor if there is one already
11601162
EditorManager.openDocument(doc, pane);
11611163
_makeFileMostRecent(paneId, doc.file);
1164+
1165+
if (!options.noPaneActivate) {
1166+
setActivePaneId(paneId);
1167+
}
11621168
}
11631169

11641170
/**
11651171
* Opens a file in the specified pane this can be used to open a file with a custom viewer
11661172
* or a document for editing. If it's a document for editing, edit is called on the document
11671173
* @param {!string} paneId - id of the pane in which to open the document
11681174
* @param {!File} file - file to open
1169-
* @param {{noPaneActivate:boolean}=} optionsIn - options
1175+
* @param {{noPaneActivate:boolean=, noPaneRedundancyCheck:boolean=}=} optionsIn - options
11701176
* @return {jQuery.Promise} promise that resolves to a File object or
11711177
* rejects with a File error or string
11721178
*/
11731179
function _open(paneId, file, optionsIn) {
11741180
var result = new $.Deferred(),
11751181
options = optionsIn || {};
11761182

1183+
function doPostOpenActivation() {
1184+
if (!options.noPaneActivate) {
1185+
setActivePaneId(paneId);
1186+
}
1187+
}
1188+
11771189
if (!file || !_getPane(paneId)) {
11781190
return result.reject("bad argument").promise();
11791191
}
@@ -1203,9 +1215,6 @@ define(function (require, exports, module) {
12031215
// we could just do pane.showView(doc._masterEditor) in that
12041216
// case but Editor Manager may do some state syncing
12051217
paneId = currentPaneId;
1206-
if (!options.noPaneActivate) {
1207-
setActivePaneId(paneId);
1208-
}
12091218
}
12101219

12111220
// See if there is already a view for the file
@@ -1227,6 +1236,7 @@ define(function (require, exports, module) {
12271236
if (!ProjectManager.isWithinProject(file.fullPath)) {
12281237
addToWorkingSet(paneId, file);
12291238
}
1239+
doPostOpenActivation();
12301240
result.resolve(file);
12311241
})
12321242
.fail(function (fileError) {
@@ -1239,14 +1249,18 @@ define(function (require, exports, module) {
12391249
} else {
12401250
DocumentManager.getDocumentForPath(file.fullPath)
12411251
.done(function (doc) {
1242-
_edit(paneId, doc, options);
1252+
_edit(paneId, doc, $.extend({}, options, {
1253+
noPaneActivate: true,
1254+
noPaneRedundancyCheck: true
1255+
}));
1256+
doPostOpenActivation();
12431257
result.resolve(doc.file);
12441258
})
12451259
.fail(function (fileError) {
12461260
result.reject(fileError);
12471261
});
12481262
}
1249-
1263+
12501264
return result;
12511265
}
12521266

0 commit comments

Comments
 (0)