Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

Commit 49d18cf

Browse files
author
bhasher
committed
random cursor uuid
1 parent 60306b9 commit 49d18cf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/static/js/editor/cursor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {getCurrentElement, triggerEvent, getCaretCharacterOffsetWithin, get_uuid_element} from '../utils.js';
22

33
const colors = ['blue', 'red', 'brown'];
4-
4+
const uuid = getRandomString(10);
55

66
export default class Cursor{
77

@@ -10,10 +10,9 @@ export default class Cursor{
1010
// Listen for others caret moves
1111
document.addEventListener('socket.receive.cursor-moves', e => {
1212
// select the good line and set the cursor
13-
console.log(e.detail.request.data);
1413
let element = this.editor.querySelector('div[uuid="' + e.detail.request.data.id + '"]');
1514
// Insert at the right place the cursor
16-
let old_elements = this.editor.querySelectorAll('div[user-id="null"]');
15+
let old_elements = this.editor.querySelectorAll('div[user-id="' + e.detail.request.data.userId + '"]');
1716
let current_color = null;
1817
old_elements.forEach(element => {
1918
current_color = element.style.background;
@@ -22,7 +21,7 @@ export default class Cursor{
2221
element.style.background = null;
2322
});
2423
element.className = 'cursor-line';
25-
element.setAttribute('user-id', 'null');
24+
element.setAttribute('user-id', e.detail.request.data.userId);
2625
if (current_color) {
2726
element.style.background = current_color;
2827
}
@@ -48,6 +47,7 @@ export default class Cursor{
4847
type: 'cursor-moves',
4948
data: {
5049
id: element.getAttribute('uuid'),
50+
userId: uuid,
5151
content: getCaretCharacterOffsetWithin(element)
5252
}
5353
};

0 commit comments

Comments
 (0)