Skip to content

Commit

Permalink
Rich/MD and list continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
TRIAEIOU committed May 4, 2023
1 parent db58ca5 commit ad2bf65
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ The editor used is [CodeMirror 6](https://codemirror.net/) with the following co

### Field input mode

- Configurable default state for editor fields (`rich text` or `markdown`, default `rich text`).
- Configurable default state for editor fields (`rich text`, `markdown` or `rich text/markdown`, default `rich text`).
- Configurable behaviour of "field input mode" shortcut, cycle between rich text and Markdown (`true`) or just toggle Markdown input (`false`). (default `true`)
- Configurable shortcut to toggle rich text input. (default `Ctrl+Alt+X`)
- Configurable shortcuts to move to next/previous input (since tab is a valid Markdown character it will not work to "tab out" of a markdown input). (default `Ctrl+PgDown` and `Ctrl+PgUp`)
Expand Down Expand Up @@ -181,3 +181,4 @@ Functionality split into different classes to facilitate reuse:
- 2023-03-11: Restructuring of code to allow modularity with other projects and easier maintenance.
- 2023-03-12: Change "dialog mode" to "window mode" and inherit QMainWindow rather than QDialog. Add option to edit complete note in window mode, improve CSS styling of editor, now done from separate CSS file. Modify default styling (based on VS Code styles) to suit both light and dark mode. Fix anyoing eating of trailing spaces when focusing to another window. Add option to hide editor toolbar when focusing a Markdown field.
- 2023-04-26: Improve logic to fix anoying eating of trailing spaces, change search/replace dialog placement so that it is visible without having to scroll.
- 2023-05-04: Add `rich text/markdown` field default configuration option, add list continuation thanks to [David C.](https://github.com/d-k-bo).
2 changes: 1 addition & 1 deletion src/py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
config = mw.addonManager.getConfig(__name__)

CVER = get_version()
NVER = "2.2.1"
NVER = "2.2.2"

msgs = []
if strvercmp(CVER, '2.2.0') < 0:
Expand Down
4 changes: 2 additions & 2 deletions src/ts/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {defaultKeymap, historyKeymap, indentWithTab, history} from "@codemirror/
import {closeBrackets, closeBracketsKeymap} from "@codemirror/autocomplete"
import {highlightSelectionMatches, search} from "search"
import {autocompletion, completionKeymap} from "@codemirror/autocomplete"
import {markdown, markdownKeymap, markdownLanguage } from "@codemirror/lang-markdown"
import {ankiImagePaste } from "./CodeMirror.extensions/ankiImagePaste"
import {markdown, markdownKeymap, markdownLanguage} from "@codemirror/lang-markdown"
import {ankiImagePaste} from "./CodeMirror.extensions/ankiImagePaste"
import {classHighlighter} from '@lezer/highlight'
import {Subscript, Superscript, Strikethrough, Table} from "@lezer/markdown"

Expand Down
15 changes: 15 additions & 0 deletions src/ts/field_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const MD = '<!--?xml version="1.0" encoding="UTF-8"?--><svg xmlns="http://www.w3

let _config
let _converter
let _editor_count

/////////////////////////////////////////////////////////////////////////////
// Non-arrow function (for `this` use) to instantiate an editor instance
Expand Down Expand Up @@ -79,7 +80,20 @@ function onadd() {
if (_config[FIELD_INPUT]?.[FIELD_DEFAULT]?.toLowerCase() === 'markdown') {
this.toggle()
this.toggle_rich()
} else if (_config[FIELD_INPUT]?.[FIELD_DEFAULT]?.toLowerCase() === 'rich text/markdown') {
this.toggle()
// Ugly temporary hack to focus first Markdown input initially
if(!_editor_count) {
window.requestAnimationFrame(() =>
window.requestAnimationFrame(() =>
window.requestAnimationFrame(() =>
this.editor.cm.focus()
)
)
)
}
}
_editor_count++
}

/////////////////////////////////////////////////////////////////////////////
Expand All @@ -98,6 +112,7 @@ function init(cfg: Configuration) {
onadd: onadd,
badge: MD
})
_editor_count = 0
}

/////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit ad2bf65

Please sign in to comment.