aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/util/RichTextSchema.tsx2
-rw-r--r--src/client/views/nodes/FormattedTextBox.tsx21
-rw-r--r--src/client/views/nodes/FormattedTextBoxComment.tsx41
3 files changed, 47 insertions, 17 deletions
diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx
index ee0c0870a..f8da98f17 100644
--- a/src/client/util/RichTextSchema.tsx
+++ b/src/client/util/RichTextSchema.tsx
@@ -335,7 +335,7 @@ export const marks: { [index: string]: MarkSpec } = {
attrs: {
userid: { default: "" },
hide_users: { default: [] },
- opened: { default: false }
+ opened: { default: true }
},
group: "inline",
inclusive: false,
diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx
index 2485760df..c23b85e83 100644
--- a/src/client/views/nodes/FormattedTextBox.tsx
+++ b/src/client/views/nodes/FormattedTextBox.tsx
@@ -714,27 +714,32 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
const pos = view.posAtCoords({ left: e.clientX, top: e.clientY });
const rpos = pos && view.state.doc.resolve(pos.pos);
let noselection = view.state.selection.$from === view.state.selection.$to;
+ let set = false;
if (pos && rpos) {
let nbef = findStartOfMark(rpos, view, findOtherUserMark);
let naft = findEndOfMark(rpos, view, findOtherUserMark);
- const spos = view.state.doc.resolve(pos.pos - nbef);
- const epos = view.state.doc.resolve(pos.pos + naft);
- let ts = new TextSelection(spos, epos);
+ const spos = pos.pos - nbef;
+ const epos = pos.pos + naft;
let child = rpos.nodeBefore || rpos.nodeAfter;
let mark = child && findOtherUserMark(child.marks);
if (mark && child && (nbef || naft) && (!mark.attrs.opened || noselection)) {
- let opened = e.button === 2 ? false : !mark.attrs.opened;
- SelectionSizeTooltip.tooltip.style.display = opened ? "" : "none";
- let mid = opened ? epos : view.state.doc.resolve((spos.pos + epos.pos) / 2);
- let nmark = view.state.schema.marks.user_mark.create({ ...mark.attrs, userid: e.button === 2 ? Doc.CurrentUserEmail : mark.attrs.userid, opened: opened });
- view.dispatch(view.state.tr.addMark(ts.from, ts.to, nmark).setSelection(new TextSelection(mid, mid)));
+ SelectionSizeTooltip.SetState(this, mark.attrs.opened, spos, epos, mark);
+ set = true;
}
}
+ !set && SelectionSizeTooltip.Hide();
if (e.buttons === 1 && this.props.isSelected() && !e.altKey) {
e.stopPropagation();
}
}
+ setAnnotation = (start: number, end: number, mark: Mark, opened: boolean, keep: boolean = false) => {
+ let view = this._editorView!;
+ let mid = view.state.doc.resolve(Math.round((start + end) / 2));
+ let nmark = view.state.schema.marks.user_mark.create({ ...mark.attrs, userid: keep ? Doc.CurrentUserEmail : mark.attrs.userid, opened: opened });
+ view.dispatch(view.state.tr.removeMark(start, end, nmark).addMark(start, end, nmark).setSelection(new TextSelection(mid, mid)));
+ }
+
@action
onFocused = (e: React.FocusEvent): void => {
document.removeEventListener("keypress", this.recordKeyHandler);
diff --git a/src/client/views/nodes/FormattedTextBoxComment.tsx b/src/client/views/nodes/FormattedTextBoxComment.tsx
index e88c85a86..31eb06427 100644
--- a/src/client/views/nodes/FormattedTextBoxComment.tsx
+++ b/src/client/views/nodes/FormattedTextBoxComment.tsx
@@ -1,6 +1,5 @@
-import { Plugin, EditorState, TextSelection } from "prosemirror-state"
+import { Plugin, EditorState } from "prosemirror-state"
import './FormattedTextBoxComment.scss'
-import { DragManager } from "../../util/DragManager";
import { ResolvedPos, Mark } from "prosemirror-model";
import { EditorView } from "prosemirror-view";
import { Doc } from "../../../new_fields/Doc";
@@ -35,18 +34,43 @@ export function findEndOfMark(rpos: ResolvedPos, view: EditorView, finder: (mark
return after;
}
+
export class SelectionSizeTooltip {
- static tooltip: any;
+ static tooltip: HTMLElement;
+ static start: number;
+ static end: number;
+ static mark: Mark;
+ static opened: boolean;
+ static textBox: any;
constructor(view: any) {
if (!SelectionSizeTooltip.tooltip) {
+ const root = document.getElementById("root");
SelectionSizeTooltip.tooltip = document.createElement("div");
SelectionSizeTooltip.tooltip.className = "FormattedTextBox-tooltip";
- DragManager.Root().appendChild(SelectionSizeTooltip.tooltip);
+ SelectionSizeTooltip.tooltip.style.pointerEvents = "all";
+ SelectionSizeTooltip.tooltip.onpointerdown = (e: PointerEvent) => {
+ SelectionSizeTooltip.opened = !SelectionSizeTooltip.opened;
+ SelectionSizeTooltip.textBox.setAnnotation(
+ SelectionSizeTooltip.start, SelectionSizeTooltip.end, SelectionSizeTooltip.mark,
+ SelectionSizeTooltip.opened, e.button == 2);
+ };
+ root && root.appendChild(SelectionSizeTooltip.tooltip);
}
-
this.update(view, undefined);
}
+ public static Hide() {
+ SelectionSizeTooltip.textBox = undefined;
+ SelectionSizeTooltip.tooltip && (SelectionSizeTooltip.tooltip.style.display = "none");
+ }
+ public static SetState(textBox: any, opened: boolean, start: number, end: number, mark: Mark) {
+ SelectionSizeTooltip.textBox = textBox;
+ SelectionSizeTooltip.start = start;
+ SelectionSizeTooltip.end = end;
+ SelectionSizeTooltip.mark = mark;
+ SelectionSizeTooltip.opened = opened;
+ SelectionSizeTooltip.textBox && SelectionSizeTooltip.tooltip && (SelectionSizeTooltip.tooltip.style.display = "");
+ }
update(view: EditorView, lastState?: EditorState) {
let state = view.state;
@@ -59,12 +83,13 @@ export class SelectionSizeTooltip {
let naft = findEndOfMark(state.selection.$from, view, findOtherUserMark);
let child = state.selection.$from.nodeBefore;
let mark = child && findOtherUserMark(child.marks);
- if (mark && child && nbef && naft && mark.attrs.opened && SelectionSizeTooltip.tooltip.offsetParent) {
+ if (mark && child && nbef && naft) {
SelectionSizeTooltip.tooltip.textContent = mark.attrs.userid;
// These are in screen coordinates
- let start = view.coordsAtPos(state.selection.from), end = view.coordsAtPos(state.selection.to);
+ // let start = view.coordsAtPos(state.selection.from), end = view.coordsAtPos(state.selection.to);
+ let start = view.coordsAtPos(state.selection.from - nbef), end = view.coordsAtPos(state.selection.from - nbef);
// The box in which the tooltip is positioned, to use as base
- let box = SelectionSizeTooltip.tooltip.offsetParent.getBoundingClientRect();
+ let box = (document.getElementById("main-div") as any).getBoundingClientRect();
// Find a center-ish x position from the selection endpoints (when
// crossing lines, end may be more to the left)
let left = Math.max((start.left + end.left) / 2, start.left + 3);