Browse Source

Ctrl+K bind for link creation

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

14
src/components/chat/input.ts

@ -671,17 +671,29 @@ export default class ChatInput {
'I': 'italic', 'I': 'italic',
'U': 'underline', 'U': 'underline',
'S': 'strikethrough', 'S': 'strikethrough',
'M': 'monospace' 'M': 'monospace',
'K': 'link'
}; };
const selection = document.getSelection();
if(selection.toString().trim().length) {
for(const key in formatKeys) { for(const key in formatKeys) {
const good = e.code == ('Key' + key); const good = e.code == ('Key' + key);
if(good) { if(good) {
// * костыльчик
if(key === 'K') {
this.appImManager.markupTooltip.showLinkEditor();
cancelEvent(e);
break;
}
this.applyMarkdown(formatKeys[key]); this.applyMarkdown(formatKeys[key]);
cancelEvent(e); // cancel legacy event cancelEvent(e); // cancel legacy event
break; break;
} }
} }
}
//return; //return;
if(e.code == 'KeyZ') { if(e.code == 'KeyZ') {

43
src/components/chat/markupTooltip.ts

@ -48,25 +48,7 @@ export default class MarkupTooltip {
} else { } else {
attachClickEvent(button, (e) => { attachClickEvent(button, (e) => {
cancelEvent(e); cancelEvent(e);
this.container.classList.add('is-link'); this.showLinkEditor();
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());
}); });
} }
}); });
@ -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) { private applyLink(e: Event) {
cancelEvent(e); cancelEvent(e);
this.resetSelection(); this.resetSelection();

Loading…
Cancel
Save