vditor 3.8.6 → 3.8.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -618,7 +618,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
618
618
  codeElement.className.indexOf("language-") > -1
619
619
  ? codeElement.className.split("-")[1].split(" ")[0]
620
620
  : "";
621
- language.oninput = () => {
621
+ language.oninput = (e: InputEvent) => {
622
622
  if (language.value.trim() !== "") {
623
623
  codeElement.className = `language-${language.value}`;
624
624
  } else {
@@ -631,6 +631,13 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
631
631
  processCodeRender(blockRenderElement.lastElementChild as HTMLElement, vditor);
632
632
  }
633
633
  afterRenderEvent(vditor);
634
+ // 当鼠标点选语言时,触发自定义input事件
635
+ if (e.detail === 1) {
636
+ // 选择语言后,输入焦点切换到代码输入框
637
+ range.setStart(codeElement.firstChild, 0);
638
+ range.collapse(true);
639
+ setSelectionFocus(range);
640
+ }
634
641
  };
635
642
  language.onkeydown = (event: KeyboardEvent) => {
636
643
  if (event.isComposing) {
@@ -647,17 +654,18 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
647
654
  event.preventDefault();
648
655
  return;
649
656
  }
657
+ vditor.hint.select(event, vditor);
650
658
  if (
651
659
  !isCtrl(event) &&
652
660
  !event.shiftKey &&
653
- event.altKey &&
654
661
  event.key === "Enter"
655
662
  ) {
656
663
  range.setStart(codeElement.firstChild, 0);
657
664
  range.collapse(true);
658
665
  setSelectionFocus(range);
666
+ event.preventDefault();
667
+ event.stopPropagation();
659
668
  }
660
- vditor.hint.select(event, vditor);
661
669
  };
662
670
  language.onkeyup = (event: KeyboardEvent) => {
663
671
  if (
@@ -39,6 +39,7 @@ class WYSIWYG {
39
39
  public preventInput: boolean;
40
40
  public composingLock = false;
41
41
  public commentIds: string[] = [];
42
+ private scrollListener: () => void;
42
43
 
43
44
  constructor(vditor: IVditor) {
44
45
  const divElement = document.createElement("div");
@@ -195,6 +196,10 @@ class WYSIWYG {
195
196
  this.selectPopover.setAttribute("style", "display:none");
196
197
  }
197
198
 
199
+ public unbindListener() {
200
+ window.removeEventListener("scroll", this.scrollListener);
201
+ }
202
+
198
203
  private copy(event: ClipboardEvent, vditor: IVditor) {
199
204
  const range = getSelection().getRangeAt(0);
200
205
  if (range.toString() === "") {
@@ -238,7 +243,8 @@ class WYSIWYG {
238
243
  }
239
244
 
240
245
  private bindEvent(vditor: IVditor) {
241
- window.addEventListener("scroll", () => {
246
+ this.unbindListener();
247
+ window.addEventListener("scroll", this.scrollListener = () => {
242
248
  hidePanel(vditor, ["hint"]);
243
249
  if (this.popover.style.display !== "block" || this.selectPopover.style.display !== "block") {
244
250
  return;
@@ -331,7 +337,7 @@ class WYSIWYG {
331
337
  this.preventInput = false;
332
338
  return;
333
339
  }
334
- if (this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
340
+ if (this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
335
341
  return;
336
342
  }
337
343
  const range = getSelection().getRangeAt(0);