Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 可手持、自定义文本编辑器、复制/粘贴问题_Javascript_Angularjs_Handsontable - Fatal编程技术网

Javascript 可手持、自定义文本编辑器、复制/粘贴问题

Javascript 可手持、自定义文本编辑器、复制/粘贴问题,javascript,angularjs,handsontable,Javascript,Angularjs,Handsontable,我有一个包含两列的表:name和code。我为代码列创建了一个简单的自定义编辑器。其思想是,当用户双击单元格时,将打开带有代码编辑器的自定义对话框。我已经实现了它,并在这里发布了简化的示例: 但是,复制/粘贴功能有一个问题:如果我使用编辑器,编辑单元格的一些代码,按“保存”,则“代码”列值似乎已正确保存。但当我选择此单元格并按Ctrl+C时,不会复制该值 问题是:这是handsontable中的一个bug还是我在实现自定义编辑器时遗漏了什么?如何更改自定义编辑器以使复制粘贴功能正常工作 编辑代

我有一个包含两列的表:name和code。我为代码列创建了一个简单的自定义编辑器。其思想是,当用户双击单元格时,将打开带有代码编辑器的自定义对话框。我已经实现了它,并在这里发布了简化的示例:

但是,复制/粘贴功能有一个问题:如果我使用编辑器,编辑单元格的一些代码,按“保存”,则“代码”列值似乎已正确保存。但当我选择此单元格并按Ctrl+C时,不会复制该值

问题是:这是handsontable中的一个bug还是我在实现自定义编辑器时遗漏了什么?如何更改自定义编辑器以使复制粘贴功能正常工作

编辑代码:

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;
};
规格: 角度版本:1.6.1 可手持设备版本:0.31.2
Chrome版本:58.0.3029.81版

我在手持github Repository上发布了一个问题,并在那里收到了答案。问题链接:

解决方案: 正如handsontable团队的成员所建议的,在打开对话框之前,在open函数中,我调用
this.instance.decell()。但是,使用此解决方案时,问题是,如果按Enter键,则不会插入新行,而是选择了handsontable中的下一个单元格。然后,我将调用包装在
setTimeout()
中,调用成功了

链接到plunker:

工作守则是:

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);

};