Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: consider the selected range when pasting content with plain paste enabled #141 #142

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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