diff --git a/src/components/chat/input.ts b/src/components/chat/input.ts index 88fce2de..0a7f2f09 100644 --- a/src/components/chat/input.ts +++ b/src/components/chat/input.ts @@ -671,15 +671,27 @@ export default class ChatInput { 'I': 'italic', 'U': 'underline', 'S': 'strikethrough', - 'M': 'monospace' + 'M': 'monospace', + 'K': 'link' }; - for(const key in formatKeys) { - const good = e.code == ('Key' + key); - if(good) { - this.applyMarkdown(formatKeys[key]); - cancelEvent(e); // cancel legacy event - break; + const selection = document.getSelection(); + if(selection.toString().trim().length) { + for(const key in formatKeys) { + const good = e.code == ('Key' + key); + + if(good) { + // * костыльчик + if(key === 'K') { + this.appImManager.markupTooltip.showLinkEditor(); + cancelEvent(e); + break; + } + + this.applyMarkdown(formatKeys[key]); + cancelEvent(e); // cancel legacy event + break; + } } } diff --git a/src/components/chat/markupTooltip.ts b/src/components/chat/markupTooltip.ts index bf519232..3fffc7c5 100644 --- a/src/components/chat/markupTooltip.ts +++ b/src/components/chat/markupTooltip.ts @@ -48,25 +48,7 @@ export default class MarkupTooltip { } else { attachClickEvent(button, (e) => { cancelEvent(e); - this.container.classList.add('is-link'); - - const selection = document.getSelection(); - this.savedRange = selection.getRangeAt(0); - - if(button.classList.contains('active')) { - const startContainer = this.savedRange.startContainer; - const anchor = startContainer.parentElement as HTMLAnchorElement; - this.linkInput.value = anchor.href; - } else { - this.linkInput.value = ''; - } - - this.setTooltipPosition(true); - - setTimeout(() => { - this.linkInput.focus(); // !!! instant focus will break animation - }, 200); - this.linkInput.classList.toggle('is-valid', this.isLinkValid()); + this.showLinkEditor(); }); } }); @@ -136,6 +118,29 @@ export default class MarkupTooltip { }); } + public showLinkEditor() { + const button = this.buttons.link; + this.container.classList.add('is-link'); + + const selection = document.getSelection(); + this.savedRange = selection.getRangeAt(0); + + if(button.classList.contains('active')) { + const startContainer = this.savedRange.startContainer; + const anchor = startContainer.parentElement as HTMLAnchorElement; + this.linkInput.value = anchor.href; + } else { + this.linkInput.value = ''; + } + + this.setTooltipPosition(true); + + setTimeout(() => { + this.linkInput.focus(); // !!! instant focus will break animation + }, 200); + this.linkInput.classList.toggle('is-valid', this.isLinkValid()); + } + private applyLink(e: Event) { cancelEvent(e); this.resetSelection();