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

Commit a08eb28

Browse files
committed
Merge pull request #4576 from adobe/pflynn/middle-close
Improvements to middle-click closing files
2 parents 15277a8 + 04bf243 commit a08eb28

1 file changed

Lines changed: 12 additions & 33 deletions

File tree

src/project/WorkingSetView.js

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ define(function (require, exports, module) {
4242
ViewUtils = require("utils/ViewUtils");
4343

4444

45+
/** @const @type {number} Constants for event.which values */
46+
var LEFT_BUTTON = 1,
47+
MIDDLE_BUTTON = 2;
48+
4549
/** Each list item in the working set stores a references to the related document in the list item's data.
4650
* Use listItem.data(_FILE_KEY) to get the document reference
4751
*/
@@ -239,21 +243,14 @@ define(function (require, exports, module) {
239243
window.clearInterval(interval);
240244
}
241245

242-
// If file wasnt moved open or close it
246+
// If item wasn't dragged, treat as a click
243247
if (!moved) {
244-
if (!fromClose) {
245-
/***/
246-
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW);
247-
/***
248-
// Backing out for Sprint 18 due to issues described in #2394, #2411
249-
if (selected) {
250-
CommandManager.execute(Commands.FILE_RENAME);
251-
} else {
252-
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW);
253-
}
254-
***/
255-
} else {
248+
// Click on close icon, or middle click anywhere - close the item without selecting it first
249+
if (fromClose || event.which === MIDDLE_BUTTON) {
256250
CommandManager.execute(Commands.FILE_CLOSE, {file: $listItem.data(_FILE_KEY)});
251+
} else {
252+
// Normal right and left click - select the item
253+
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW);
257254
}
258255

259256
} else {
@@ -276,7 +273,7 @@ define(function (require, exports, module) {
276273

277274
// Only drag with the left mouse button, and control key is not down
278275
// on Mac, end the drop in other cases
279-
if (event.which !== 1 || (event.ctrlKey && brackets.platform === "mac")) {
276+
if (event.which !== LEFT_BUTTON || (event.ctrlKey && brackets.platform === "mac")) {
280277
drop();
281278
return;
282279
}
@@ -355,20 +352,11 @@ define(function (require, exports, module) {
355352
}
356353

357354
function isOpenAndDirty(file) {
355+
// working set item might never have been opened; if so, then it's definitely not dirty
358356
var docIfOpen = DocumentManager.getOpenDocumentForPath(file.fullPath);
359357
return (docIfOpen && docIfOpen.isDirty);
360358
}
361359

362-
/**
363-
* @private
364-
* @param {$.Event} event The Click Event to respond to.
365-
*/
366-
function _handleMiddleMouseClick(event) {
367-
var file = $(event.target).closest("li").data(_FILE_KEY);
368-
369-
CommandManager.execute(Commands.FILE_CLOSE, {file: file});
370-
}
371-
372360
/**
373361
* Builds the UI for a new list item and inserts in into the end of the list
374362
* @private
@@ -386,8 +374,6 @@ define(function (require, exports, module) {
386374

387375
$openFilesContainer.find("ul").append($newItem);
388376

389-
// working set item might never have been opened; if so, then it's definitely not dirty
390-
391377
// Update the listItem's apperance
392378
_updateFileStatusIcon($newItem, isOpenAndDirty(file), false);
393379
_updateListItemSelection($newItem, curDoc);
@@ -397,13 +383,6 @@ define(function (require, exports, module) {
397383
e.preventDefault();
398384
});
399385

400-
$newItem.click(function (e) {
401-
if (e.which === 2) {
402-
_handleMiddleMouseClick(e);
403-
}
404-
e.preventDefault();
405-
});
406-
407386
$newItem.hover(
408387
function () {
409388
_updateFileStatusIcon($(this), isOpenAndDirty(file), true);

0 commit comments

Comments
 (0)