aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-09-03 08:03:43 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-09-03 08:03:43 -0400
commit4a1d94325d5d1b5641cd280e89c442c114074e8d (patch)
tree83f9564428c9af22cf02cbc1fde82f21a79db599
parentdc7990e969bff201fefe050ac321b2d2d1d58059 (diff)
cleanup names for formattedTextBoxComment stuff. fixed brushing bug with user_mark.
-rw-r--r--src/client/util/RichTextSchema.tsx2
-rw-r--r--src/client/util/TooltipTextMenu.tsx6
-rw-r--r--src/client/views/nodes/FormattedTextBox.tsx12
-rw-r--r--src/client/views/nodes/FormattedTextBoxComment.tsx70
4 files changed, 41 insertions, 49 deletions
diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx
index 3161467b8..7911cf629 100644
--- a/src/client/util/RichTextSchema.tsx
+++ b/src/client/util/RichTextSchema.tsx
@@ -346,7 +346,7 @@ export const marks: { [index: string]: MarkSpec } = {
return hidden ?
(node.attrs.opened ?
['span', { class: "userMarkOpen" }, 0] :
- ['span', { class: "userMark" }, ['span', { style: "font-size:2" }, 0]]
+ ['span', { class: "userMark" }, ['span', 0]]
) :
['span', 0];
}
diff --git a/src/client/util/TooltipTextMenu.tsx b/src/client/util/TooltipTextMenu.tsx
index 3b4b7f05a..ce7b04e31 100644
--- a/src/client/util/TooltipTextMenu.tsx
+++ b/src/client/util/TooltipTextMenu.tsx
@@ -60,8 +60,6 @@ export class TooltipTextMenu {
@observable
private _storedMarks: Mark<any>[] | null | undefined;
- public HackToFixTextSelectionGlitch: boolean = false;
-
constructor(view: EditorView, editorProps: FieldViewProps & FormattedTextBoxProps) {
this.view = view;
@@ -629,7 +627,7 @@ export class TooltipTextMenu {
if (!this.view.state.selection.empty && $from && $from.nodeAfter) {
if (this._brushMarks && to - from > 0) {
this.view.dispatch(this.view.state.tr.removeMark(from, to));
- this._brushMarks.forEach((mark: Mark) => {
+ Array.from(this._brushMarks).filter(m => m.type !== schema.marks.user_mark).forEach((mark: Mark) => {
const markType = mark.type;
this.changeToMarkInGroup(markType, this.view, []);
@@ -876,8 +874,6 @@ export class TooltipTextMenu {
this.updateFontSizeDropdown("Various");
}
}
- !this.HackToFixTextSelectionGlitch &&
- this.view.dispatch(this.view.state.tr.setStoredMarks(this._activeMarks)); // bcz: what's the purpose of this line? It messes up text selection without the Hack.
this.update_mark_doms();
}
diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx
index 93ac2f06f..6232dd3ab 100644
--- a/src/client/views/nodes/FormattedTextBox.tsx
+++ b/src/client/views/nodes/FormattedTextBox.tsx
@@ -37,8 +37,7 @@ import { DocumentDecorations } from '../DocumentDecorations';
import { DictationManager } from '../../util/DictationManager';
import { ReplaceStep } from 'prosemirror-transform';
import { DocumentType } from '../../documents/DocumentTypes';
-import { selectionSizePlugin, findStartOfMark, findUserMark, findEndOfMark, findOtherUserMark, SelectionSizeTooltip } from './FormattedTextBoxComment';
-import { date } from 'serializr';
+import { formattedTextBoxCommentPlugin, FormattedTextBoxComment } from './FormattedTextBoxComment';
library.add(faEdit);
library.add(faSmile, faTextHeight, faUpload);
@@ -172,9 +171,7 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
dispatchTransaction = (tx: Transaction) => {
if (this._editorView) {
const state = this._editorView.state.apply(tx);
- FormattedTextBox._toolTipTextMenu && (FormattedTextBox._toolTipTextMenu.HackToFixTextSelectionGlitch = true);
this._editorView.updateState(state);
- FormattedTextBox._toolTipTextMenu && (FormattedTextBox._toolTipTextMenu.HackToFixTextSelectionGlitch = false);
if (state.selection.empty && FormattedTextBox._toolTipTextMenu && tx.storedMarks) {
FormattedTextBox._toolTipTextMenu.mark_key_pressed(tx.storedMarks);
}
@@ -327,7 +324,7 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
attributes: { class: "ProseMirror-example-setup-style" }
}
}),
- selectionSizePlugin
+ formattedTextBoxCommentPlugin
] : [
history(),
keymap(buildKeymap(schema)),
@@ -713,7 +710,7 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
}
onPointerUp = (e: React.PointerEvent): void => {
- SelectionSizeTooltip.textBox = this;
+ FormattedTextBoxComment.textBox = this;
if (e.buttons === 1 && this.props.isSelected() && !e.altKey) {
e.stopPropagation();
}
@@ -805,8 +802,7 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
}
if (m < 10) m = '0' + m;
- if (s < 10) s = '0' + s;
- return now.toLocaleDateString() + ' ' + h + ':' + m + ':' + s + ' ' + ampm;
+ return now.toLocaleDateString() + ' ' + h + ':' + m + ' ' + ampm;
}
var markerss = this._editorView!.state.storedMarks || (this._editorView!.state.selection.$to.parentOffset && this._editorView!.state.selection.$from.marks());
let newMarks = [...(markerss ? markerss.filter(m => m.type !== schema.marks.user_mark) : []), schema.marks.user_mark.create({ userid: Doc.CurrentUserEmail, modified: timenow() })];
diff --git a/src/client/views/nodes/FormattedTextBoxComment.tsx b/src/client/views/nodes/FormattedTextBoxComment.tsx
index c368a3f34..255000936 100644
--- a/src/client/views/nodes/FormattedTextBoxComment.tsx
+++ b/src/client/views/nodes/FormattedTextBoxComment.tsx
@@ -8,8 +8,8 @@ import { DocServer } from "../../DocServer";
import { Utils } from "../../../Utils";
import { StrCast } from "../../../new_fields/Types";
-export let selectionSizePlugin = new Plugin({
- view(editorView) { return new SelectionSizeTooltip(editorView); }
+export let formattedTextBoxCommentPlugin = new Plugin({
+ view(editorView) { return new FormattedTextBoxComment(editorView); }
});
export function findOtherUserMark(marks: Mark[]): Mark | undefined {
return marks.find(m => m.attrs.userid && m.attrs.userid !== Doc.CurrentUserEmail);
@@ -42,7 +42,7 @@ export function findEndOfMark(rpos: ResolvedPos, view: EditorView, finder: (mark
}
-export class SelectionSizeTooltip {
+export class FormattedTextBoxComment {
static tooltip: HTMLElement;
static tooltipText: HTMLElement;
static start: number;
@@ -51,39 +51,39 @@ export class SelectionSizeTooltip {
static opened: boolean;
static textBox: any;
constructor(view: any) {
- if (!SelectionSizeTooltip.tooltip) {
+ if (!FormattedTextBoxComment.tooltip) {
const root = document.getElementById("root");
let input = document.createElement("input");
input.type = "checkbox";
- SelectionSizeTooltip.tooltip = document.createElement("div");
- SelectionSizeTooltip.tooltipText = document.createElement("div");
- SelectionSizeTooltip.tooltip.appendChild(SelectionSizeTooltip.tooltipText);
- SelectionSizeTooltip.tooltip.className = "FormattedTextBox-tooltip";
- SelectionSizeTooltip.tooltip.style.pointerEvents = "all";
- SelectionSizeTooltip.tooltip.appendChild(input);
- SelectionSizeTooltip.tooltip.onpointerdown = (e: PointerEvent) => {
+ FormattedTextBoxComment.tooltip = document.createElement("div");
+ FormattedTextBoxComment.tooltipText = document.createElement("div");
+ FormattedTextBoxComment.tooltip.appendChild(FormattedTextBoxComment.tooltipText);
+ FormattedTextBoxComment.tooltip.className = "FormattedTextBox-tooltip";
+ FormattedTextBoxComment.tooltip.style.pointerEvents = "all";
+ FormattedTextBoxComment.tooltip.appendChild(input);
+ FormattedTextBoxComment.tooltip.onpointerdown = (e: PointerEvent) => {
let keep = e.target && (e.target as any).type === "checkbox";
- SelectionSizeTooltip.opened = keep || !SelectionSizeTooltip.opened;
- SelectionSizeTooltip.textBox && SelectionSizeTooltip.textBox.setAnnotation(
- SelectionSizeTooltip.start, SelectionSizeTooltip.end, SelectionSizeTooltip.mark,
- SelectionSizeTooltip.opened, keep);
+ FormattedTextBoxComment.opened = keep || !FormattedTextBoxComment.opened;
+ FormattedTextBoxComment.textBox && FormattedTextBoxComment.textBox.setAnnotation(
+ FormattedTextBoxComment.start, FormattedTextBoxComment.end, FormattedTextBoxComment.mark,
+ FormattedTextBoxComment.opened, keep);
};
- root && root.appendChild(SelectionSizeTooltip.tooltip);
+ root && root.appendChild(FormattedTextBoxComment.tooltip);
}
this.update(view, undefined);
}
public static Hide() {
- SelectionSizeTooltip.textBox = undefined;
- SelectionSizeTooltip.tooltip && (SelectionSizeTooltip.tooltip.style.display = "none");
+ FormattedTextBoxComment.textBox = undefined;
+ FormattedTextBoxComment.tooltip && (FormattedTextBoxComment.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.tooltip && (SelectionSizeTooltip.tooltip.style.display = "");
+ FormattedTextBoxComment.textBox = textBox;
+ FormattedTextBoxComment.start = start;
+ FormattedTextBoxComment.end = end;
+ FormattedTextBoxComment.mark = mark;
+ FormattedTextBoxComment.opened = opened;
+ FormattedTextBoxComment.tooltip && (FormattedTextBoxComment.tooltip.style.display = "");
}
update(view: EditorView, lastState?: EditorState) {
@@ -102,10 +102,10 @@ export class SelectionSizeTooltip {
let mark = child && findOtherUserMark(child.marks);
let noselection = view.state.selection.$from === view.state.selection.$to;
if (mark && child && (nbef || naft) && (!mark.attrs.opened || noselection)) {
- SelectionSizeTooltip.SetState(this, mark.attrs.opened, spos, epos, mark);
+ FormattedTextBoxComment.SetState(this, mark.attrs.opened, spos, epos, mark);
}
if (mark && child && nbef && naft) {
- SelectionSizeTooltip.tooltipText.textContent = mark.attrs.userid + " " + mark.attrs.modified;
+ FormattedTextBoxComment.tooltipText.textContent = mark.attrs.userid + " " + mark.attrs.modified;
// 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 - nbef), end = view.coordsAtPos(state.selection.from - nbef);
@@ -114,23 +114,23 @@ export class SelectionSizeTooltip {
// 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);
- SelectionSizeTooltip.tooltip.style.left = (left - box.left) + "px";
- SelectionSizeTooltip.tooltip.style.bottom = (box.bottom - start.top) + "px";
+ FormattedTextBoxComment.tooltip.style.left = (left - box.left) + "px";
+ FormattedTextBoxComment.tooltip.style.bottom = (box.bottom - start.top) + "px";
set = "";
}
}
if (set === "none" && state.selection.$from) {
- SelectionSizeTooltip.textBox = undefined;
+ FormattedTextBoxComment.textBox = undefined;
let nbef = findStartOfMark(state.selection.$from, view, findLinkMark);
let naft = findEndOfMark(state.selection.$from, view, findLinkMark);
let child = state.selection.$from.nodeBefore;
let mark = child && findLinkMark(child.marks);
if (mark && child && nbef && naft) {
- SelectionSizeTooltip.tooltipText.textContent = "link : " + (mark.attrs.title || mark.attrs.href);
+ FormattedTextBoxComment.tooltipText.textContent = "link : " + (mark.attrs.title || mark.attrs.href);
if (mark.attrs.href.indexOf(Utils.prepend("/doc/")) === 0) {
let docTarget = mark.attrs.href.replace(Utils.prepend("/doc/"), "").split("?")[0];
docTarget && DocServer.GetRefField(docTarget).then(linkDoc =>
- (linkDoc as Doc) && (SelectionSizeTooltip.tooltipText.textContent = "link :" + StrCast((linkDoc as Doc)!.title)));
+ (linkDoc as Doc) && (FormattedTextBoxComment.tooltipText.textContent = "link :" + StrCast((linkDoc as Doc)!.title)));
}
// These are in screen coordinates
// let start = view.coordsAtPos(state.selection.from), end = view.coordsAtPos(state.selection.to);
@@ -140,13 +140,13 @@ export class SelectionSizeTooltip {
// 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);
- SelectionSizeTooltip.tooltip.style.left = (left - box.left) + "px";
- SelectionSizeTooltip.tooltip.style.bottom = (box.bottom - start.top) + "px";
+ FormattedTextBoxComment.tooltip.style.left = (left - box.left) + "px";
+ FormattedTextBoxComment.tooltip.style.bottom = (box.bottom - start.top) + "px";
set = "";
}
}
- SelectionSizeTooltip.tooltip && (SelectionSizeTooltip.tooltip.style.display = set);
+ FormattedTextBoxComment.tooltip && (FormattedTextBoxComment.tooltip.style.display = set);
}
- destroy() { SelectionSizeTooltip.tooltip.style.display = "none"; }
+ destroy() { FormattedTextBoxComment.tooltip.style.display = "none"; }
}