aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorab <abdullah_ahmed@brown.edu>2019-07-11 18:04:09 -0400
committerab <abdullah_ahmed@brown.edu>2019-07-11 18:04:09 -0400
commit9f3fd2717bb20ac7b84059e6eb4ad8e58dcc1b92 (patch)
tree0b3e26d50af4bd2c9e57ec587c85e543d535dbf4 /src
parent40465c791184762a491e63b6d403e4436b9e228a (diff)
started brush
Diffstat (limited to 'src')
-rw-r--r--src/client/util/TooltipTextMenu.tsx70
-rw-r--r--src/client/views/search/SearchItem.tsx6
2 files changed, 63 insertions, 13 deletions
diff --git a/src/client/util/TooltipTextMenu.tsx b/src/client/util/TooltipTextMenu.tsx
index 515d9439c..58abd6c05 100644
--- a/src/client/util/TooltipTextMenu.tsx
+++ b/src/client/util/TooltipTextMenu.tsx
@@ -19,6 +19,7 @@ import { CollectionDockingView } from "../views/collections/CollectionDockingVie
import { DocumentManager } from "./DocumentManager";
import { Id } from "../../new_fields/FieldSymbols";
import { FormattedTextBoxProps, FormattedTextBox } from "../views/nodes/FormattedTextBox";
+import { typeAlias } from "babel-types";
//appears above a selection of text in a RichTextBox to give user options such as Bold, Italics, etc.
export class TooltipTextMenu {
@@ -47,6 +48,10 @@ export class TooltipTextMenu {
private _collapseBtn?: MenuItem;
+ private _brushMarks?: Set<Mark>;
+
+ private _brushIsEmpty: boolean = true;
+
constructor(view: EditorView, editorProps: FieldViewProps & FormattedTextBoxProps) {
this.view = view;
this.editorProps = editorProps;
@@ -125,6 +130,8 @@ export class TooltipTextMenu {
this.listTypeToIcon.set(schema.nodes.ordered_list, "1)");
this.listTypes = Array.from(this.listTypeToIcon.keys());
+ this.tooltip.appendChild(this.createBrush().render(this.view).dom);
+
this.tooltip.appendChild(this.createLink().render(this.view).dom);
this.tooltip.appendChild(this.createStar().render(this.view).dom);
@@ -168,24 +175,24 @@ export class TooltipTextMenu {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (elmnt) {
// if present, the header is where you move the DIV from:
- elmnt.onmousedown = dragMouseDown;
+ elmnt.onpointerdown = dragMouseDown;
}
const self = this;
- function dragMouseDown(e: any) {
+ function dragMouseDown(e: PointerEvent) {
e = e || window.event;
- e.preventDefault();
+ //e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
- document.onmouseup = closeDragElement;
+ document.onpointerup = closeDragElement;
// call a function whenever the cursor moves:
- document.onmousemove = elementDrag;
+ document.onpointermove = elementDrag;
}
- function elementDrag(e: any) {
+ function elementDrag(e: PointerEvent) {
e = e || window.event;
- e.preventDefault();
+ //e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
@@ -198,10 +205,10 @@ export class TooltipTextMenu {
function closeDragElement() {
// stop moving when mouse button is released:
- document.onmouseup = null;
- document.onmousemove = null;
+ document.onpointerup = null;
+ document.onpointermove = null;
//self.highlightSearchTerms(self.state, ["hello"]);
- FormattedTextBox.Instance.unhighlightSearchTerms();
+ //FormattedTextBox.Instance.unhighlightSearchTerms();
}
}
@@ -291,6 +298,8 @@ export class TooltipTextMenu {
},
hideSource: false
});
+ e.stopPropagation();
+ e.preventDefault();
};
this.linkEditor.appendChild(this.linkDrag);
// this.linkEditor.appendChild(this.linkText);
@@ -433,6 +442,41 @@ export class TooltipTextMenu {
});
}
+ createBrush() {
+ return new MenuItem({
+ title: "Brush tool",
+ label: "Brush tool",
+ icon: icons.join,
+ css: "color:white;",
+ class: "summarize",
+ execEvent: "",
+ run: (state, dispatch) => {
+ this.brush_function(state, dispatch);
+ }
+
+ });
+ }
+
+ // selectionchanged event handler
+
+ brush_function(state: EditorState<any>, dispatch: any) {
+ if (this._brushIsEmpty) {
+ this._brushMarks = this.getMarksInSelection(state);
+ }
+ else {
+ let { from, to } = state.selection;
+ if (this._brushMarks && to - from > 0) {
+ this.view.state.tr.removeMark(from, to);
+ this._brushMarks.forEach((mark: Mark) => {
+ this.view.dispatch(this.view.state.tr.addMark(from, from + to, mark));
+ });
+ }
+ }
+ this._brushIsEmpty = !this._brushIsEmpty;
+
+
+ }
+
createCollapse() {
this._collapseBtn = new MenuItem({
title: "Collapse",
@@ -588,14 +632,14 @@ export class TooltipTextMenu {
};
}
- getMarksInSelection(state: EditorState<any>, targets: MarkType<any>[]) {
- let found: Mark<any>[] = [];
+ getMarksInSelection(state: EditorState<any>) {
+ let found = new Set<Mark>();
let { from, to } = state.selection as TextSelection;
state.doc.nodesBetween(from, to, (node) => {
let marks = node.marks;
if (marks) {
marks.forEach(m => {
- if (targets.includes(m.type)) found.push(m);
+ found.add(m);
});
}
});
diff --git a/src/client/views/search/SearchItem.tsx b/src/client/views/search/SearchItem.tsx
index c5a75eee1..2b8d3eda3 100644
--- a/src/client/views/search/SearchItem.tsx
+++ b/src/client/views/search/SearchItem.tsx
@@ -171,6 +171,12 @@ export class SearchItem extends React.Component<SearchItemProps> {
return [(bounds.x + bounds.r) / 2, (bounds.y + bounds.b) / 2, Number(SEARCH_THUMBNAIL_SIZE) / Math.max((bounds.b - bounds.y), (bounds.r - bounds.x)), this._displayDim];
}
+ componentWillUnmount() {
+ if (this._previewDoc) {
+ DocServer.DeleteDocument(this._previewDoc[Id]);
+ }
+ }
+
//@computed
@action