From bf73b629c78d0db0b8d4bcf6aadd6609b3fe1689 Mon Sep 17 00:00:00 2001
From: ab <abdullah_ahmed@brown.edu>
Date: Tue, 11 Jun 2019 12:02:00 -0400
Subject: star node, trying to set selection as its attribute for copy/paste
 like behavior

---
 src/client/util/TooltipTextMenu.tsx | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

(limited to 'src/client/util/TooltipTextMenu.tsx')

diff --git a/src/client/util/TooltipTextMenu.tsx b/src/client/util/TooltipTextMenu.tsx
index 366105ad9..c5d016547 100644
--- a/src/client/util/TooltipTextMenu.tsx
+++ b/src/client/util/TooltipTextMenu.tsx
@@ -1,6 +1,6 @@
 import { action, IReactionDisposer, reaction } from "mobx";
 import { Dropdown, DropdownSubmenu, MenuItem, MenuItemSpec, renderGrouped, icons, } from "prosemirror-menu"; //no import css
-import { baseKeymap, lift } from "prosemirror-commands";
+import { baseKeymap, lift, deleteSelection } from "prosemirror-commands";
 import { history, redo, undo } from "prosemirror-history";
 import { keymap } from "prosemirror-keymap";
 import { EditorState, Transaction, NodeSelection, TextSelection } from "prosemirror-state";
@@ -28,6 +28,7 @@ import { CollectionDockingView } from "../views/collections/CollectionDockingVie
 import { DocumentManager } from "./DocumentManager";
 import { Id } from "../../new_fields/FieldSymbols";
 import { Utils } from "../../Utils";
+// import { wrap } from "module";
 
 const SVG = "http://www.w3.org/2000/svg";
 
@@ -74,7 +75,7 @@ export class TooltipTextMenu {
             { command: toggleMark(schema.marks.strikethrough), dom: this.icon("S", "strikethrough", "Strikethrough") },
             { command: toggleMark(schema.marks.superscript), dom: this.icon("s", "superscript", "Superscript") },
             { command: toggleMark(schema.marks.subscript), dom: this.icon("s", "subscript", "Subscript") },
-            { command: toggleMark(schema.marks.collapse), dom: this.icon("C", 'collapse', 'Collapse') }
+            { command: deleteSelection, dom: this.icon("C", 'collapse', 'Collapse') }
             // { command: wrapInList(schema.nodes.bullet_list), dom: this.icon(":", "bullets") },
             // { command: wrapInList(schema.nodes.ordered_list), dom: this.icon("1)", "bullets") },
             // { command: lift, dom: this.icon("<", "lift") },
@@ -274,18 +275,18 @@ export class TooltipTextMenu {
     insertStar(state: EditorState<any>, dispatch: any) {
         console.log("creating star...");
         let type = schema.nodes.star;
-        //let {$from} = state.selection;
         let select = state.selection;
+        let node = select.$from.nodeAfter;
+        if (node) {
+            console.log("node");
+            console.log(node.type.name);
+            if (node.type.name === "star") {
+                console.log(node.attrs.oldtext);
+            }
+        }
         if (dispatch) {
-            dispatch(state.tr.setMeta('select.visible', false));
+            dispatch(state.tr.replaceSelectionWith(type.create({ attrs: { oldtext: select } })));
         }
-        // console.log($from);
-        // if (!$from.parent.canReplaceWith($from.index(), $from.index(), type)) {
-        //     return false;
-        // }
-        // if (dispatch) {
-        //     dispatch(state.tr.replaceSelectionWith(type.create()));
-        // }
         return true;
     }
 
-- 
cgit v1.2.3-70-g09d2

