Skip to content

Commit

Permalink
Revert adobe/brackets "Add cut/copy/paste to the context menu" which
Browse files Browse the repository at this point in the history
relies on document.execCommand() which doesn't work well (esp. for paste)
in browsers.  See adobe#12674.

This reverts commit d93ccc5.
  • Loading branch information
humphd committed Feb 16, 2017
1 parent 368b12e commit 95bdac5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
14 changes: 6 additions & 8 deletions src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,6 @@ define(function (require, exports, module) {
// editor_cmenu.addMenuItem(Commands.NAVIGATE_JUMPTO_DEFINITION);
editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT);
editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_DOCS);
editor_cmenu.addMenuDivider();
editor_cmenu.addMenuItem(Commands.EDIT_CUT);
editor_cmenu.addMenuItem(Commands.EDIT_COPY);
editor_cmenu.addMenuItem(Commands.EDIT_PASTE);

editor_cmenu.addMenuDivider();
editor_cmenu.addMenuItem(Commands.EDIT_SELECT_ALL);

var inline_editor_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.INLINE_EDITOR_MENU);
Expand Down Expand Up @@ -287,13 +281,17 @@ define(function (require, exports, module) {
inlineWidget = EditorManager.getFocusedInlineWidget();

if (editor) {
//if (!editor.hasSelection()) {
// If there's just an insertion point select the word token at the cursor pos so
// it's more clear what the context menu applies to.
if (!editor.hasSelection()) {
editor.selectWordAt(editor.getCursorPos());

// Prevent menu from overlapping text by moving it down a little
// Temporarily backout this change for now to help mitigate issue #1111,
// which only happens if mouse is not over context menu. Better fix
// requires change to bootstrap, which is too risky for now.
//e.pageY += 6;
//}
}

// Inline text editors have a different context menu (safe to assume it's not some other
// type of inline widget since we already know an Editor has focus)
Expand Down
31 changes: 14 additions & 17 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,17 @@ define(function (require, exports, module) {
return handleUndoRedo("redo");
}

function _handleSelectAll() {
/**
* Special command handler that just ignores the command. This is used for Cut, Copy, and Paste.
* These menu items are handled natively, but need to be registered in our JavaScript code so the
* menu items can be created.
*/
function ignoreCommand() {
// Do nothing. The shell will call the native handler for the command.
return (new $.Deferred()).reject().promise();
}

function _handleSelectAll() {
var result = new $.Deferred(),
editor = EditorManager.getFocusedEditor();

Expand All @@ -1127,19 +1137,6 @@ define(function (require, exports, module) {
return result.promise();
}

function _execCommand(cmd) {
window.document.execCommand(cmd);
}
function _execCommandCut() {
_execCommand("cut");
}
function _execCommandCopy() {
_execCommand("copy");
}
function _execCommandPaste() {
_execCommand("paste");
}

// Register commands
CommandManager.register(Strings.CMD_INDENT, Commands.EDIT_INDENT, indentText);
CommandManager.register(Strings.CMD_UNINDENT, Commands.EDIT_UNINDENT, unindentText);
Expand All @@ -1158,8 +1155,8 @@ define(function (require, exports, module) {

CommandManager.register(Strings.CMD_UNDO, Commands.EDIT_UNDO, handleUndo);
CommandManager.register(Strings.CMD_REDO, Commands.EDIT_REDO, handleRedo);
CommandManager.register(Strings.CMD_CUT, Commands.EDIT_CUT, _execCommandCut);
CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, _execCommandCopy);
CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, _execCommandPaste);
CommandManager.register(Strings.CMD_CUT, Commands.EDIT_CUT, ignoreCommand);
CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, ignoreCommand);
CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, ignoreCommand);
CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll);
});

0 comments on commit 95bdac5

Please sign in to comment.