aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-04-01 16:11:27 -0400
committerbobzel <zzzman@gmail.com>2024-04-01 16:11:27 -0400
commit8f3d3bef02a0c43f7e951cea32aea611eb247846 (patch)
tree72b048b51d7f949db92748c16396d065067f4fcf
parent6227ac6f13ba112fc6edac340940f4543d2ac82f (diff)
fixing setting marks on ordererd_lists
-rw-r--r--src/client/views/nodes/formattedText/ProsemirrorExampleTransfer.ts7
-rw-r--r--src/client/views/nodes/formattedText/RichTextMenu.tsx7
2 files changed, 8 insertions, 6 deletions
diff --git a/src/client/views/nodes/formattedText/ProsemirrorExampleTransfer.ts b/src/client/views/nodes/formattedText/ProsemirrorExampleTransfer.ts
index ab49a53ea..92cc65fc5 100644
--- a/src/client/views/nodes/formattedText/ProsemirrorExampleTransfer.ts
+++ b/src/client/views/nodes/formattedText/ProsemirrorExampleTransfer.ts
@@ -11,7 +11,6 @@ import { Docs } from '../../../documents/Documents';
import { RTFMarkup } from '../../../util/RTFMarkup';
import { SelectionManager } from '../../../util/SelectionManager';
import { OpenWhere } from '../DocumentView';
-//import { liftListItem, sinkListItem } from './prosemirrorPatches.js';
import { Doc } from '../../../../fields/Doc';
import { EditorView } from 'prosemirror-view';
@@ -90,7 +89,7 @@ export function buildKeymap<S extends Schema<any>>(schema: S, props: any, mapKey
if (!canEdit(state)) return true;
const ref = state.selection;
const range = ref.$from.blockRange(ref.$to);
- const marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks());
+ const marks = state.storedMarks || state.selection.$to.parentOffset ? state.selection.$from.marks() : undefined;
if (
!sinkListItem(schema.nodes.list_item)(state, (tx2: Transaction) => {
const tx3 = updateBullets(tx2, schema);
@@ -103,7 +102,9 @@ export function buildKeymap<S extends Schema<any>>(schema: S, props: any, mapKey
const newstate = state.applyTransaction(state.tr.setSelection(TextSelection.create(state.doc, range!.start, range!.end)));
if (
!wrapInList(schema.nodes.ordered_list)(newstate.state as any, (tx2: Transaction) => {
- const tx3 = updateBullets(tx2, schema);
+ const tx25 = updateBullets(tx2, schema);
+ const ol_node = tx25.doc.nodeAt(range!.start)!;
+ const tx3 = tx25.setNodeMarkup(range!.start, ol_node.type, { ...ol_node.attrs, ...(marks?.[0]?.type === schema.marks.pFontSize ? { fontSize: marks[0].attrs.fontSize } : {}) });
// when promoting to a list, assume list will format things so don't copy the stored marks.
marks && tx3.ensureMarks([...marks]);
marks && tx3.setStoredMarks([...marks]);
diff --git a/src/client/views/nodes/formattedText/RichTextMenu.tsx b/src/client/views/nodes/formattedText/RichTextMenu.tsx
index b5d0f28d8..9b6eb8b8d 100644
--- a/src/client/views/nodes/formattedText/RichTextMenu.tsx
+++ b/src/client/views/nodes/formattedText/RichTextMenu.tsx
@@ -161,7 +161,8 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps> {
const liTo = numberRange(state.selection.$to.depth + 1).find(i => state.selection.$to.node(i)?.type === state.schema.nodes.list_item);
const olFirst = numberRange(state.selection.$from.depth + 1).find(i => state.selection.$from.node(i)?.type === state.schema.nodes.ordered_list);
const nodeOl = (liFirst && liTo && state.selection.$from.node(liFirst) !== state.selection.$to.node(liTo) && olFirst) || (!liFirst && !liTo && olFirst);
- const newPos = nodeOl ? numberRange(state.selection.from).findIndex(i => state.doc.nodeAt(i)?.type === state.schema.nodes.ordered_list) : state.selection.from;
+ const fromRange = numberRange(state.selection.from).reverse();
+ const newPos = nodeOl ? fromRange.find(i => state.doc.nodeAt(i)?.type === state.schema.nodes.ordered_list) ?? state.selection.from : state.selection.from;
const node = (state.selection as NodeSelection).node ?? (newPos >= 0 ? state.doc.nodeAt(newPos) : undefined);
if (node?.type === schema.nodes.ordered_list) {
let attrs = node.attrs;
@@ -370,7 +371,7 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps> {
setFontSize = (fontSize: string) => {
if (this.view) {
if (this.view.state.selection.from === 1 && this.view.state.selection.empty && (!this.view.state.doc.nodeAt(1) || !this.view.state.doc.nodeAt(1)?.marks.some(m => m.type.name === fontSize))) {
- this.TextView.dataDoc.fontSize = fontSize;
+ this.TextView.dataDoc[this.TextView.fieldKey + '_fontSize'] = fontSize;
this.view.focus();
} else {
const fmark = this.view.state.schema.marks.pFontSize.create({ fontSize });
@@ -385,7 +386,7 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps> {
setFontFamily = (family: string) => {
if (this.view) {
- const fmark = this.view.state.schema.marks.pFontFamily.create({ family: family });
+ const fmark = this.view.state.schema.marks.pFontFamily.create({ family });
this.setMark(fmark, this.view.state, (tx: any) => this.view!.dispatch(tx.addStoredMark(fmark)), true);
this.view.focus();
} else if (SelectionManager.Views.length) {