From a4b4a7a847fa99b23ea1ced98cf203228c25c902 Mon Sep 17 00:00:00 2001 From: Ran Luo Date: Mon, 21 Oct 2019 10:42:05 +0800 Subject: [PATCH] Feat: add user preference whether hide the link popup (#1504) --- docs/PREFERENCES.md | 36 ++++++++++--------- src/main/preferences/schema.json | 5 +++ src/muya/lib/config/index.js | 1 + src/muya/lib/eventHandler/mouseEvent.js | 3 +- .../components/editorWithTabs/editor.vue | 11 +++++- src/renderer/prefComponents/editor/index.vue | 6 ++++ src/renderer/store/preferences.js | 1 + static/preference.json | 1 + 8 files changed, 45 insertions(+), 19 deletions(-) diff --git a/docs/PREFERENCES.md b/docs/PREFERENCES.md index 8028bbd0..e73a8c1c 100644 --- a/docs/PREFERENCES.md +++ b/docs/PREFERENCES.md @@ -19,23 +19,24 @@ Preferences can be controlled and modified in the settings window or via the `pr #### Editor -| Key | Type | Defaut | Description | -| ---------------------- | ------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| fontSize | Number | 16 | Font size in pixels. 12 ~ 32 | -| editorFontFamily | String | Open Sans | Font Family | -| lineHeight | Number | 1.6 | Line Height | -| autoPairBracket | Boolean | true | Automatically brackets when editing | -| autoPairMarkdownSyntax | Boolean | true | Autocomplete markdown syntax | -| autoPairQuote | Boolean | true | Automatic completion of quotes | -| endOfLine | String | default | The newline character used at the end of each line. The default value is default, which will be selected according to your system intelligence. `lf` `crlf` `default` | -| textDirection | String | ltr | The writing text direction, optional value: `ltr` or `rtl` | -| codeFontSize | Number | 14 | Font size on code block, the range is 12 ~ 28 | -| codeFontFamily | String | `DejaVu Sans Mono` | Code font family | -| trimUnnecessaryCodeBlockEmptyLines | Boolean | true | Whether to trim the beginning and end empty line in Code block | -| hideQuickInsertHint | Boolean | false | Hide hint for quickly creating paragraphs | -| imageDropAction | String | folder | The default behavior after paste or drag the image to Mark Text, upload it to the image cloud (if configured), move to the specified folder, insert the path | -| defaultEncoding | String | `utf8` | The default file encoding | -| autoGuessEncoding | Boolean | true | Try to automatically guess the file encoding when opening files | +| Key | Type | Defaut | Description | +| ---------------------------------- | ------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| fontSize | Number | 16 | Font size in pixels. 12 ~ 32 | +| editorFontFamily | String | Open Sans | Font Family | +| lineHeight | Number | 1.6 | Line Height | +| autoPairBracket | Boolean | true | Automatically brackets when editing | +| autoPairMarkdownSyntax | Boolean | true | Autocomplete markdown syntax | +| autoPairQuote | Boolean | true | Automatic completion of quotes | +| endOfLine | String | default | The newline character used at the end of each line. The default value is default, which will be selected according to your system intelligence. `lf` `crlf` `default` | +| textDirection | String | ltr | The writing text direction, optional value: `ltr` or `rtl` | +| codeFontSize | Number | 14 | Font size on code block, the range is 12 ~ 28 | +| codeFontFamily | String | `DejaVu Sans Mono` | Code font family | +| trimUnnecessaryCodeBlockEmptyLines | Boolean | true | Whether to trim the beginning and end empty line in Code block | +| hideQuickInsertHint | Boolean | false | Hide hint for quickly creating paragraphs | +| imageDropAction | String | folder | The default behavior after paste or drag the image to Mark Text, upload it to the image cloud (if configured), move to the specified folder, insert the path | +| defaultEncoding | String | `utf8` | The default file encoding | +| autoGuessEncoding | Boolean | true | Try to automatically guess the file encoding when opening files | +| hideLinkPopup | Boolean | false | It will not show the link popup when hover over the link if set `hideLinkPopup` to true | #### Markdown @@ -48,6 +49,7 @@ Preferences can be controlled and modified in the settings window or via the `pr | tabSize | Number | 4 | The number of spaces a tab is equal to | | listIndentation | String | 1 | The list indentation of sub list items or paragraphs, optional value `dfm`, `tab` or number 1~4 | | frontmatterType | String | `-` | The frontmatter type: `-` (YAML), `+` (TOML), `;` (JSON) or `{` (JSON) | + #### Theme | Key | Type | Default | Description | diff --git a/src/main/preferences/schema.json b/src/main/preferences/schema.json index 50a63ca4..334e1f42 100644 --- a/src/main/preferences/schema.json +++ b/src/main/preferences/schema.json @@ -176,6 +176,11 @@ "description": "Editor--Hide hint for quickly creating paragraphs", "type": "boolean" }, + "hideLinkPopup": { + "description": "Editor--Hide link popup when the cursor is hover on the link", + "type": "boolean", + "default": false + }, "preferLooseListItem": { "description": "Markdown--The preferred list type", diff --git a/src/muya/lib/config/index.js b/src/muya/lib/config/index.js index 760798cc..b6ca8832 100644 --- a/src/muya/lib/config/index.js +++ b/src/muya/lib/config/index.js @@ -255,6 +255,7 @@ export const MUYA_DEFAULT_OPTION = { mermaidTheme: 'default', // dark / forest / default vegaTheme: 'latimes', // excel / ggplot2 / quartz / vox / fivethirtyeight / dark / latimes hideQuickInsertHint: false, + hideLinkPopup: false, // Whether we should set spellcheck attribute on our container to highlight misspelled words. // NOTE: The browser is not able to correct misspelled words words without a custom // implementation like in Mark Text. diff --git a/src/muya/lib/eventHandler/mouseEvent.js b/src/muya/lib/eventHandler/mouseEvent.js index edf98193..3aed62b7 100644 --- a/src/muya/lib/eventHandler/mouseEvent.js +++ b/src/muya/lib/eventHandler/mouseEvent.js @@ -12,7 +12,8 @@ class MouseEvent { const handler = event => { const target = event.target const parent = target.parentNode - if (parent && parent.tagName === 'A' && parent.classList.contains('ag-inline-rule')) { + const { hideLinkPopup } = this.muya.options + if (!hideLinkPopup && parent && parent.tagName === 'A' && parent.classList.contains('ag-inline-rule')) { const rect = parent.getBoundingClientRect() const reference = { getBoundingClientRect () { diff --git a/src/renderer/components/editorWithTabs/editor.vue b/src/renderer/components/editorWithTabs/editor.vue index caf16e6c..cb3b4d07 100644 --- a/src/renderer/components/editorWithTabs/editor.vue +++ b/src/renderer/components/editorWithTabs/editor.vue @@ -144,6 +144,7 @@ export default { trimUnnecessaryCodeBlockEmptyLines: state => state.preferences.trimUnnecessaryCodeBlockEmptyLines, editorFontFamily: state => state.preferences.editorFontFamily, hideQuickInsertHint: state => state.preferences.hideQuickInsertHint, + hideLinkPopup: state => state.preferences.hideLinkPopup, editorLineWidth: state => state.preferences.editorLineWidth, imageInsertAction: state => state.preferences.imageInsertAction, imageFolderPath: state => state.preferences.imageFolderPath, @@ -291,6 +292,12 @@ export default { editor.setOptions({ orderListDelimiter: value }) } }, + hideLinkPopup: function (value, oldValue) { + const { editor } = this + if (value !== oldValue && editor) { + editor.setOptions({ hideLinkPopup: value }) + } + }, codeFontSize: function (value, oldValue) { if (value !== oldValue) { addCommonStyle({ @@ -434,7 +441,8 @@ export default { hideQuickInsertHint, editorLineWidth, theme, - spellcheckerEnabled + spellcheckerEnabled, + hideLinkPopup } = this // use muya UI plugins @@ -471,6 +479,7 @@ export default { listIndentation, frontmatterType, hideQuickInsertHint, + hideLinkPopup, spellcheckEnabled: spellcheckerEnabled, imageAction: this.imageAction.bind(this), imagePathPicker: this.imagePathPicker.bind(this), diff --git a/src/renderer/prefComponents/editor/index.vue b/src/renderer/prefComponents/editor/index.vue index 8a34c084..de75761c 100644 --- a/src/renderer/prefComponents/editor/index.vue +++ b/src/renderer/prefComponents/editor/index.vue @@ -91,6 +91,11 @@ :bool="hideQuickInsertHint" :onChange="value => onSelectChange('hideQuickInsertHint', value)" > + state.preferences.codeFontFamily, trimUnnecessaryCodeBlockEmptyLines: state => state.preferences.trimUnnecessaryCodeBlockEmptyLines, hideQuickInsertHint: state => state.preferences.hideQuickInsertHint, + hideLinkPopup: state => state.preferences.hideLinkPopup, editorLineWidth: state => state.preferences.editorLineWidth, defaultEncoding: state => state.preferences.defaultEncoding, autoGuessEncoding: state => state.preferences.autoGuessEncoding diff --git a/src/renderer/store/preferences.js b/src/renderer/store/preferences.js index 40192ff5..c58b7b82 100644 --- a/src/renderer/store/preferences.js +++ b/src/renderer/store/preferences.js @@ -31,6 +31,7 @@ const state = { textDirection: 'ltr', hideQuickInsertHint: false, imageInsertAction: 'folder', + hideLinkPopup: false, preferLooseListItem: true, bulletListMarker: '-', diff --git a/static/preference.json b/static/preference.json index 43b0c626..7a2d29f8 100644 --- a/static/preference.json +++ b/static/preference.json @@ -28,6 +28,7 @@ "textDirection": "ltr", "hideQuickInsertHint": false, "imageInsertAction": "path", + "hideLinkPopup": false, "preferLooseListItem": true, "bulletListMarker": "-",