Skip to content

Commit

Permalink
♻️ ir
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 authored and stevapple committed Apr 8, 2020
1 parent 5c6f1aa commit 8f3f7be
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/ts/ir/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ class IR {
expandMarker(getSelection().getRangeAt(0), vditor);
}
});

this.element.addEventListener("keydown", (event) => {
this.composingLock = event.isComposing;
});
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/ts/ir/processKeydown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
vditor.ir.composingLock = event.isComposing;
if (event.isComposing) {
return false;
}
}
2 changes: 2 additions & 0 deletions src/ts/toolbar/Redo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class Redo extends MenuItem {
vditor.undo.redo(vditor);
} else if (vditor.currentMode === "wysiwyg") {
vditor.wysiwygUndo.redo(vditor);
} else if (vditor.currentMode === "ir") {
vditor.irUndo.redo(vditor);
}
event.preventDefault();
});
Expand Down
2 changes: 1 addition & 1 deletion src/ts/toolbar/Undo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Undo extends MenuItem {
vditor.undo.undo(vditor);
} else if (vditor.currentMode === "wysiwyg") {
vditor.wysiwygUndo.undo(vditor);
}else if (vditor.currentMode === "ir") {
} else if (vditor.currentMode === "ir") {
vditor.irUndo.undo(vditor);
}
event.preventDefault();
Expand Down
10 changes: 10 additions & 0 deletions src/ts/upload/getElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const getElement = (vditor: IVditor) => {
switch (vditor.currentMode) {
case "ir":
return vditor.ir.element;
case "wysiwyg":
return vditor.wysiwyg.element;
case "sv":
return vditor.editor.element;
}
};
5 changes: 3 additions & 2 deletions src/ts/upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {i18n} from "../i18n/index";
import {insertText} from "../sv/insertText";
import {getEditorRange, setSelectionFocus} from "../util/selection";
import {getElement} from "./getElement";
import {setHeaders} from "./setHeaders";

class Upload {
Expand Down Expand Up @@ -73,7 +74,7 @@ const validateFile = (vditor: IVditor, files: File[]) => {
};

const genUploadedLabel = (responseText: string, vditor: IVditor) => {
const editorElement = vditor.currentMode === "sv" ? vditor.editor.element : vditor.wysiwyg.element;
const editorElement = getElement(vditor);
editorElement.focus();
const response = JSON.parse(responseText);
let errorTip = "";
Expand Down Expand Up @@ -181,7 +182,7 @@ const uploadFiles = (vditor: IVditor, files: FileList | DataTransferItemList | F
return;
}
}
const editorElement = vditor.currentMode === "sv" ? vditor.editor.element : vditor.wysiwyg.element;
const editorElement = getElement(vditor);

vditor.upload.range = getEditorRange(editorElement);

Expand Down
5 changes: 5 additions & 0 deletions src/ts/util/editorCommenEvent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {getSelectText} from "../sv/getSelectText";
import {insertText} from "../sv/insertText";
import {processKeydown as mdProcessKeydown} from "../sv/processKeydown";
import {processKeydown as irProcessKeydown} from "../ir/processKeydown";
import {setEditMode} from "../toolbar/EditMode";
import {hidePanel} from "../toolbar/setToolbar";
import {getCursorPosition} from "../util/selection";
Expand Down Expand Up @@ -87,6 +88,10 @@ export const hotkeyEvent = (vditor: IVditor, editorElement: HTMLElement) => {
if (processKeydown(vditor, event)) {
return;
}
} else if (vditor.currentMode === "ir") {
if (irProcessKeydown(vditor, event)) {
return;
}
}

if (vditor.options.ctrlEnter && matchHotKey("⌘-Enter", event)) {
Expand Down
6 changes: 3 additions & 3 deletions src/ts/wysiwyg/processKeydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
if (pElement.previousElementSibling && event.key === "Backspace" && !isCtrl(event) && !event.altKey &&
!event.shiftKey && pElement.textContent.trimRight().split("\n").length > 1 &&
getSelectPosition(pElement, range).start === 0) {
const lastElement = getLastNode(pElement.previousElementSibling) as HTMLElement
if (!lastElement.textContent.endsWith('\n')) {
lastElement.textContent = lastElement.textContent + '\n'
const lastElement = getLastNode(pElement.previousElementSibling) as HTMLElement;
if (!lastElement.textContent.endsWith("\n")) {
lastElement.textContent = lastElement.textContent + "\n";
}
lastElement.parentElement.insertAdjacentHTML("beforeend", `<wbr>${pElement.innerHTML}`);
pElement.remove();
Expand Down

0 comments on commit 8f3f7be

Please sign in to comment.