Make auto-closing of HTML tags default but optional (#2101)

This commit is contained in:
Matthias Metelka 2022-10-03 05:14:57 +02:00 committed by GitHub
parent 76065e843b
commit 9b878a2229
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 1 deletions

View file

@ -62,6 +62,7 @@ editing-unordered-list = Unordered list
editing-warning-cloze-deletions-will-not-work = Warning, cloze deletions will not work until you switch the type at the top to Cloze. editing-warning-cloze-deletions-will-not-work = Warning, cloze deletions will not work until you switch the type at the top to Cloze.
editing-toggle-mathjax-rendering = Toggle MathJax Rendering editing-toggle-mathjax-rendering = Toggle MathJax Rendering
editing-shrink-images = Shrink Images editing-shrink-images = Shrink Images
editing-close-html-tags = Auto-close HTML tags
## You don't need to translate these strings, as they will be replaced with different ones soon. ## You don't need to translate these strings, as they will be replaced with different ones soon.

View file

@ -536,6 +536,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
setTagsCollapsed({}); setTagsCollapsed({});
setMathjaxEnabled({}); setMathjaxEnabled({});
setShrinkImages({}); setShrinkImages({});
setCloseHTMLTags({});
""".format( """.format(
json.dumps(data), json.dumps(data),
json.dumps(collapsed), json.dumps(collapsed),
@ -549,6 +550,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
json.dumps(self.mw.pm.tags_collapsed(self.editorMode)), json.dumps(self.mw.pm.tags_collapsed(self.editorMode)),
json.dumps(self.mw.col.get_config("renderMathjax", True)), json.dumps(self.mw.col.get_config("renderMathjax", True)),
json.dumps(self.mw.col.get_config("shrinkEditorImages", True)), json.dumps(self.mw.col.get_config("shrinkEditorImages", True)),
json.dumps(self.mw.col.get_config("closeHTMLTags", True)),
) )
if self.addMode: if self.addMode:
@ -1169,6 +1171,12 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
not self.mw.col.get_config("shrinkEditorImages", True), not self.mw.col.get_config("shrinkEditorImages", True),
) )
def toggleCloseHTMLTags(self) -> None:
self.mw.col.set_config(
"closeHTMLTags",
not self.mw.col.get_config("closeHTMLTags", True),
)
def collapseTags(self) -> None: def collapseTags(self) -> None:
aqt.mw.pm.set_tags_collapsed(self.editorMode, True) aqt.mw.pm.set_tags_collapsed(self.editorMode, True)
@ -1203,6 +1211,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
mathjaxChemistry=Editor.insertMathjaxChemistry, mathjaxChemistry=Editor.insertMathjaxChemistry,
toggleMathjax=Editor.toggleMathjax, toggleMathjax=Editor.toggleMathjax,
toggleShrinkImages=Editor.toggleShrinkImages, toggleShrinkImages=Editor.toggleShrinkImages,
toggleCloseHTMLTags=Editor.toggleCloseHTMLTags,
expandTags=Editor.expandTags, expandTags=Editor.expandTags,
collapseTags=Editor.collapseTags, collapseTags=Editor.collapseTags,
) )

View file

@ -68,6 +68,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import MathjaxElement from "./MathjaxElement.svelte"; import MathjaxElement from "./MathjaxElement.svelte";
import Notification from "./Notification.svelte"; import Notification from "./Notification.svelte";
import PlainTextInput from "./plain-text-input"; import PlainTextInput from "./plain-text-input";
import { closeHTMLTags } from "./plain-text-input/PlainTextInput.svelte";
import PlainTextBadge from "./PlainTextBadge.svelte"; import PlainTextBadge from "./PlainTextBadge.svelte";
import RichTextInput, { editingInputIsRichText } from "./rich-text-input"; import RichTextInput, { editingInputIsRichText } from "./rich-text-input";
import RichTextBadge from "./RichTextBadge.svelte"; import RichTextBadge from "./RichTextBadge.svelte";
@ -278,6 +279,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$shrinkImagesByDefault = shrinkByDefault; $shrinkImagesByDefault = shrinkByDefault;
} }
function setCloseHTMLTags(closeTags: boolean) {
$closeHTMLTags = closeTags;
}
import { mathjaxConfig } from "../editable/mathjax-element"; import { mathjaxConfig } from "../editable/mathjax-element";
import { wrapInternal } from "../lib/wrap"; import { wrapInternal } from "../lib/wrap";
import { refocusInput } from "./helpers"; import { refocusInput } from "./helpers";
@ -313,6 +318,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
setMathjaxEnabled, setMathjaxEnabled,
setInsertSymbolsEnabled, setInsertSymbolsEnabled,
setShrinkImages, setShrinkImages,
setCloseHTMLTags,
...oldEditorAdapter, ...oldEditorAdapter,
}); });

