aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/formattedText/RichTextRules.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-01-28 23:46:18 -0500
committerbobzel <zzzman@gmail.com>2024-01-28 23:46:18 -0500
commit1a32884f5084d9c39190e44bd9331e94590322e5 (patch)
treecb01f5028d696664cbae66567bfe9fb550f423ff /src/client/views/nodes/formattedText/RichTextRules.ts
parentb8288a83669f1c6690082a18c7f4d14a76e31586 (diff)
fixed inking when in panToScroll mode. fixed text templates to restore default text when all text is deleted. changed code blocks to stay in code black mode after a carriage return (unless its a hard break, e.g. shift+carriage return). added a ^@paint input rule to turn text documents into paint func docs.
Diffstat (limited to 'src/client/views/nodes/formattedText/RichTextRules.ts')
-rw-r--r--src/client/views/nodes/formattedText/RichTextRules.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/client/views/nodes/formattedText/RichTextRules.ts b/src/client/views/nodes/formattedText/RichTextRules.ts
index 456ed4732..be32a2c4a 100644
--- a/src/client/views/nodes/formattedText/RichTextRules.ts
+++ b/src/client/views/nodes/formattedText/RichTextRules.ts
@@ -13,6 +13,8 @@ import { FormattedTextBox } from './FormattedTextBox';
import { wrappingInputRule } from './prosemirrorPatches';
import { RichTextMenu } from './RichTextMenu';
import { schema } from './schema_rts';
+import { CollectionView } from '../../collections/CollectionView';
+import { CollectionViewType } from '../../../documents/DocumentTypes';
export class RichTextRules {
public Document: Doc;
@@ -68,6 +70,23 @@ export class RichTextRules {
// ``` create code block
textblockTypeInputRule(/^```$/, schema.nodes.code_block),
+ new InputRule(new RegExp(/^\^@paint/), (state, match, start, end) => {
+ const { dataDoc, layoutDoc, fieldKey } = this.TextBox;
+ layoutDoc.type_collection = CollectionViewType.Freeform;
+ dataDoc.layout_painted = CollectionView.LayoutString('painted');
+ const layoutFieldKey = layoutDoc.layout_fieldKey;
+ layoutDoc.layout_fieldKey = 'layout_painted';
+ this.TextBox.DocumentView?.().setToggleDetail();
+ layoutDoc.layout_fieldKey = layoutFieldKey;
+ dataDoc.paintFunc = ComputedField.MakeFunction(`toJavascriptString(this['${fieldKey}']?.Text)`);
+ const comment = '/* this is now a paint func */';
+ const tr = state.tr
+ .deleteRange(start, end)
+ .insertText(comment)
+ .insert(start + comment.length, schema.nodes.code_block.create());
+ return tr.setSelection(new TextSelection(tr.doc.resolve(start + comment.length + 2)));
+ }),
+
// %<font-size> set the font size
new InputRule(new RegExp(/%([0-9]+)\s$/), (state, match, start, end) => {
const size = Number(match[1]);