繁体   English   中英

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

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

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

链接到朋克

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

问题是:这是实践中的错误,还是在实现自定义编辑器时错过了一些东西? 我应如何更改自定义编辑器以使复制粘贴功能正常工作。

编辑器代码:

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

规格:Angular版本:1.6.1可操作版本:0.31.2 Chrome版本:版本58.0.3029.81

我已经在可动手操作的github仓库上发布了一个问题,并在那里得到了答案。 链接到问题: 这里

解决方案:就像动手操作团队的成员建议的那样,在打开对话框之前的打开函数中,我称为this.instance.deselectCell(); 但是,使用此解决方案时,问题是,如果按Enter输入代码编辑器对话框,则不会插入新行,而是选择了handontable中的下一个单元格。 然后,我将调用包装在setTimeout() ,并且工作正常。

链接到punker: 这里

工作代码是:

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