View file

@ -10,6 +10,7 @@ import "codemirror/addon/fold/foldcode";
import "codemirror/addon/fold/foldgutter"; import "codemirror/addon/fold/foldgutter";
import "codemirror/addon/fold/xml-fold"; import "codemirror/addon/fold/xml-fold";
import "codemirror/addon/edit/matchtags"; import "codemirror/addon/edit/matchtags";
import "codemirror/addon/edit/closetag";
import "codemirror/addon/display/placeholder"; import "codemirror/addon/display/placeholder";
import CodeMirror from "codemirror"; import CodeMirror from "codemirror";

View file

@ -11,6 +11,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { bridgeCommand } from "../../lib/bridgecommand"; import { bridgeCommand } from "../../lib/bridgecommand";
import * as tr from "../../lib/ftl"; import * as tr from "../../lib/ftl";
import { shrinkImagesByDefault } from "../image-overlay/ImageOverlay.svelte"; import { shrinkImagesByDefault } from "../image-overlay/ImageOverlay.svelte";
import { closeHTMLTags } from "../plain-text-input/PlainTextInput.svelte";
import { cogIcon } from "./icons"; import { cogIcon } from "./icons";
let showFloating = false; let showFloating = false;
@ -20,6 +21,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
bridgeCommand("toggleShrinkImages"); bridgeCommand("toggleShrinkImages");
showFloating = false; showFloating = false;
} }
function toggleCloseHTMLTags(_evt: MouseEvent): void {
$closeHTMLTags = !$closeHTMLTags;
bridgeCommand("toggleCloseHTMLTags");
showFloating = false;
}
</script> </script>
<WithFloating <WithFloating
@ -43,5 +50,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<CheckBox value={$shrinkImagesByDefault} /> <CheckBox value={$shrinkImagesByDefault} />
<span class="d-flex-inline ps-3">{tr.editingShrinkImages()}</span> <span class="d-flex-inline ps-3">{tr.editingShrinkImages()}</span>
</DropdownItem> </DropdownItem>
<DropdownItem on:click={toggleCloseHTMLTags}>
<CheckBox value={$closeHTMLTags} />
<span class="d-flex-inline ps-3">{tr.editingCloseHtmlTags()}</span>
</DropdownItem>
</Popover> </Popover>
</WithFloating> </WithFloating>

View file

@ -16,6 +16,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
export const parsingInstructions: string[] = []; export const parsingInstructions: string[] = [];
export const closeHTMLTags = writable(true);
const [lifecycle, instances, setupLifecycleHooks] = const [lifecycle, instances, setupLifecycleHooks] =
lifecycleHooks<PlainTextInputAPI>(); lifecycleHooks<PlainTextInputAPI>();
@ -43,10 +44,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export let hidden = false; export let hidden = false;
export let richTextHidden: boolean; export let richTextHidden: boolean;
const configuration = { $: configuration = {
mode: htmlanki, mode: htmlanki,
...baseOptions, ...baseOptions,
...gutterOptions, ...gutterOptions,
...{ autoCloseTags: $closeHTMLTags },
}; };
const { focusedInput } = noteEditorContext.get(); const { focusedInput } = noteEditorContext.get();