Skip to content

Commit 2c30f0e

Browse files
authored
Merge pull request #1684 from kawmra/prevent-fetching-title-in-link-tag
Prevent generating a link tag when pasting URL to inside of a link tag.
2 parents 1472114 + b36322b commit 2c30f0e

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

browser/components/CodeEditor.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,19 @@ export default class CodeEditor extends React.Component {
287287
const matcher = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/
288288
return matcher.test(str)
289289
}
290+
const isInLinkTag = (editor) => {
291+
const startCursor = editor.getCursor('start')
292+
const prevChar = editor.getRange(
293+
{ line: startCursor.line, ch: startCursor.ch - 2 },
294+
{ line: startCursor.line, ch: startCursor.ch }
295+
)
296+
const endCursor = editor.getCursor('end')
297+
const nextChar = editor.getRange(
298+
{ line: endCursor.line, ch: endCursor.ch },
299+
{ line: endCursor.line, ch: endCursor.ch + 1 }
300+
)
301+
return prevChar === '](' && nextChar === ')'
302+
}
290303
if (dataTransferItem.type.match('image')) {
291304
const blob = dataTransferItem.getAsFile()
292305
const reader = new FileReader()
@@ -306,7 +319,7 @@ export default class CodeEditor extends React.Component {
306319
const imageMd = `![${imageName}](${path.join('/:storage', `${imageName}.png`)})`
307320
this.insertImageMd(imageMd)
308321
}
309-
} else if (this.props.fetchUrlTitle && isURL(pastedTxt)) {
322+
} else if (this.props.fetchUrlTitle && isURL(pastedTxt) && !isInLinkTag(editor)) {
310323
this.handlePasteUrl(e, editor, pastedTxt)
311324
}
312325
}

0 commit comments

Comments
 (0)