Skip to content

Commit

Permalink
fix(typography): 删除冗余IE11调试代码
Browse files Browse the repository at this point in the history
  • Loading branch information
byq1213 committed Jul 23, 2024
1 parent ccfa2c8 commit cce47d6
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions src/typography/utils/copy-to-clipboard/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import deselectCurrent from './toggle-selection';

interface Options {
debug?: boolean;
message?: string;
format?: string; // MIME type
onCopy?: (clipboardData: object) => void;
}

const clipboardToIE11Formatting = {
'text/plain': 'Text',
'text/html': 'Url',
default: 'Text',
};

const defaultMessage = 'Copy to clipboard: #{key}, Enter';

function format(message: string) {
Expand All @@ -30,7 +23,6 @@ function copy(text: string, options?: Options): boolean {
if (!options) {
options = {};
}
const debug = options.debug || false;
try {
reselectPrevious = deselectCurrent();

Expand All @@ -54,18 +46,8 @@ function copy(text: string, options?: Options): boolean {
e.stopPropagation();
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 as any).clipboardData.clearData();
const format = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting['default'];
(window as any).clipboardData.setData(format, text);
} else {
// all other browsers
e.clipboardData.clearData();
e.clipboardData.setData(options.format, text);
}
e.clipboardData.clearData();
e.clipboardData.setData(options.format, text);
}
if (options.onCopy) {
e.preventDefault();
Expand All @@ -84,15 +66,11 @@ function copy(text: string, options?: Options): boolean {
}
success = true;
} catch (err) {
debug && console.error('unable to copy using execCommand: ', err);
debug && console.warn('trying IE specific stuff');
try {
(window as any).clipboardData.setData(options.format || 'text', text);
options.onCopy && options.onCopy((window as any).clipboardData);
success = true;
} catch (err) {
debug && console.error('unable to copy using clipboardData: ', err);
debug && console.error('falling back to prompt');
message = format('message' in options ? options.message : defaultMessage);
window.prompt(message, text);
}
Expand Down

0 comments on commit cce47d6

Please sign in to comment.