Skip to content

Commit 2661306

Browse files
author
Andrew L
committed
Make config flag more specific
1 parent cd58a52 commit 2661306

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/option-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export interface OptionConfig {
2-
pasteAsPlainText?: boolean
2+
pasteLinkAsPlainTextOverSelectedText?: boolean
33
}

src/paste-markdown-link.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import {OptionConfig} from './option-config'
22
import {insertText} from './text'
33
import {shouldSkipFormatting} from './paste-keyboard-shortcut-helper'
44

5-
const pasteAsPlainTextMap = new WeakMap<HTMLElement, boolean>()
5+
const pasteLinkAsPlainTextOverSelectedTextMap = new WeakMap<HTMLElement, boolean>()
66

77
export function install(el: HTMLElement, optionConfig?: OptionConfig): void {
8-
pasteAsPlainTextMap.set(el, optionConfig?.pasteAsPlainText === true)
8+
pasteLinkAsPlainTextOverSelectedTextMap.set(el, optionConfig?.pasteLinkAsPlainTextOverSelectedText === true)
99
el.addEventListener('paste', onPaste)
1010
}
1111

@@ -16,10 +16,13 @@ export function uninstall(el: HTMLElement): void {
1616
function onPaste(event: ClipboardEvent) {
1717
const {currentTarget: el} = event
1818
const element = el as HTMLElement
19-
const shouldPastePlainText = pasteAsPlainTextMap.get(element) ?? false
19+
const shouldPasteAsPlainText = pasteLinkAsPlainTextOverSelectedTextMap.get(element) ?? false
2020
const shouldSkipDefaultBehavior = shouldSkipFormatting(element)
2121

22-
if ((!shouldPastePlainText && shouldSkipDefaultBehavior) || (shouldPastePlainText && !shouldSkipDefaultBehavior)) {
22+
if (
23+
(!shouldPasteAsPlainText && shouldSkipDefaultBehavior) ||
24+
(shouldPasteAsPlainText && !shouldSkipDefaultBehavior)
25+
) {
2326
return
2427
}
2528

test/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('paste-markdown', function () {
4343
assert.equal(textarea.value, 'The examples can be found [here](https://github.com).')
4444
})
4545

46-
it('turns pasted urls on selected text into markdown links if pasteAsPlainText is false', function () {
46+
it('turns pasted urls on selected text into markdown links if pasteLinkAsPlainTextOverSelectedText is false', function () {
4747
subscription = subscribeWithOptionConfig(subscription, textarea, false)
4848

4949
// eslint-disable-next-line i18n-text/no-en
@@ -53,7 +53,7 @@ describe('paste-markdown', function () {
5353
assert.equal(textarea.value, 'The examples can be found [here](https://github.com).')
5454
})
5555

56-
it('turns pasted urls on selected text into markdown links if pasteAsPlainText is true and skip format flag is true', function () {
56+
it('turns pasted urls on selected text into markdown links if pasteLinkAsPlainTextOverSelectedText is true and skip format flag is true', function () {
5757
subscription = subscribeWithOptionConfig(subscription, textarea, true)
5858

5959
// eslint-disable-next-line i18n-text/no-en
@@ -64,7 +64,7 @@ describe('paste-markdown', function () {
6464
assert.equal(textarea.value, 'The examples can be found [here](https://github.com).')
6565
})
6666

67-
it('pastes as plain text on selected text if pasteAsPlainText is true', function () {
67+
it('pastes as plain text on selected text if pasteLinkAsPlainTextOverSelectedText is true', function () {
6868
subscription = subscribeWithOptionConfig(subscription, textarea, true)
6969

7070
// eslint-disable-next-line i18n-text/no-en
@@ -385,10 +385,10 @@ function dispatchSkipFormattingKeyEvent(textarea) {
385385
)
386386
}
387387

388-
function subscribeWithOptionConfig(subscription, textarea, pasteAsPlainText) {
388+
function subscribeWithOptionConfig(subscription, textarea, pasteLinkAsPlainTextOverSelectedText) {
389389
// Clear the before test subscription with no config and re-subscribe with config
390390
subscription.unsubscribe()
391-
return subscribe(textarea, {pasteAsPlainText})
391+
return subscribe(textarea, {pasteLinkAsPlainTextOverSelectedText})
392392
}
393393

394394
function paste(textarea, data) {

0 commit comments

Comments
 (0)