简体   繁体   English

可手动操作,自定义文本编辑器,复制/粘贴问题

[英]Handsontable, custom text editor, copy/paste issue

I have a table with two columns: name and code. 我有一个包含两列的表:名称和代码。 I have created a simple custom editor for code column. 我为代码列创建了一个简单的自定义编辑器。 The idea is, when user double clicks on the cell, the custom dialog with code editor opens. 这个想法是,当用户双击单元格时,带有代码编辑器的自定义对话框将打开。 I have implemented it and posted the simplified example here: 我已经实现了它,并在此处发布了简化的示例:

Link to plunker 链接到朋克

However, I have one issue with copy/paste functionality: if I use my editor, edit some code for the cell, press “Save”, the "code" column value seems to be correctly saved. 但是,复制/粘贴功能存在一个问题:如果使用编辑器,请为单元格编辑一些代码,然后按“保存”,则“代码”列值似乎已正确保存。 But when I select this cell and press Ctrl+C, the value is not copied. 但是,当我选择此单元格并按Ctrl + C时,不会复制该值。

The question is: is it a bug in handsontable or I have just missed something, while implementing the custom editor? 问题是:这是实践中的错误,还是在实现自定义编辑器时错过了一些东西? How should I change my custom editor to make the copy-paste functionality working properly. 我应如何更改自定义编辑器以使复制粘贴功能正常工作。

The code of editor: 编辑器代码:

var ScriptEditor = Handsontable.editors.TextEditor.prototype.extend();

ScriptEditor.prototype.getValue = function () {
    return this.TEXTAREA.value;
};

ScriptEditor.prototype.setValue = function (value) {
    this.TEXTAREA.value = value;
};

ScriptEditor.prototype.open = function () {

    var self = this;

    this.instance.deselectCell();

    var value = self.instance.getDataAtCell(self.row, self.col);
    var decodedCode = decodeURI(value);

    var success = function (resultCode) {
        var encodedCode = encodeURI(resultCode);

        self.instance.setDataAtCell(self.row, self.col, encodedCode, 'edit');
        self.instance.selectCell(self.row, self.col);
    };

    openEditor(decodedCode)
            .then(success);

};

ScriptEditor.prototype.focus = function () {
    Handsontable.editors.TextEditor.prototype.focus.apply(this, arguments);
};

ScriptEditor.prototype.close = function () {

};


var openEditor = function (codeToEdit) {

    var deferred = $q.defer();

    var dialog = ngDialog.open({
        template: 'editorTemplate.htm',
        className: 'ngdialog-theme-default',
        controllerAs: "editor",
        controller: function () {
            var vm = this;
            vm.inputCode = codeToEdit;
            vm.submitChanges = function () {
                dialog.close();
                deferred.resolve(vm.inputCode);
            };
        }
    });

    return deferred.promise;
};

Specs: Angular version: 1.6.1 Handsontable version: 0.31.2 Chrome version: Version 58.0.3029.81 规格:Angular版本:1.6.1可操作版本:0.31.2 Chrome版本:版本58.0.3029.81

I have posted an issue on handsontable github repositiory and received there the answer. 我已经在可动手操作的github仓库上发布了一个问题,并在那里得到了答案。 Link to issue: here 链接到问题: 这里

Solution: Like the member of handsontable team has suggested, in open function before opening my dialog I call this.instance.deselectCell(); 解决方案:就像动手操作团队的成员建议的那样,在打开对话框之前的打开函数中,我称为this.instance.deselectCell(); . However, with this solution, the problem was, that if I press Enter my code editor dialog, not the new line is inserted, but the next cell in handsontable is selected. 但是,使用此解决方案时,问题是,如果按Enter输入代码编辑器对话框,则不会插入新行,而是选择了handontable中的下一个单元格。 Then, I have wrappped the call in setTimeout() and it is worked. 然后,我将调用包装在setTimeout() ,并且工作正常。

Link to plunker: here 链接到punker: 这里

The working code is: 工作代码是:

ScriptEditor.prototype.open = function () {

    var self = this;

    setTimeout(function () {
        self.instance.deselectCell();
    });

    var value = self.instance.getDataAtCell(self.row, self.col);
    var decodedCode = decodeURI(value);

    var success = function (resultCode) {
        var encodedCode = encodeURI(resultCode);
        self.instance.setDataAtCell(self.row, self.col, encodedCode, 'edit');
        self.instance.selectCell(self.row, self.col);
    };

    openEditor(decodedCode)
        .then(success);

};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM