Skip to content

Commit

Permalink
🐛 fix #294
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Apr 10, 2020
1 parent a0e6d91 commit 2659c8a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 40 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

* [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 `修复缺陷`
* [285](https://github.com/Vanessa219/vditor/issues/285) shift+tab is not working at lists `修复缺陷`
Expand Down
3 changes: 1 addition & 2 deletions src/assets/scss/_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@
}

&:after {
$height: var(--editor-bottom);
content: "";
height: var(--editor-bottom-fullscreen, $height);
height: var(--editor-bottom);
display: block;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/assets/scss/_ir.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@
}

&:after {
$height: var(--editor-bottom);
content: "";
height: var(--editor-bottom-fullscreen, $height);
height: var(--editor-bottom);
display: block;
}

Expand Down
3 changes: 1 addition & 2 deletions src/assets/scss/_wysiwyg.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
}

&:after {
$height: var(--editor-bottom);
content: "";
height: var(--editor-bottom-fullscreen, $height);
height: var(--editor-bottom);
display: block;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/ts/toolbar/EditMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {i18n} from "../i18n";
import {highlightToolbar as IRHighlightToolbar} from "../ir/highlightToolbar";
import {processAfterRender} from "../ir/process";
import {formatRender} from "../sv/formatRender";
import {setPadding} from "../ui/initUI";
import {setPadding, setTypewriterPosition} from "../ui/initUI";
import {getEventName, updateHotkeyTip} from "../util/compatibility";
import {getMarkdown} from "../util/getMarkdown";
import {processCodeRender} from "../util/processCode";
import {highlightToolbar} from "../wysiwyg/highlightToolbar";
import {renderDomByMd} from "../wysiwyg/renderDomByMd";
import {MenuItem} from "./MenuItem";
import {enableToolbar, hidePanel, hideToolbar, removeCurrentToolbar, showToolbar} from "./setToolbar";
import {disableToolbar, enableToolbar, hidePanel, hideToolbar, removeCurrentToolbar, showToolbar} from "./setToolbar";

export const setEditMode = (vditor: IVditor, type: string, event: Event | string) => {
let markdownText;
Expand All @@ -37,6 +37,7 @@ export const setEditMode = (vditor: IVditor, type: string, event: Event | string
}
enableToolbar(vditor.toolbar.elements, Constants.TOOLBARS);
removeCurrentToolbar(vditor.toolbar.elements, Constants.TOOLBARS);
disableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);

if (type === "ir") {
hideToolbar(vditor.toolbar.elements, ["format", "both", "preview"]);
Expand Down Expand Up @@ -106,6 +107,7 @@ export const setEditMode = (vditor: IVditor, type: string, event: Event | string
vditor.sv.element.focus();
}
}
setTypewriterPosition(vditor);
};

export class EditMode extends MenuItem {
Expand Down
13 changes: 3 additions & 10 deletions src/ts/toolbar/Fullscreen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import contractSVG from "../../assets/icons/contract.svg";
import fullscreenSVG from "../../assets/icons/fullscreen.svg";
import {setPadding} from "../ui/initUI";
import {setPadding, setTypewriterPosition} from "../ui/initUI";
import {getEventName} from "../util/compatibility";
import {MenuItem} from "./MenuItem";

Expand All @@ -12,17 +12,10 @@ export class Fullscreen extends MenuItem {
}

public _bindEvent(vditor: IVditor, menuItem: IMenuItem) {
const setTypewriterPosition = () => {
// 由于 Firefox padding-bottom bug,只能使用 :after
vditor.element.style.setProperty("--editor-bottom-fullscreen", (window.innerHeight / 2 - 18) + "px");
};

this.element.children[0].addEventListener(getEventName(), function(event) {
event.preventDefault();
if (vditor.element.className.includes("vditor--fullscreen")) {
this.innerHTML = menuItem.icon || fullscreenSVG;
vditor.element.style.removeProperty("--editor-bottom-fullscreen");
window.removeEventListener("resize", setTypewriterPosition);
vditor.element.classList.remove("vditor--fullscreen");
Object.keys(vditor.toolbar.elements).forEach((key) => {
const svgElement = vditor.toolbar.elements[key].firstChild as HTMLElement;
Expand All @@ -32,8 +25,6 @@ export class Fullscreen extends MenuItem {
});
} else {
this.innerHTML = menuItem.icon || contractSVG;
setTypewriterPosition();
window.addEventListener("resize", setTypewriterPosition);
vditor.element.classList.add("vditor--fullscreen");
Object.keys(vditor.toolbar.elements).forEach((key) => {
const svgElement = vditor.toolbar.elements[key].firstChild as HTMLElement;
Expand All @@ -52,6 +43,8 @@ export class Fullscreen extends MenuItem {
}

setPadding(vditor);

setTypewriterPosition(vditor);
});
}
}
43 changes: 21 additions & 22 deletions src/ts/ui/initUI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {html2md} from "../sv/html2md";
import {setEditMode} from "../toolbar/EditMode";
import {scrollCenter} from "../util/editorCommonEvent";
import {setTheme} from "./setTheme";

export const initUI = (vditor: IVditor) => {
Expand Down Expand Up @@ -73,32 +72,32 @@ export const setPadding = (vditor: IVditor) => {
}
};

const afterRender = (vditor: IVditor, contentElement: HTMLElement) => {
const setTypewriterPosition = () => {
let height: number;
if (typeof vditor.options.height !== "number") {
height = window.innerHeight;
} else {
height = vditor.options.height;
if (typeof vditor.options.minHeight === "number") {
height = Math.max(height, vditor.options.minHeight + vditor.toolbar.element.offsetHeight);
}
height = Math.min(window.innerHeight, height);
export const setTypewriterPosition = (vditor: IVditor) => {
if (!vditor.options.typewriterMode) {
return;
}
let height: number = window.innerHeight;
if (typeof vditor.options.height === "number") {
height = vditor.options.height;
if (typeof vditor.options.minHeight === "number") {
height = Math.max(height, vditor.options.minHeight);
}
// 由于 Firefox padding-bottom bug,只能使用 :after
contentElement.style.setProperty("--editor-bottom", (height / 2 - 18) + "px");
};

if (vditor.options.typewriterMode) {
setTypewriterPosition();
height = Math.min(window.innerHeight, height);
}
if (vditor.element.classList.contains("vditor--fullscreen")) {
height = window.innerHeight;
}
// 由于 Firefox padding-bottom bug,只能使用 :after
vditor[vditor.currentMode].element.style.setProperty("--editor-bottom",
((height - vditor.toolbar.element.offsetHeight) / 2) + "px");
};

const afterRender = (vditor: IVditor, contentElement: HTMLElement) => {
setTypewriterPosition(vditor);

window.addEventListener("resize", () => {
setPadding(vditor);
if (vditor.options.typewriterMode) {
setTypewriterPosition();
scrollCenter(vditor);
}
setTypewriterPosition(vditor);
});

// set default value
Expand Down

0 comments on commit 2659c8a

Please sign in to comment.