This repository has been 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
Improvements to middle-click closing files #4576
Merged
Merged
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -42,6 +42,10 @@ define(function (require, exports, module) { | |
ViewUtils = require("utils/ViewUtils"); | ||
|
||
|
||
/** @const @type {number} Constants for event.which values */ | ||
var LEFT_BUTTON = 1, | ||
MIDDLE_BUTTON = 2; | ||
|
||
/** Each list item in the working set stores a references to the related document in the list item's data. | ||
* Use listItem.data(_FILE_KEY) to get the document reference | ||
*/ | ||
|
@@ -239,21 +243,14 @@ define(function (require, exports, module) { | |
window.clearInterval(interval); | ||
} | ||
|
||
// If file wasnt moved open or close it | ||
// If item wasn't dragged, treat as a click | ||
if (!moved) { | ||
if (!fromClose) { | ||
/***/ | ||
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW); | ||
/*** | ||
// Backing out for Sprint 18 due to issues described in #2394, #2411 | ||
if (selected) { | ||
CommandManager.execute(Commands.FILE_RENAME); | ||
} else { | ||
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW); | ||
} | ||
***/ | ||
} else { | ||
// Click on close icon, or middle click anywhere - close the item without selecting it first | ||
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. This comment and the one above really make it clear that we're handling click events in this function, especially middle clicks right here. |
||
if (fromClose || event.which === MIDDLE_BUTTON) { | ||
CommandManager.execute(Commands.FILE_CLOSE, {file: $listItem.data(_FILE_KEY)}); | ||
} else { | ||
// Normal right and left click - select the item | ||
FileViewController.openAndSelectDocument($listItem.data(_FILE_KEY).fullPath, FileViewController.WORKING_SET_VIEW); | ||
} | ||
|
||
} else { | ||
|
@@ -276,7 +273,7 @@ define(function (require, exports, module) { | |
|
||
// Only drag with the left mouse button, and control key is not down | ||
// on Mac, end the drop in other cases | ||
if (event.which !== 1 || (event.ctrlKey && brackets.platform === "mac")) { | ||
if (event.which !== LEFT_BUTTON || (event.ctrlKey && brackets.platform === "mac")) { | ||
drop(); | ||
return; | ||
} | ||
|
@@ -355,20 +352,11 @@ define(function (require, exports, module) { | |
} | ||
|
||
function isOpenAndDirty(file) { | ||
// working set item might never have been opened; if so, then it's definitely not dirty | ||
var docIfOpen = DocumentManager.getOpenDocumentForPath(file.fullPath); | ||
return (docIfOpen && docIfOpen.isDirty); | ||
} | ||
|
||
/** | ||
* @private | ||
* @param {$.Event} event The Click Event to respond to. | ||
*/ | ||
function _handleMiddleMouseClick(event) { | ||
var file = $(event.target).closest("li").data(_FILE_KEY); | ||
|
||
CommandManager.execute(Commands.FILE_CLOSE, {file: file}); | ||
} | ||
|
||
/** | ||
* Builds the UI for a new list item and inserts in into the end of the list | ||
* @private | ||
|
@@ -386,8 +374,6 @@ define(function (require, exports, module) { | |
|
||
$openFilesContainer.find("ul").append($newItem); | ||
|
||
// working set item might never have been opened; if so, then it's definitely not dirty | ||
|
||
// Update the listItem's apperance | ||
_updateFileStatusIcon($newItem, isOpenAndDirty(file), false); | ||
_updateListItemSelection($newItem, curDoc); | ||
|
@@ -397,13 +383,6 @@ define(function (require, exports, module) { | |
e.preventDefault(); | ||
}); | ||
|
||
$newItem.click(function (e) { | ||
if (e.which === 2) { | ||
_handleMiddleMouseClick(e); | ||
} | ||
e.preventDefault(); | ||
}); | ||
|
||
$newItem.hover( | ||
function () { | ||
_updateFileStatusIcon($(this), isOpenAndDirty(file), true); | ||
|
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.
Nice to see those defined as constant. Don't we also need to define RIGHT_BUTTON?
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.
Don't bother to define right button. We're not using it anywhere any way. We can always add it here when we need it.