Hides the '\' from escaped characters (#901)

pull/903/head
MrMugame 2024-06-26 15:55:56 +02:00 committed by GitHub
parent 513b9ef441
commit 1ea652a730
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import { cleanWikiLinkPlugin } from "./wiki_link.ts";
import { cleanCommandLinkPlugin } from "./command_link.ts"; import { cleanCommandLinkPlugin } from "./command_link.ts";
import { fencedCodePlugin } from "./fenced_code.ts"; import { fencedCodePlugin } from "./fenced_code.ts";
import { frontmatterPlugin } from "./frontmatter.ts"; import { frontmatterPlugin } from "./frontmatter.ts";
import { cleanEscapePlugin } from "./escapes.ts";
export function cleanModePlugins(client: Client) { export function cleanModePlugins(client: Client) {
return [ return [
@ -42,5 +43,6 @@ export function cleanModePlugins(client: Client) {
tablePlugin(client), tablePlugin(client),
cleanWikiLinkPlugin(client), cleanWikiLinkPlugin(client),
cleanCommandLinkPlugin(client), cleanCommandLinkPlugin(client),
cleanEscapePlugin(),
] as Extension[]; ] as Extension[];
} }

28
web/cm_plugins/escapes.ts Normal file
View File

@ -0,0 +1,28 @@
import { EditorState } from "@codemirror/state";
import { syntaxTree } from "@codemirror/language";
import { Decoration } from "@codemirror/view";
import {
decoratorStateField,
invisibleDecoration,
isCursorInRange,
} from "./util.ts";
export function cleanEscapePlugin() {
return decoratorStateField(
(state: EditorState) => {
const widgets: any[] = [];
syntaxTree(state).iterate({
enter({ type, from, to }) {
if (
type.name === "Escape" &&
!isCursorInRange(state, [from, to])
) {
widgets.push(invisibleDecoration.range(from, from + 1));
}
},
});
return Decoration.set(widgets, true);
},
);
}