Refactoring of offline handling

This commit is contained in:
Zef Hemel
2023-07-27 11:41:44 +02:00
parent 7b8d8af2c1
commit 4d0f36d475
13 changed files with 251 additions and 206 deletions
+1 -1
View File
@@ -170,7 +170,7 @@ export function admonitionPlugin(editor: Client) {
widget: new AdmonitionIconWidget(
iconRange.from + 1,
admonitionType,
editor.editorView!,
editor.editorView,
),
inclusive: true,
}).range(iconRange.from, iconRange.to),
+1 -1
View File
@@ -49,7 +49,7 @@ export function cleanCommandLinkPlugin(editor: Client) {
(e) => {
if (e.altKey) {
// Move cursor into the link
return editor.editorView!.dispatch({
return editor.editorView.dispatch({
selection: { anchor: from + 2 },
});
}
+6 -6
View File
@@ -118,15 +118,15 @@ export function attachmentExtension(editor: Client) {
// Only do rich text paste if shift is NOT down
if (richText && !shiftDown) {
// Are we in a fencede code block?
const editorText = editor.editorView!.state.sliceDoc();
const editorText = editor.editorView.state.sliceDoc();
const tree = lezerToParseTree(
editorText,
syntaxTree(editor.editorView!.state).topNode,
syntaxTree(editor.editorView.state).topNode,
);
addParentPointers(tree);
const currentNode = nodeAtPos(
tree,
editor.editorView!.state.selection.main.from,
editor.editorView.state.selection.main.from,
);
if (currentNode) {
const fencedParentNode = findParentMatching(
@@ -141,7 +141,7 @@ export function attachmentExtension(editor: Client) {
const markdown = striptHtmlComments(turndownService.turndown(richText))
.trim();
const view = editor.editorView!;
const view = editor.editorView;
const selection = view.state.selection.main;
view.dispatch({
changes: [
@@ -221,11 +221,11 @@ export function attachmentExtension(editor: Client) {
if (mimeType.startsWith("image/")) {
attachmentMarkdown = `![](${encodeURI(finalFileName)})`;
}
editor.editorView!.dispatch({
editor.editorView.dispatch({
changes: [
{
insert: attachmentMarkdown,
from: editor.editorView!.state.selection.main.from,
from: editor.editorView.state.selection.main.from,
},
],
});
+2 -2
View File
@@ -41,7 +41,7 @@ class IFrameWidget extends WidgetType {
iframe.style.height = data.height + "px";
break;
case "setBody":
this.editor.editorView!.dispatch({
this.editor.editorView.dispatch({
changes: {
from: this.from,
to: this.to,
@@ -50,7 +50,7 @@ class IFrameWidget extends WidgetType {
});
break;
case "blur":
this.editor.editorView!.dispatch({
this.editor.editorView.dispatch({
selection: { anchor: this.from },
});
this.editor.focus();
+1 -1
View File
@@ -26,7 +26,7 @@ class TableViewWidget extends WidgetType {
// Pulling data-pos to put the cursor in the right place, falling back
// to the start of the table.
const dataAttributes = (e.target as any).dataset;
this.editor.editorView!.dispatch({
this.editor.editorView.dispatch({
selection: {
anchor: dataAttributes.pos ? +dataAttributes.pos : this.pos,
},
+1 -1
View File
@@ -90,7 +90,7 @@ export function cleanWikiLinkPlugin(editor: Client) {
callback: (e) => {
if (e.altKey) {
// Move cursor into the link
return editor.editorView!.dispatch({
return editor.editorView.dispatch({
selection: { anchor: from + 2 },
});
}