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

Holding shift when pasting pastes unformatted url #2455

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion packages/ui/src/components/base/MarkdownEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ let editorThemeCompartment: Compartment | null = null

const emit = defineEmits(['update:modelValue'])

const shiftKeyHeld = ref(false)

onMounted(() => {
const updateListener = EditorView.updateListener.of((update) => {
if (update.docChanged) {
Expand Down Expand Up @@ -361,6 +363,16 @@ onMounted(() => {
const disabledCompartment = EditorState.readOnly.of(props.disabled)

const eventHandlers = EditorView.domEventHandlers({
keydown: (ev) => {
const { key, shiftKey } = ev
if (!key || !shiftKey) return
if (key === 'V' && shiftKey) shiftKeyHeld.value = true
},
keyup: (ev) => {
const { key, shiftKey } = ev
if (!key || !shiftKey) return
if (key === 'V' && shiftKey) shiftKeyHeld.value = false
},
paste: (ev, view) => {
const { clipboardData } = ev
if (!clipboardData) return
Expand All @@ -387,7 +399,8 @@ onMounted(() => {
// If the user's pasting a url, automatically convert it to a link with the selection as the text or the url itself if no selection content.
const url = ev.clipboardData?.getData('text/plain')

if (url) {
// If the user is holding shift when pasting, don't change the link
if (url && !shiftKeyHeld.value) {
try {
cleanUrl(url)
} catch (error: unknown) {
Expand Down
Loading