Browse Source

Ctrl+K bind for link creation

master
Eduard Kuzmenko 4 years ago
parent
commit
20d0adc406
  1. 26
      src/components/chat/input.ts
  2. 43
      src/components/chat/markupTooltip.ts

26
src/components/chat/input.ts

@ -671,15 +671,27 @@ export default class ChatInput { @@ -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;
}
}
}

43
src/components/chat/markupTooltip.ts

@ -48,25 +48,7 @@ export default class MarkupTooltip { @@ -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 { @@ -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…
Cancel
Save