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
Added support for closing files on middle click #3901
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6ca02c8
Added support for closing files on middle click
WebsiteDeveloper f430b5c
Fix a undefined exception
WebsiteDeveloper 9db1b35
Removed unnecessary $.extend
WebsiteDeveloper ba164b5
Fixes after review
WebsiteDeveloper 0ae96f4
Changed to use .click instead of .on("click")
WebsiteDeveloper 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 |
---|---|---|
|
@@ -343,6 +343,16 @@ define(function (require, exports, module) { | |
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 | ||
|
@@ -361,7 +371,7 @@ 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); | ||
|
@@ -370,6 +380,13 @@ define(function (require, exports, module) { | |
_reorderListItem(e, $(this)); | ||
e.preventDefault(); | ||
}); | ||
|
||
$newItem.click(function (e) { | ||
if (e.which === 2) { | ||
_handleMiddleMouseClick(e); | ||
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 does work, but I think this should be done in mouse up events rather than right here. Try with tabs in the browsers and other editors. All of them work on mouse ups. |
||
} | ||
e.preventDefault(); | ||
}); | ||
|
||
$newItem.hover( | ||
function () { | ||
|
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.
This is a lot easier to implement by just changing line 233 to
if (!fromClose || event.which !== 2)
since mousedown calls_reorderListItem
, and inside_reorderListItem
if the user isn't using the left button, it callsdrop
, so if indrop
we check if the user pressed the middle button and close the file, it works.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.
@TomMalbran
Thanks for your suggestion of an alternative solution which has the least changes to get this functionality. But I think @WebsiteDeveloper current solution is cleaner, and easier to understand and easier to locate the implementation due to the function name and the event being used. Your solution may not be easy for someone to locate the code since it is harder to imagine that a middle button click is implemented inside drop() function which is called from
_reorderListItem
. And also if someone is going to restrict the call of drop() to only left mouse button clicks in the future (since drag-n-drop is done with left mouse button), then this functionality will be broken.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.
@RaymondLim No problem. I thought it would make sense to have all the close implementations together, since closing from the "x" button is already implemented inside the drag and drop implementation to be able to drag from the close button if desired.