Skip to content

Commit

Permalink
🐛 fix #36
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jan 6, 2020
1 parent 78cc8ed commit 74a1995
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
* v1.7
* `option.preivew.show?: boolean` => `option.preivew.mode?: string`
* 移除 `option.editorName`

### TODO

* [3](https://github.com/Vanessa219/vditor/issues/3) 编辑预览同步滚动改进 `enhancement`
* [4](https://github.com/Vanessa219/vditor/issues/4) 添加支持思维导图的功能 `enhancement`
* [31](https://github.com/Vanessa219/vditor/issues/31) merge list `bug`
* [37](https://github.com/Vanessa219/vditor/issues/37) 为 wysiwyg 代码块添加快捷键 `引入特性`

### v2.0.12 / 2020-01-05

* [36](https://github.com/Vanessa219/vditor/issues/36) two 'enter' at code block `修复缺陷`
* [32](https://github.com/Vanessa219/vditor/issues/32) 反斜杠转义处理 `修复缺陷`
* [33](https://github.com/Vanessa219/vditor/issues/33) 插入链接优化 `improvement`
* [30](https://github.com/Vanessa219/vditor/issues/30) 添加 option.value `enhancement`
Expand Down
8 changes: 2 additions & 6 deletions src/ts/util/editorCommenEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {getSelectText} from "../editor/getSelectText";
import {insertText} from "../editor/insertText";
import {getCursorPosition} from "../hint/getCursorPosition";
import {getText} from "../util/getText";
import {deleteKey} from "../wysiwyg/processKeydown";
import {deleteKey, tabKey} from "../wysiwyg/processKeydown";
import {getCurrentLinePosition} from "./getCurrentLinePosition";
import {hasClosestByClassName} from "./hasClosest";

Expand Down Expand Up @@ -116,11 +116,7 @@ export const hotkeyEvent = (vditor: IVditor, editorElement: HTMLElement) => {
event.preventDefault();
event.stopPropagation();
if (vditor.currentMode === "wysiwyg") {
if (event.shiftKey) {
document.execCommand("outdent", false);
} else {
document.execCommand("indent", false);
}
tabKey(vditor, event)
return;
}

Expand Down
36 changes: 34 additions & 2 deletions src/ts/wysiwyg/processKeydown.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {setSelectionFocus} from "../editor/setSelection";
import {hasClosestByAttribute, hasClosestByMatchTag} from "../util/hasClosest";
import {hasClosestByAttribute, hasClosestByClassName, hasClosestByMatchTag} from "../util/hasClosest";
import {processCodeRender} from "./processCodeRender";
import {afterRenderEvent} from "./afterRenderEvent";

export const deleteKey = (vditor: IVditor, event: Event) => {
export const deleteKey = (vditor: IVditor, event: KeyboardEvent) => {
const range = getSelection().getRangeAt(0);
const startContainer = range.startContainer as HTMLElement;

Expand Down Expand Up @@ -81,3 +83,33 @@ export const deleteKey = (vditor: IVditor, event: Event) => {
}
}
};

export const tabKey = (vditor: IVditor, event: KeyboardEvent) => {
const range = getSelection().getRangeAt(0)
const codeElement = hasClosestByMatchTag(range.startContainer, 'CODE')
if (event.shiftKey) {
if (codeElement) {
// TODO 代码块缩进
}
} else {
if (range.collapsed) {
range.insertNode(document.createTextNode(vditor.options.tab));
range.collapse(false);
} else {
if (codeElement) {
// TODO 代码块缩进
} else {
range.extractContents();
range.insertNode(document.createTextNode(vditor.options.tab));
range.collapse(false);
}
}
}

const blockRenderElement = hasClosestByClassName(range.startContainer, 'vditor-wysiwyg__block')
if (blockRenderElement) {
processCodeRender(blockRenderElement, vditor);
}

afterRenderEvent(vditor);
}

0 comments on commit 74a1995

Please sign in to comment.