Hides the '\' from escaped characters (#901)
parent
513b9ef441
commit
1ea652a730
|
@ -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[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue