aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/RichTextRules.ts
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-01-25 12:01:15 -0500
committerBob Zeleznik <zzzman@gmail.com>2020-01-25 12:01:15 -0500
commite78f2663901b4cbd9fddc3418e40b8798ecfd994 (patch)
tree36fce56f0687418c7872fd0a03daf7f5b9c1b6f0 /src/client/util/RichTextRules.ts
parent2fac43821ee90ef914c79923b63425aefcdc8e39 (diff)
added text templates for FormattedText, added field views in formatted text box, got rid of documentText @@@ initing of FormattedText
Diffstat (limited to 'src/client/util/RichTextRules.ts')
-rw-r--r--src/client/util/RichTextRules.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/client/util/RichTextRules.ts b/src/client/util/RichTextRules.ts
index 02b7502d8..bc8a0abb1 100644
--- a/src/client/util/RichTextRules.ts
+++ b/src/client/util/RichTextRules.ts
@@ -2,7 +2,7 @@ import { textblockTypeInputRule, smartQuotes, emDash, ellipsis, InputRule } from
import { schema } from "./RichTextSchema";
import { wrappingInputRule } from "./prosemirrorPatches";
import { NodeSelection, TextSelection } from "prosemirror-state";
-import { NumCast, Cast } from "../../new_fields/Types";
+import { StrCast, Cast } from "../../new_fields/Types";
import { Doc } from "../../new_fields/Doc";
import { FormattedTextBox } from "../views/nodes/FormattedTextBox";
import { Docs, DocUtils } from "../documents/Documents";
@@ -72,6 +72,19 @@ export const inpRules = {
// make current selection a hyperlink portal (assumes % was used to initiate an EnteringStyle mode)
new InputRule(
+ new RegExp(/!$/),
+ (state, match, start, end) => {
+ if (state.selection.to === state.selection.from || !(schema as any).EnteringStyle) return null;
+ const value = state.doc.textBetween(start, end);
+
+ const node = (state.doc.resolve(start) as any).nodeAfter;
+ const sm = state.storedMarks || undefined;
+ const fieldView = state.schema.nodes.dashField.create({ fieldKey: StrCast(value) });
+ const replaced = node ? state.tr.replaceRangeWith(start, end, fieldView).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : state.tr;
+ return replaced.doc.nodeSize > end - 2 ? replaced.setSelection(new TextSelection(replaced.doc.resolve(end - 2))) : replaced;
+ }),
+ // make current selection a hyperlink portal (assumes % was used to initiate an EnteringStyle mode)
+ new InputRule(
new RegExp(/@$/),
(state, match, start, end) => {
if (state.selection.to === state.selection.from || !(schema as any).EnteringStyle) return null;
@@ -196,7 +209,7 @@ export const inpRules = {
new InputRule(
new RegExp(/%#$/),
(state, match, start, end) => {
- const target = Docs.Create.TextDocument({ _width: 75, _height: 35, backgroundColor: "yellow", annotationOn: FormattedTextBox.FocusedBox!.dataDoc, _autoHeight: true, fontSize: 9, title: "inline comment" });
+ const target = Docs.Create.TextDocument("", { _width: 75, _height: 35, backgroundColor: "yellow", annotationOn: FormattedTextBox.FocusedBox!.dataDoc, _autoHeight: true, fontSize: 9, title: "inline comment" });
const node = (state.doc.resolve(start) as any).nodeAfter;
const newNode = schema.nodes.dashComment.create({ docid: target[Id] });
const dashDoc = schema.nodes.dashDoc.create({ width: 75, height: 35, title: "dashDoc", docid: target[Id], float: "right" });