(core) Add cut, copy, and paste to context menu

Summary:
On supported browsers, the new context menu commands work exactly as they do
via keyboard shortcuts. On unsupported browsers, an unavailable command
modal is shown with a suggestion to use keyboard shortcuts instead.

Test Plan: Browser tests.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3867
This commit is contained in:
George Gevoian
2023-04-28 02:20:28 -07:00
parent c6ec8339f5
commit 18ad39cba3
17 changed files with 468 additions and 97 deletions

View File

@@ -22,7 +22,7 @@ const {ClientColumnGetters} = require('app/client/models/ClientColumnGetters');
const {reportError, reportSuccess} = require('app/client/models/errors');
const {urlState} = require('app/client/models/gristUrlState');
const {SectionFilter} = require('app/client/models/SectionFilter');
const {copyToClipboard} = require('app/client/lib/copyToClipboard');
const {copyToClipboard} = require('app/client/lib/clipboardUtils');
const {setTestState} = require('app/client/lib/testState');
const {ExtraRows} = require('app/client/models/DataTableModelWithDiff');
const {createFilterMenu} = require('app/client/ui/ColumnFilterMenu');
@@ -153,7 +153,7 @@ function BaseView(gristDoc, viewSectionModel, options) {
return linking && linking.disableEditing();
}));
this.isPreview = this.options.isPreview;
this.isPreview = this.options.isPreview ?? false;
this.enableAddRow = this.autoDispose(ko.computed(() => this.options.addNewRow &&
!this.viewSection.disableAddRemoveRows() && !this.disableEditing()));
@@ -602,6 +602,9 @@ BaseView.prototype._saveEditRowField = function(editRowModel, colName, value) {
* @returns {pasteObj} - Paste object
*/
BaseView.prototype.copy = function(selection) {
// Clear the previous copy selection, if any.
commands.allCommands.clearCopySelection.run();
this.copySelection(selection);
return {
@@ -617,6 +620,9 @@ BaseView.prototype.copy = function(selection) {
* @returns {pasteObj} - Paste object
*/
BaseView.prototype.cut = function(selection) {
// Clear the previous copy selection, if any.
commands.allCommands.clearCopySelection.run();
this.copySelection(selection);
return {