Skip to content

Commit

Permalink
fix: consider the selected range when pasting content with plain past…
Browse files Browse the repository at this point in the history
…e enabled #141
  • Loading branch information
mostafaznv committed Sep 25, 2024
1 parent 6b7efe4 commit a3cc1fa
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions resources/js/fields/editor-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,23 @@ export default {
editor.editing.view.document.on('clipboardInput', (evt, data) => {
evt.stop()
editor.model.change(writer => {
writer.insertText(
data.dataTransfer.getData('text/plain'),
editor.model.document.selection.getFirstPosition()
)
})
const model = editor.model
const selection = model.document.selection
const selectedRange = selection.getFirstRange()
const content = data.dataTransfer.getData('text/plain')
model.change(writer => {
if (selectedRange.isCollapsed) {
writer.insertText(
content, selection.getFirstPosition()
)
}
else {
editor.execute('input', {
text: content
})
}
});
})
}
})
Expand Down

0 comments on commit a3cc1fa

Please sign in to comment.