Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.
Merged
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
9 changes: 5 additions & 4 deletions src/db/MongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MongoDB {

async newLine (documentLink, previousUuid, uuid, content) {
// Insert a line at the right place
//TODO is it possible in one operation ?
//TODO is it possible in one operation ?
// TODO is it possible to implement with bulk?
try {
let doc = await this.documentsCollection.findOne({documentLink: documentLink});
Expand Down Expand Up @@ -206,17 +206,18 @@ class MongoDB {
for (let request of requests) {
let requestType = request.type;
let data = request.data;
let results = ""
switch (requestType) {
case 'set-line':
let results = await this.setLine(documentLink, data.id, data.content);
results = await this.setLine(documentLink, data.id, data.content);
if (!results) success = false;
break;
case 'new-line':
let results = await this.newLine(documentLink, data.previous, data.id, data.content);
results = await this.newLine(documentLink, data.previous, data.id, data.content);
if (!results) success = false;
break;
case 'delete-line':
let results = await this.deleteLine(documentLink, data.id);
results = await this.deleteLine(documentLink, data.id);
if (!results) success = false;
break;
}
Expand Down
15 changes: 11 additions & 4 deletions src/publics/js/dev/page/editor/editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,18 @@ export default class Editable{

const line = getNodeFromAttribute('uuid');

if(!line) return;
if(!line){
e.preventDefault();
temporaryCardAlert('Editor', 'Sorry, your action has been canceled because you are not on any line.', 5000);
return;
}

if(!anchorParent.hasAttribute('uuid')
|| !focusParent.hasAttribute('uuid')
|| ((Caret.getBeginPosition(line) === 0
|| Caret.getEndPosition(line) === 0)
) && anchorParent !== focusParent){
e.preventDefault();
temporaryCardAlert('Override', 'Sorry, you can\'t override the first char of a line', 5000);
return;
Caret.setRangeStart(line, 1);
}

switch (e.keyCode) {
Expand All @@ -155,6 +157,11 @@ export default class Editable{
this.insertTab();
break;
case 13: // enter
if(e.shiftKey){
temporaryCardAlert('Shift+Enter', 'Please just use Enter to avoid any bugs.', 5000);
e.preventDefault();
return;
}
if(this.keepSpace){
Debug.debug('Prevent action when trying to add new line (key is probably maintain).');
e.preventDefault();
Expand Down
16 changes: 16 additions & 0 deletions src/publics/js/dev/utils/caret.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ export default class Caret{
}
}


/**
* Set the start range of the user caret on specified position in element or children
* @param {HTMLElement|Node} element
* @param {number} position
*/
static setRangeStart(element, position) {
if (position >= 0) {
let selection = document.getSelection();

let range = Caret.createRange(element, {count: position});
selection.getRangeAt(0).setStart(range.endContainer, range.endOffset);

}
}

/**
* Get the position of the end of the user selection
* Based on https://stackoverflow.com/a/4812022/11247647
Expand Down
6 changes: 3 additions & 3 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Alexandre Dewilde
* @date 15/11/2020
* @version 1.0.0
*
*
*/
const fs = require('fs');
const path = require('path');
Expand All @@ -15,7 +15,7 @@ const port = configs.PORT;
const DEBUG = configs.DEBUG;
const ssl = configs.SSL;
const sslKeyPath = configs.KEY_FILE_SSL;
const sslCertPath = configs.CERT_FILE_SSL;
const sslCertPath = configs.CERT_FILE_SSL;

const options = ssl ? {
key: fs.readFileSync(sslKeyPath.startsWith('/') ? sslKeyPath : path.join(__dirname, sslKeyPath), 'utf8'),
Expand All @@ -29,7 +29,7 @@ const http = ssl ? require('https') : require('http');
const server = http.createServer(options, app);
if (configs.METRICS) {
const {metricsApp} = require('./metricsApp');
var metricsServer = http.createServer(metricsApp);
var metricsServer = require('http').createServer(metricsApp);
}

// config websockets
Expand Down
5 changes: 3 additions & 2 deletions src/socket/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ module.exports = function (wss) {
broadcastRoomExceptSender(data, 'uuid', data.uuid);
const succesUpdatingDate = db.updateLastViewedDate(data.room);
const succesUpdate = db.applyRequests(data.room, data.data);
if (!succesUpdatingDate || !succesUpdate) socket.send(JSON.stringify({event: 'update', success: false}));
// /!\ Bad event
// if (!succesUpdatingDate || !succesUpdate) socket.send(JSON.stringify({event: 'update', success: false}));
} catch (err) {
if (config.DEBUG) {
console.error(err);
Expand All @@ -82,7 +83,7 @@ module.exports = function (wss) {
rooms[data.room][uuid] = socket;
}
break;

case 'language':
try {
broadcastRoomExceptSender(data, 'language', data.language);
Expand Down