Skip to content

Commit

Permalink
Merge pull request BoostIO#1684 from kawmra/prevent-fetching-title-in…
Browse files Browse the repository at this point in the history
…-link-tag

Prevent generating a link tag when pasting URL to inside of a link tag.
  • Loading branch information
Rokt33r authored Mar 20, 2018
2 parents 1472114 + b36322b commit 2c30f0e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,19 @@ export default class CodeEditor extends React.Component {
const matcher = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/
return matcher.test(str)
}
const isInLinkTag = (editor) => {
const startCursor = editor.getCursor('start')
const prevChar = editor.getRange(
{ line: startCursor.line, ch: startCursor.ch - 2 },
{ line: startCursor.line, ch: startCursor.ch }
)
const endCursor = editor.getCursor('end')
const nextChar = editor.getRange(
{ line: endCursor.line, ch: endCursor.ch },
{ line: endCursor.line, ch: endCursor.ch + 1 }
)
return prevChar === '](' && nextChar === ')'
}
if (dataTransferItem.type.match('image')) {
const blob = dataTransferItem.getAsFile()
const reader = new FileReader()
Expand All @@ -306,7 +319,7 @@ export default class CodeEditor extends React.Component {
const imageMd = `![${imageName}](${path.join('/:storage', `${imageName}.png`)})`
this.insertImageMd(imageMd)
}
} else if (this.props.fetchUrlTitle && isURL(pastedTxt)) {
} else if (this.props.fetchUrlTitle && isURL(pastedTxt) && !isInLinkTag(editor)) {
this.handlePasteUrl(e, editor, pastedTxt)
}
}
Expand Down

0 comments on commit 2c30f0e

Please sign in to comment.