Skip to content

Commit

Permalink
Merge pull request #142 from mostafaznv/dev
Browse files Browse the repository at this point in the history
fix: consider the selected range when pasting content with plain paste enabled #141
  • Loading branch information
mostafaznv authored Sep 25, 2024
2 parents 3461b57 + 2c8d85f commit 01c77af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

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 01c77af

Please sign in to comment.