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

Add cut/copy/paste to the context menu #12674

Merged
merged 1 commit into from
Sep 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ 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 @@ -279,17 +285,13 @@ define(function (require, exports, module) {
inlineWidget = EditorManager.getFocusedInlineWidget();

if (editor) {
// 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());

//if (!editor.hasSelection()) {
// 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: 17 additions & 14 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,17 +1113,7 @@ define(function (require, exports, module) {
return handleUndoRedo("redo");
}

/**
* 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() {
function _handleSelectAll() {
var result = new $.Deferred(),
editor = EditorManager.getFocusedEditor();

Expand All @@ -1137,6 +1127,19 @@ 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 @@ -1155,8 +1158,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, ignoreCommand);
CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, ignoreCommand);
CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, ignoreCommand);
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_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll);
});