UBERF-9279: Ctrl/Cmd + K for hyperlinks (#7857)

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
Victor Ilyushchenko
2025-01-31 22:24:36 +07:00
committed by GitHub
parent e0c6724c73
commit b075ab1ec3
6 changed files with 65 additions and 5 deletions
@@ -0,0 +1,43 @@
//
// Copyright © 2025 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import { Extension } from '@tiptap/core'
import { showPopup } from '@hcengineering/ui'
import LinkPopup from '../LinkPopup.svelte'
export const LinkShortcutsExtension = Extension.create<any>({
name: 'defaultShortcuts',
addKeyboardShortcuts () {
return {
'Mod-k': () => {
const { from, to } = this.editor.state.selection
if (from === to) return false
const link = this.editor.getAttributes('link').href
showPopup(LinkPopup, { link }, undefined, undefined, (newLink) => {
if (newLink === '') {
this.editor.chain().focus().extendMarkRange('link').unsetLink().run()
} else {
this.editor.chain().focus().extendMarkRange('link').setLink({ href: newLink }).run()
}
})
return true
}
}
}
})