Skip to content

Commit

Permalink
🎨 #411 标题快捷键导致光标重置
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Aug 1, 2020
1 parent 8f19808 commit 7ffccf1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ window.vditor = new Vditor('vditor', {
// _lutePath: `http://192.168.0.107:9090/lute.min.js?${new Date().getTime()}`,
_lutePath: 'src/js/lute/lute.min.js',
toolbar,
mode: 'wysiwyg',
mode: 'ir',
height: window.innerHeight + 100,
outline: true,
debugger: true,
Expand Down
17 changes: 6 additions & 11 deletions src/ts/ir/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import {Constants} from "../constants";
import {getMarkdown} from "../markdown/getMarkdown";
import {removeCurrentToolbar} from "../toolbar/setToolbar";
import {accessLocalStorage} from "../util/compatibility";
import {listToggle, renderToc} from "../util/fixBrowserBehavior";
import {listToggle} from "../util/fixBrowserBehavior";
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName, hasClosestByMatchTag} from "../util/hasClosest";
import {getEditorRange, getSelectPosition, setRangeByWbr, setSelectionFocus} from "../util/selection";
import {highlightToolbarIR} from "./highlightToolbarIR";
import {input} from "./input";

export const processHint = (vditor: IVditor) => {
vditor.hint.render(vditor);
Expand Down Expand Up @@ -80,19 +81,13 @@ export const processHeading = (vditor: IVditor, value: string) => {
const headingElement = hasClosestBlock(range.startContainer) || range.startContainer as HTMLElement;
if (headingElement) {
const headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading");
if (value === "") {
range.selectNodeContents(headingMarkerElement);
setSelectionFocus(range);
document.execCommand("delete");
if (headingMarkerElement) {
headingMarkerElement.innerHTML = value;
} else {
headingMarkerElement.remove();
range.selectNodeContents(headingElement);
range.collapse(true);
setSelectionFocus(range);
document.execCommand("insertHTML", false, value);
headingElement.insertAdjacentText("afterbegin", value);
}
input(vditor, range.cloneRange());
highlightToolbarIR(vditor);
renderToc(vditor);
}
};

Expand Down

0 comments on commit 7ffccf1

Please sign in to comment.