mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Prevent generating a link tag when pasting URL to inside of a link tag.
This commit is contained in:
@@ -287,6 +287,19 @@ export default class CodeEditor extends React.Component {
|
|||||||
const matcher = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/
|
const matcher = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/
|
||||||
return matcher.test(str)
|
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')) {
|
if (dataTransferItem.type.match('image')) {
|
||||||
const blob = dataTransferItem.getAsFile()
|
const blob = dataTransferItem.getAsFile()
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
@@ -306,7 +319,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
const imageMd = `})`
|
const imageMd = `})`
|
||||||
this.insertImageMd(imageMd)
|
this.insertImageMd(imageMd)
|
||||||
}
|
}
|
||||||
} else if (this.props.fetchUrlTitle && isURL(pastedTxt)) {
|
} else if (this.props.fetchUrlTitle && isURL(pastedTxt) && !isInLinkTag(editor)) {
|
||||||
this.handlePasteUrl(e, editor, pastedTxt)
|
this.handlePasteUrl(e, editor, pastedTxt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user