copy-to-clipboard icon indicating copy to clipboard operation
copy-to-clipboard copied to clipboard

哥们,你的 options 的 format 必须传值才走复制的代码,format 传为 text/plain,你下个版本修复下?

Open wzzz711 opened this issue 5 years ago • 5 comments

function copy(text, options) {
  var debug,
    message,
    reselectPrevious,
    range,
    selection,
    mark,
    success = false;
  if (!options) {
    options = {};
  }
  ...
  mark.addEventListener("copy", function(e) {
      e.stopPropagation();
      // 这里必须传默认值,否则根本不执行复制逻辑,并且你的 options 并未给 format 默认值
      if (options.format) {
        e.preventDefault();
        if (typeof e.clipboardData === "undefined") { // IE 11
          debug && console.warn("unable to use e.clipboardData");
          debug && console.warn("trying IE specific stuff");
          window.clipboardData.clearData();
          var format = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting["default"]
          window.clipboardData.setData(format, text);
        } else { // all other browsers
          e.clipboardData.clearData();
          e.clipboardData.setData(options.format, text);
        }
      }
      if (options.onCopy) {
        e.preventDefault();
        options.onCopy(e.clipboardData);
      }
    });
}

wzzz711 avatar Aug 20 '20 02:08 wzzz711

自己二次封装下吧,也简单,他最近都没维护更新了。

leegsen7 avatar Jul 27 '22 09:07 leegsen7

I don't know what this issue is about, so not sure how to address this one. Care to translate? If format not passed, we just have execCommand('copy') and default format being set, with format option making difference only if we are able to manipulate clipboard content

sudodoki avatar Jul 27 '22 20:07 sudodoki

@sudodoki What he means is to say options.format does not provide a default value, so

copy(' test plain text'), // doesn't work copy('test plain text',{format: 'text/plain'}) // work fine

in your code , you only do copy when options.format is provided

sorry for my bad english

aaronzyf avatar Oct 19 '22 08:10 aaronzyf

you can see the author's profile, he is from Ukraine With a war going on in Ukraine, it is understandable that there is no time for updates

他乌克兰人 , 打仗呢 , 多理解下

aaronzyf avatar Oct 19 '22 08:10 aaronzyf

@aaronzyf thanks for translation. Yeah, I have enough time now to take care of the package at pre-war level (which is quite low, frankly speaking), but seems to be similar to what we have in https://github.com/sudodoki/copy-to-clipboard/pull/122

sudodoki avatar Oct 19 '22 10:10 sudodoki