Ctrl+K bind for link creation
This commit is contained in:
parent
c2dbe531f0
commit
20d0adc406
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user