Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wzzz711 opened this issue Aug 20, 2020 · 5 comments

Comments

@wzzz711
Copy link

wzzz711 commented Aug 20, 2020

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 wzzz711 changed the title 哥们,你的 options 的 format 必选传值才能复制,传为 text/plain 哥们,你的 options 的 format 必须传值才走复制的代码,format 传为 text/plain Aug 20, 2020
@wzzz711 wzzz711 changed the title 哥们,你的 options 的 format 必须传值才走复制的代码,format 传为 text/plain 哥们,你的 options 的 format 必须传值才走复制的代码,format 传为 text/plain,你下个版本修复下? Aug 20, 2020
@leegsen7
Copy link

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

@sudodoki
Copy link
Owner

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

@aaronzyf
Copy link

aaronzyf commented Oct 19, 2022

@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
Copy link

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

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

@sudodoki
Copy link
Owner

@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 #122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants