Skip to content

Commit d93ccc5

Browse files
committed
Add cut/copy/paste to the context menu
1 parent 300f3d0 commit d93ccc5

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/command/DefaultMenus.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ define(function (require, exports, module) {
251251
// editor_cmenu.addMenuItem(Commands.NAVIGATE_JUMPTO_DEFINITION);
252252
editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT);
253253
editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_DOCS);
254+
editor_cmenu.addMenuDivider();
255+
editor_cmenu.addMenuItem(Commands.EDIT_CUT);
256+
editor_cmenu.addMenuItem(Commands.EDIT_COPY);
257+
editor_cmenu.addMenuItem(Commands.EDIT_PASTE);
258+
259+
editor_cmenu.addMenuDivider();
254260
editor_cmenu.addMenuItem(Commands.EDIT_SELECT_ALL);
255261

256262
var inline_editor_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.INLINE_EDITOR_MENU);
@@ -279,17 +285,13 @@ define(function (require, exports, module) {
279285
inlineWidget = EditorManager.getFocusedInlineWidget();
280286

281287
if (editor) {
282-
// If there's just an insertion point select the word token at the cursor pos so
283-
// it's more clear what the context menu applies to.
284-
if (!editor.hasSelection()) {
285-
editor.selectWordAt(editor.getCursorPos());
286-
288+
//if (!editor.hasSelection()) {
287289
// Prevent menu from overlapping text by moving it down a little
288290
// Temporarily backout this change for now to help mitigate issue #1111,
289291
// which only happens if mouse is not over context menu. Better fix
290292
// requires change to bootstrap, which is too risky for now.
291293
//e.pageY += 6;
292-
}
294+
//}
293295

294296
// Inline text editors have a different context menu (safe to assume it's not some other
295297
// type of inline widget since we already know an Editor has focus)

src/editor/EditorCommandHandlers.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,17 +1113,7 @@ define(function (require, exports, module) {
11131113
return handleUndoRedo("redo");
11141114
}
11151115

1116-
/**
1117-
* Special command handler that just ignores the command. This is used for Cut, Copy, and Paste.
1118-
* These menu items are handled natively, but need to be registered in our JavaScript code so the
1119-
* menu items can be created.
1120-
*/
1121-
function ignoreCommand() {
1122-
// Do nothing. The shell will call the native handler for the command.
1123-
return (new $.Deferred()).reject().promise();
1124-
}
1125-
1126-
function _handleSelectAll() {
1116+
function _handleSelectAll() {
11271117
var result = new $.Deferred(),
11281118
editor = EditorManager.getFocusedEditor();
11291119

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

1130+
function _execCommand(cmd) {
1131+
window.document.execCommand(cmd);
1132+
}
1133+
function _execCommandCut() {
1134+
_execCommand("cut");
1135+
}
1136+
function _execCommandCopy() {
1137+
_execCommand("copy");
1138+
}
1139+
function _execCommandPaste() {
1140+
_execCommand("paste");
1141+
}
1142+
11401143
// Register commands
11411144
CommandManager.register(Strings.CMD_INDENT, Commands.EDIT_INDENT, indentText);
11421145
CommandManager.register(Strings.CMD_UNINDENT, Commands.EDIT_UNINDENT, unindentText);
@@ -1155,8 +1158,8 @@ define(function (require, exports, module) {
11551158

11561159
CommandManager.register(Strings.CMD_UNDO, Commands.EDIT_UNDO, handleUndo);
11571160
CommandManager.register(Strings.CMD_REDO, Commands.EDIT_REDO, handleRedo);
1158-
CommandManager.register(Strings.CMD_CUT, Commands.EDIT_CUT, ignoreCommand);
1159-
CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, ignoreCommand);
1160-
CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, ignoreCommand);
1161+
CommandManager.register(Strings.CMD_CUT, Commands.EDIT_CUT, _execCommandCut);
1162+
CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, _execCommandCopy);
1163+
CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, _execCommandPaste);
11611164
CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll);
11621165
});

0 commit comments

Comments
 (0)