Skip to content

Commit

Permalink
🎨 fix #738
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Sep 3, 2020
1 parent 232979d commit 893a0db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

### v3.5.2 / 2020-09-xx

* [738](https://github.com/Vanessa219/vditor/issues/738) IR 模式标题变大变小快捷键及光标位置 `修复缺陷`
* [736](https://github.com/Vanessa219/vditor/issues/736) MathJax 数学公式会抖动 `改进功能`

### v3.5.1 / 2020-08-30
Expand Down
2 changes: 2 additions & 0 deletions src/ts/ir/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export const processHeading = (vditor: IVditor, value: string) => {
headingMarkerElement.innerHTML = value;
} else {
headingElement.insertAdjacentText("afterbegin", value);
range.selectNodeContents(headingElement);
range.collapse(false);
}
input(vditor, range.cloneRange());
highlightToolbarIR(vditor);
Expand Down
26 changes: 24 additions & 2 deletions src/ts/ir/processKeydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
import {hasClosestByHeadings} from "../util/hasClosestByHeadings";
import {getEditorRange, getSelectPosition, setSelectionFocus} from "../util/selection";
import {expandMarker} from "./expandMarker";
import {processAfterRender} from "./process";
import {processAfterRender, processHeading} from "./process";
import {matchHotKey} from "../util/hotKey";

export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
vditor.ir.composingLock = event.isComposing;
Expand Down Expand Up @@ -162,6 +163,28 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
return true;
}

const headingElement = hasClosestByHeadings(startContainer);
if (headingElement) {
// enter++: 标题变大
if (matchHotKey("⌘-=", event)) {
const headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading");
if (headingMarkerElement && headingMarkerElement.textContent.trim().length > 1) {
processHeading(vditor, headingMarkerElement.textContent.substr(1));
}
event.preventDefault();
return true;
}

// enter++: 标题变小
if (matchHotKey("⌘--", event)) {
const headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading");
if (headingMarkerElement && headingMarkerElement.textContent.trim().length < 6) {
processHeading(vditor, headingMarkerElement.textContent.trim() + "# ");
}
event.preventDefault();
return true;
}
}
const blockElement = hasClosestBlock(startContainer);
if (event.key === "Backspace" && !isCtrl(event) && !event.shiftKey && !event.altKey && range.toString() === "") {
if (fixDelete(vditor, range, event, pElement)) {
Expand All @@ -188,7 +211,6 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
}

// 光标位于标题前,marker 后
const headingElement = hasClosestByHeadings(startContainer);
if (headingElement) {
const headingLength = headingElement.firstElementChild.textContent.length;
if (getSelectPosition(headingElement, vditor.ir.element).start === headingLength) {
Expand Down

0 comments on commit 893a0db

Please sign in to comment.