Skip to content

Commit

Permalink
🐛 fix #295
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Apr 10, 2020
1 parent 2659c8a commit 8125da9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

### v3.1.4 / 2020-04-0x

* [295](https://github.com/Vanessa219/vditor/issues/295) 全屏模式下打字机行为异常 `修复缺陷`
* [294](https://github.com/Vanessa219/vditor/pull/294) 🐛 计算全屏 typewriterMode 位置 `修复缺陷`
* [286](https://github.com/Vanessa219/vditor/issues/286) add indent & outdent button `引入特性`
* [291](https://github.com/Vanessa219/vditor/pull/291) 🎨 改进 Counter `修复缺陷`
Expand Down
3 changes: 3 additions & 0 deletions src/ts/ir/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class IR {
if (event.isComposing || isCtrl(event)) {
return;
}
if (event.key === "Enter") {
scrollCenter(vditor);
}
highlightToolbar(vditor);
if ((event.key === "Backspace" || event.key === "Delete") &&
vditor.ir.element.innerHTML !== "" && vditor.ir.element.childNodes.length === 1 &&
Expand Down
5 changes: 0 additions & 5 deletions src/ts/ir/processKeydown.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {isCtrl} from "../util/compatibility";
import {scrollCenter} from "../util/editorCommonEvent";
import {
fixBlockquote,
fixCodeBlock,
Expand Down Expand Up @@ -151,9 +150,5 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
return true;
}

if (event.key === "Enter") {
scrollCenter(vditor);
}

return false;
};
11 changes: 6 additions & 5 deletions src/ts/util/editorCommonEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ export const focusEvent = (vditor: IVditor, editorElement: HTMLElement) => {
};

export const scrollCenter = (vditor: IVditor) => {
if (vditor.options.typewriterMode && typeof vditor.options.height === "string") {
if (vditor.options.typewriterMode && typeof vditor.options.height === "string"
&& !vditor.element.classList.contains("vditor--fullscreen")) {
window.scrollTo(window.scrollX, vditor.element.clientHeight + vditor.element.offsetTop - window.innerHeight);

}
if (typeof vditor.options.height === "number") {
if (typeof vditor.options.height === "number" || vditor.element.classList.contains("vditor--fullscreen")) {
const editorElement = vditor[vditor.currentMode].element;
const cursorTop = getCursorPosition(editorElement).top;
const center = editorElement.clientHeight / 2;
if (cursorTop > center) {
editorElement.scrollTop = editorElement.scrollTop + (cursorTop - center);
}
if (cursorTop < 0) {
editorElement.scrollTop = editorElement.scrollTop + (cursorTop - center) + 32;
} else if (cursorTop < 0) {
editorElement.scrollTop = editorElement.scrollTop + cursorTop;
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {uploadFiles} from "../upload";
import {isCtrl, isFirefox} from "../util/compatibility";
import {focusEvent, hotkeyEvent, selectEvent} from "../util/editorCommonEvent";
import {focusEvent, hotkeyEvent, scrollCenter, selectEvent} from "../util/editorCommonEvent";
import {isHeadingMD, isHrMD, paste, renderToc} from "../util/fixBrowserBehavior";
import {
hasClosestBlock, hasClosestByAttribute,
Expand Down Expand Up @@ -237,7 +237,11 @@ class WYSIWYG {
if (event.isComposing || isCtrl(event)) {
return;
}

// 除 md 处理、cell 内换行、table 添加新行/列、代码块语言切换、block render 换行、跳出/逐层跳出 blockquote、h6 换行、
// 任务列表换行、软换行外需在换行时调整文档位置
if (event.key === "Enter") {
scrollCenter(vditor);
}
if ((event.key === "Backspace" || event.key === "Delete") &&
vditor.wysiwyg.element.innerHTML !== "" && vditor.wysiwyg.element.childNodes.length === 1 &&
vditor.wysiwyg.element.firstElementChild && vditor.wysiwyg.element.firstElementChild.tagName === "P"
Expand Down
7 changes: 0 additions & 7 deletions src/ts/wysiwyg/processKeydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,5 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
});
}
}

// 除 md 处理、cell 内换行、table 添加新行/列、代码块语言切换、block render 换行、跳出/逐层跳出 blockquote、h6 换行、
// 任务列表换行、软换行外需在换行时调整文档位置
if (event.key === "Enter") {
scrollCenter(vditor);
}

return false;
};

0 comments on commit 8125da9

Please sign in to comment.