From 07c0368ac83d9d8a286a1ae20ead2598e97f98fb Mon Sep 17 00:00:00 2001 From: Liyuan Li Date: Wed, 15 Apr 2020 01:40:31 +0800 Subject: [PATCH 1/8] :arrow_up: vditor --- app/package-lock.json | 6 +++--- app/package.json | 2 +- app/src/editors/webview.ts | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/package-lock.json b/app/package-lock.json index d56b1a1..476f9ef 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -7389,9 +7389,9 @@ } }, "vditor": { - "version": "3.1.6", - "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.6.tgz", - "integrity": "sha512-CfMNtdHbGNsLk5iWuuVxuTKmKY3Zv8R2w/XN7ez25LoLHKsFE+iCZCLxmcOwSli2BmybW/xXMtOyVCg2+IZZKg==", + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.9.tgz", + "integrity": "sha512-uwZnl/umgx3HKayEqCnyN6BSa41uU3VzR45DBaql0HdnqoKvpkO2vauYDjSJQFAy8gGalLu6jQ/v9Iw37uPqbg==", "requires": { "diff-match-patch": "^1.0.4" } diff --git a/app/package.json b/app/package.json index 00326ed..2182ed0 100644 --- a/app/package.json +++ b/app/package.json @@ -54,6 +54,6 @@ "webpack-cli": "^3.3.10" }, "dependencies": { - "vditor": "^3.1.6" + "vditor": "^3.1.9" } } diff --git a/app/src/editors/webview.ts b/app/src/editors/webview.ts index 992c304..c282bd6 100644 --- a/app/src/editors/webview.ts +++ b/app/src/editors/webview.ts @@ -162,6 +162,7 @@ export class EditorWebview { } }, }, + 'outline', 'devtools', 'info', 'help', @@ -171,6 +172,9 @@ export class EditorWebview { cache: { enable: false }, + counter: { + enable: true + }, cdn: remote.getGlobal('liandiEditor').appDir + "/node_modules/vditor", preview: { markdown: { @@ -189,6 +193,7 @@ export class EditorWebview { style: liandi.config.theme === 'dark' ? 'native' : 'github' } }, + height: window.innerHeight - 20, upload: { setHeaders: () => { return { From 2e840f6e2dd3785c0ae1c49745e9762b2e6397a0 Mon Sep 17 00:00:00 2001 From: Liyuan Li Date: Wed, 15 Apr 2020 11:24:09 +0800 Subject: [PATCH 2/8] :arrow_up: vditor --- app/package-lock.json | 6 +++--- app/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/package-lock.json b/app/package-lock.json index 476f9ef..5b445a8 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -7389,9 +7389,9 @@ } }, "vditor": { - "version": "3.1.9", - "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.9.tgz", - "integrity": "sha512-uwZnl/umgx3HKayEqCnyN6BSa41uU3VzR45DBaql0HdnqoKvpkO2vauYDjSJQFAy8gGalLu6jQ/v9Iw37uPqbg==", + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.10.tgz", + "integrity": "sha512-WKkowreJoBVE+8NV2h7ZYMVUfXyui8PpOBr9Eike/HSoRQLLkTkFV1LP4rC8JH4oH05eqXqRBhcgrzMMe9ZGaQ==", "requires": { "diff-match-patch": "^1.0.4" } diff --git a/app/package.json b/app/package.json index 2182ed0..0be1c68 100644 --- a/app/package.json +++ b/app/package.json @@ -54,6 +54,6 @@ "webpack-cli": "^3.3.10" }, "dependencies": { - "vditor": "^3.1.9" + "vditor": "^3.1.10" } } From 85826dde2082b0af78024b6643d9071ff209a5e1 Mon Sep 17 00:00:00 2001 From: Liyuan Li Date: Fri, 17 Apr 2020 01:06:30 +0800 Subject: [PATCH 3/8] :arrow_up: vditor --- app/package-lock.json | 6 +++--- app/package.json | 2 +- app/src/editors/webview.ts | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/package-lock.json b/app/package-lock.json index 5b445a8..2fc2763 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -7389,9 +7389,9 @@ } }, "vditor": { - "version": "3.1.10", - "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.10.tgz", - "integrity": "sha512-WKkowreJoBVE+8NV2h7ZYMVUfXyui8PpOBr9Eike/HSoRQLLkTkFV1LP4rC8JH4oH05eqXqRBhcgrzMMe9ZGaQ==", + "version": "3.1.11", + "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.11.tgz", + "integrity": "sha512-+RBgMhB+zJcOOVYbKrIRJIoHEw5FgPLYeDqyq3+KsTsyvXoDgi5os375a4+taqowBihYE/vNdAH1vpurWVaQHw==", "requires": { "diff-match-patch": "^1.0.4" } diff --git a/app/package.json b/app/package.json index 0be1c68..12bdb29 100644 --- a/app/package.json +++ b/app/package.json @@ -54,6 +54,6 @@ "webpack-cli": "^3.3.10" }, "dependencies": { - "vditor": "^3.1.10" + "vditor": "^3.1.11" } } diff --git a/app/src/editors/webview.ts b/app/src/editors/webview.ts index c282bd6..f358f97 100644 --- a/app/src/editors/webview.ts +++ b/app/src/editors/webview.ts @@ -132,6 +132,8 @@ export class EditorWebview { 'line', 'code', 'inline-code', + 'insert-before', + 'insert-after', '|', 'upload', 'table', From 71fd1c6abb3daf1275a66bc244cd7fc3e5089f8b Mon Sep 17 00:00:00 2001 From: Liyuan Li Date: Fri, 17 Apr 2020 23:38:16 +0800 Subject: [PATCH 4/8] :arrow_up: vditor --- app/package-lock.json | 6 +++--- app/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/package-lock.json b/app/package-lock.json index 2fc2763..7b9dd7a 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -7389,9 +7389,9 @@ } }, "vditor": { - "version": "3.1.11", - "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.11.tgz", - "integrity": "sha512-+RBgMhB+zJcOOVYbKrIRJIoHEw5FgPLYeDqyq3+KsTsyvXoDgi5os375a4+taqowBihYE/vNdAH1vpurWVaQHw==", + "version": "3.1.12", + "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.12.tgz", + "integrity": "sha512-PuGnHtC3hDM8vxGWv01+jzCLT+sC4UeeGyDtQNtUJbj8TrFmqTKKVlM8NLfeGx80nHan+xByrNF4FxntUGuAfw==", "requires": { "diff-match-patch": "^1.0.4" } diff --git a/app/package.json b/app/package.json index 12bdb29..536c082 100644 --- a/app/package.json +++ b/app/package.json @@ -54,6 +54,6 @@ "webpack-cli": "^3.3.10" }, "dependencies": { - "vditor": "^3.1.11" + "vditor": "^3.1.12" } } From 0988fee361cf38ee55aa4d75df78e4add0105c16 Mon Sep 17 00:00:00 2001 From: Liyuan Li Date: Thu, 30 Apr 2020 13:10:36 +0800 Subject: [PATCH 5/8] :arrow_up: vditor --- app/package-lock.json | 6 +++--- app/package.json | 2 +- app/src/editors/webview.ts | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/package-lock.json b/app/package-lock.json index 7b9dd7a..ef053b2 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -7389,9 +7389,9 @@ } }, "vditor": { - "version": "3.1.12", - "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.12.tgz", - "integrity": "sha512-PuGnHtC3hDM8vxGWv01+jzCLT+sC4UeeGyDtQNtUJbj8TrFmqTKKVlM8NLfeGx80nHan+xByrNF4FxntUGuAfw==", + "version": "3.1.20", + "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.1.20.tgz", + "integrity": "sha512-M1z9xIcjpP2mHyKJ9+a+5GaKXx0cNPyf58yMoJOJBSljGLVO3YNkMhqHUMfoZWiz9Ohf7DZTc4LctYPeGFsl5w==", "requires": { "diff-match-patch": "^1.0.4" } diff --git a/app/package.json b/app/package.json index 536c082..4a62225 100644 --- a/app/package.json +++ b/app/package.json @@ -54,6 +54,6 @@ "webpack-cli": "^3.3.10" }, "dependencies": { - "vditor": "^3.1.12" + "vditor": "^3.1.20" } } diff --git a/app/src/editors/webview.ts b/app/src/editors/webview.ts index f358f97..7e4a984 100644 --- a/app/src/editors/webview.ts +++ b/app/src/editors/webview.ts @@ -183,6 +183,7 @@ export class EditorWebview { autoSpace: liandi.config.markdown.autoSpace, chinesePunct: liandi.config.markdown.chinesePunct, fixTermTypo: liandi.config.markdown.fixTermTypo, + theme: liandi.config.theme, toc: liandi.config.markdown.toc, footnotes: liandi.config.markdown.footnotes, setext: liandi.config.markdown.setext From 651cddbe37a2bb0e35bff0030b6e552e72dff269 Mon Sep 17 00:00:00 2001 From: Liyuan Li Date: Thu, 30 Apr 2020 15:48:24 +0800 Subject: [PATCH 6/8] :children_crossing: fix #45 --- app/src/hotkey/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/hotkey/index.ts b/app/src/hotkey/index.ts index 187a671..a05b3c9 100644 --- a/app/src/hotkey/index.ts +++ b/app/src/hotkey/index.ts @@ -5,7 +5,7 @@ import {initSearch} from '../search'; export const initGlobalKeyPress = (liandi?: ILiandi) => { let lastKeypressTime = 0; - window.addEventListener('keyup', (event) => { + window.addEventListener('keydown', (event) => { // 快捷搜素 if (event.key === 'Shift') { const thisKeypressTime = new Date().getTime(); From f75372c1820f9bba1b40003cb21b114e0f678ff5 Mon Sep 17 00:00:00 2001 From: Liyuan Li Date: Thu, 30 Apr 2020 16:37:20 +0800 Subject: [PATCH 7/8] :sparkles: fix #49 --- app/src/config/search.ts | 4 +++- app/src/constants.ts | 1 + app/src/editors/index.ts | 8 +++++++- app/src/editors/webview.ts | 10 +++++++++- app/src/hotkey/index.ts | 9 +++++---- app/src/search/index.ts | 10 ++++++++-- app/src/types/index.d.ts | 1 + app/src/websocket/index.ts | 1 + 8 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/src/config/search.ts b/app/src/config/search.ts index 7b9bcac..9329659 100644 --- a/app/src/config/search.ts +++ b/app/src/config/search.ts @@ -69,7 +69,9 @@ export const initConfigSearch = (liandi: ILiandi, element: HTMLElement) => { return; } if (event.key === 'Escape') { - destroyDialog(); + destroyDialog(() => { + liandi.editors.focus(); + }); event.preventDefault(); } }); diff --git a/app/src/constants.ts b/app/src/constants.ts index dbf60f1..aa1001c 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -11,6 +11,7 @@ export abstract class Constants { public static readonly LIANDI_EDITOR_OPEN: string = 'liandi-editor-open'; public static readonly LIANDI_EDITOR_FULLSCREEN: string = 'liandi-editor-fullscreen'; public static readonly LIANDI_EDITOR_RESTORE: string = 'liandi-editor-restore'; + public static readonly LIANDI_EDITOR_CURSOR: string = 'liandi-editor-cursor'; public static readonly LIANDI_WEBSOCKET_PUT: string = 'liandi-websocket-put'; diff --git a/app/src/editors/index.ts b/app/src/editors/index.ts index 7a74bf5..5dafbfa 100644 --- a/app/src/editors/index.ts +++ b/app/src/editors/index.ts @@ -1,5 +1,6 @@ import {rename} from '../util/rename'; import {remote} from 'electron'; +import {Constants} from "../constants"; export class Editors { private inputElement: HTMLInputElement; @@ -34,7 +35,12 @@ export class Editors { this.editorWebviewElement.classList.add('fn__none'); } - sendMessage(message: string, liandi: ILiandi, editorData?: { content: string, name: string }) { + focus() { + this.editorWebviewElement.focus(); + this.sendMessage(Constants.LIANDI_EDITOR_CURSOR); + } + + sendMessage(message: string, liandi?: ILiandi, editorData?: { content: string, name: string }) { if (editorData) { remote.getGlobal('liandiEditor').editorText = editorData.content; this.inputElement.value = editorData.name.replace(".md", ""); diff --git a/app/src/editors/webview.ts b/app/src/editors/webview.ts index 7e4a984..b84e655 100644 --- a/app/src/editors/webview.ts +++ b/app/src/editors/webview.ts @@ -10,10 +10,12 @@ const Vditor = require('vditor'); export class EditorWebview { private isInitMenu: boolean; private vditor: any; + private range: Range; constructor() { this.isInitMenu = false; - initGlobalKeyPress(); + this.range = document.createRange(); + initGlobalKeyPress(this); this.onMessage(); if (process.platform === 'win32') { document.body.classList.add('body--win32'); @@ -88,6 +90,11 @@ export class EditorWebview { ipcRenderer.on(Constants.LIANDI_EDITOR_RELOAD, (event, data) => { this.onOpen(data); }); + ipcRenderer.on(Constants.LIANDI_EDITOR_CURSOR, (event, data) => { + const selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(this.range); + }); } private isCtrl(event: KeyboardEvent) { @@ -214,6 +221,7 @@ export class EditorWebview { this.vditor.setValue(value); remote.getGlobal('liandiEditor').editorText = value; remote.getGlobal('liandiEditor').saved = true; + this.vditor.focus(); }, input: (textContent: string) => { remote.getGlobal('liandiEditor').editorText = textContent; diff --git a/app/src/hotkey/index.ts b/app/src/hotkey/index.ts index a05b3c9..58ffcd7 100644 --- a/app/src/hotkey/index.ts +++ b/app/src/hotkey/index.ts @@ -2,7 +2,7 @@ import {Constants} from '../constants'; import {ipcRenderer} from 'electron'; import {initSearch} from '../search'; -export const initGlobalKeyPress = (liandi?: ILiandi) => { +export const initGlobalKeyPress = (liandi: ILiandi | any) => { let lastKeypressTime = 0; window.addEventListener('keydown', (event) => { @@ -12,10 +12,11 @@ export const initGlobalKeyPress = (liandi?: ILiandi) => { if (thisKeypressTime - lastKeypressTime <= Constants.DOUBLE_DELTA && thisKeypressTime - lastKeypressTime >= 50) { // 防止 win32 长按 lastKeypressTime = 0; - if (liandi) { - initSearch(liandi); - } else { + if (liandi.range) { + liandi.range = getSelection().getRangeAt(0) ipcRenderer.sendToHost(Constants.LIANDI_SEARCH_OPEN); + } else { + initSearch(liandi); } } lastKeypressTime = thisKeypressTime; diff --git a/app/src/search/index.ts b/app/src/search/index.ts index fecb0a8..c644d71 100644 --- a/app/src/search/index.ts +++ b/app/src/search/index.ts @@ -7,6 +7,7 @@ import {initConfigSearch} from '../config/search'; import {getPath, removeLastPath} from '../util/path'; import {markdown} from '../config/markdown'; import {image} from '../config/image'; +import {Constants} from "../constants"; export const quickOpenFile = (liandi: ILiandi, dialogElement: Element) => { const currentList: HTMLElement = dialogElement.querySelector('div[data-name="search"] .list__item--current'); @@ -76,7 +77,10 @@ export const initSearch = (liandi: ILiandi) => { `, width: Math.max(window.innerWidth - 520, 600), - height: 520 + height: 520, + destroyDialogCallback: () => { + liandi.editors.focus(); + } }); const dialogElement = document.querySelector('#dialog'); @@ -102,7 +106,9 @@ export const initSearch = (liandi: ILiandi) => { return; } if (event.key === 'Escape') { - destroyDialog(); + destroyDialog(() => { + liandi.editors.focus(); + }); event.preventDefault(); } let currentList: HTMLElement = dialogElement.querySelector('div[data-name="search"] .list__item--current'); diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 3364de7..a8ae052 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -59,6 +59,7 @@ declare interface ILiandi { onRename: (liandi: ILiandi, data: { newPath: string, oldPath: string, newName: string }) => void }; editors?: { + focus: () => void; save: (liandi:ILiandi) => void; close: (liandi:ILiandi) => void; sendMessage: (message: string, liandi: ILiandi, editorData?: { content: string, name: string }) => void; diff --git a/app/src/websocket/index.ts b/app/src/websocket/index.ts index 4388688..8914843 100644 --- a/app/src/websocket/index.ts +++ b/app/src/websocket/index.ts @@ -114,6 +114,7 @@ export class WebSocketUtil { liandi.files.onLs(liandi, response.data); break; case 'get': + liandi.editors.focus() liandi.editors.sendMessage(Constants.LIANDI_EDITOR_OPEN, liandi, response.data); break; case 'searchget': From 123fe8df11af18dfd26254ad913d8abc9ff24caa Mon Sep 17 00:00:00 2001 From: Liyuan Li Date: Thu, 30 Apr 2020 16:39:27 +0800 Subject: [PATCH 8/8] :rotating_light: --- app/src/config/image.ts | 4 ++-- app/src/config/markdown.ts | 2 +- app/src/editors/index.ts | 4 ++-- app/src/editors/webview.ts | 18 +++++++++--------- app/src/hotkey/index.ts | 2 +- app/src/i18n/index.ts | 2 +- app/src/search/index.ts | 2 +- app/src/util/dialog.ts | 2 +- app/src/websocket/index.ts | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/src/config/image.ts b/app/src/config/image.ts index 4e2c86d..748cd04 100644 --- a/app/src/config/image.ts +++ b/app/src/config/image.ts @@ -16,7 +16,7 @@ export const image = { }); }); }, - onSetimage: (liandi: ILiandi, image: IImage) => { - liandi.config.image = image; + onSetimage: (liandi: ILiandi, imageConfig: IImage) => { + liandi.config.image = imageConfig; } }; diff --git a/app/src/config/markdown.ts b/app/src/config/markdown.ts index bc67ecb..d2b712f 100644 --- a/app/src/config/markdown.ts +++ b/app/src/config/markdown.ts @@ -14,7 +14,7 @@ export const markdown = { +