-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #825 from obgnail/dev
Dev
- Loading branch information
Showing
5 changed files
with
84 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class editorWidthSliderPlugin extends BasePlugin { | ||
process = async () => { | ||
this.utils.runtime.autoSaveConfig(this); | ||
await this._setWidth(); | ||
} | ||
|
||
_setWidth = async (width = this.config.WIDTH_RATIO) => { | ||
const { eWrite } = this.utils.entities; | ||
if (width < 0) { | ||
eWrite.style.removeProperty("max-width"); | ||
} else { | ||
eWrite.style.setProperty("max-width", `${width}%`, "important"); | ||
} | ||
} | ||
|
||
setWidth = async () => { | ||
const { eContent, eWrite } = this.utils.entities; | ||
const value = parseInt(eWrite.offsetWidth * 100 / eContent.offsetWidth); | ||
const oninput = ev => this._setWidth(ev.target.value); | ||
const components = [ | ||
{ label: "宽度百分比", type: "range", min: 30, max: 100, step: 1, value, oninput }, | ||
{ label: "", type: "checkbox", list: [{ label: "还原宽度设置", value: "recover" }] }, | ||
]; | ||
const { response, submit: [width, [checkbox]] } = await this.utils.dialog.modalAsync({ title: "写作区宽度", components }); | ||
if (response === 1) { | ||
this.config.WIDTH_RATIO = checkbox === "recover" ? -1 : width; | ||
} | ||
await this._setWidth(); | ||
} | ||
|
||
call = async (type, meta) => await this.setWidth() | ||
} | ||
|
||
module.exports = { | ||
plugin: editorWidthSliderPlugin, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters