Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed cursor movement issues over svg elements #2

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions togetherjs/ts/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import { elementFinder } from "./elementFinder";
import { elementFinder, CannotFind } from "./elementFinder";
import { eventMaker } from "./eventMaker";
import { peers } from "./peers";
import { session } from "./session";
Expand Down Expand Up @@ -97,17 +97,24 @@ class Cursor {

updatePosition(pos: TogetherJSNS.SessionSend.CursorClick | TogetherJSNS.On.CursorUpdate) {
let top, left;
if(this.atOtherUrl) {
if (this.atOtherUrl) {
this.element.show();
this.atOtherUrl = false;
}
if("element" in pos) {
const target = $(elementFinder.findElement(pos.element));
const offset = target.offset()!; // TODO !
top = offset.top + pos.offsetY;
left = offset.left + pos.offsetX;
}
else {
if ("element" in pos) {
try {
const target = $(elementFinder.findElement(pos.element));
const offset = target.offset()!; // TODO !
top = offset.top + pos.offsetY;
left = offset.left + pos.offsetX;
} catch (error: any) {
if (error instanceof CannotFind) {
top = pos.top;
left = pos.left;
} else
throw error;
}
} else {
// No anchor, just an absolute position
top = pos.top;
left = pos.left;
Expand Down Expand Up @@ -296,6 +303,8 @@ function mousemove(event: JQueryMouseEventObject) {
const offsetY = pageY - offset.top;
lastMessage = {
type: "cursor-update",
top: pageY,
left: pageX,
element: elementFinder.elementLocation($target),
offsetX: Math.floor(offsetX),
offsetY: Math.floor(offsetY)
Expand Down
12 changes: 6 additions & 6 deletions togetherjs/ts/elementFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function isJQuery(o: unknown): o is JQuery {
return o instanceof $;
}

class CannotFind {
export class CannotFind {
public prefix = "";

constructor(
Expand Down Expand Up @@ -86,8 +86,8 @@ export class ElementFinder {
if(child == el) {
break;
}
if(child.nodeType == document.ELEMENT_NODE) {
if(child.className.indexOf("togetherjs") != -1) {
if (child.nodeType == document.ELEMENT_NODE) {
if (child.className.indexOf && child.className.indexOf("togetherjs") != -1) {
// Don't count our UI
continue;
}
Expand Down Expand Up @@ -180,12 +180,12 @@ export class ElementFinder {
el = null;
for(let i = 0; i < children.length; i++) {
const child = children[i] as HTMLElement;
if(child.nodeType == document.ELEMENT_NODE) {
if(child.className.indexOf("togetherjs") != -1) {
if (child.nodeType == document.ELEMENT_NODE) {
if (child.className.indexOf && child.className.indexOf("togetherjs") != -1) {
continue;
}
count--;
if(count === 0) {
if (count === 0) {
// this is the element
el = child;
break;
Expand Down