1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-28 15:22:05 +03:00

Auto-fix lint errors

This commit is contained in:
J. Ryan Stinnett
2021-06-29 13:11:58 +01:00
parent 4c5720a573
commit ae0a8b8da4
625 changed files with 3170 additions and 3232 deletions

View File

@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {getLineAndNodePosition} from "../../src/editor/caret";
import { getLineAndNodePosition } from "../../src/editor/caret";
import EditorModel from "../../src/editor/model";
import {createPartCreator} from "./mock";
import { createPartCreator } from "./mock";
describe('editor/caret: DOM position for caret', function() {
describe('basic text handling', function() {
@ -25,8 +25,8 @@ describe('editor/caret: DOM position for caret', function() {
const model = new EditorModel([
pc.plain("hello"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 0, offset: 5});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 0, offset: 5 });
expect(lineIndex).toBe(0);
expect(nodeIndex).toBe(0);
expect(offset).toBe(5);
@ -36,8 +36,8 @@ describe('editor/caret: DOM position for caret', function() {
const model = new EditorModel([
pc.plain("hello"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 0, offset: 0});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 0, offset: 0 });
expect(lineIndex).toBe(0);
expect(nodeIndex).toBe(0);
expect(offset).toBe(0);
@ -47,8 +47,8 @@ describe('editor/caret: DOM position for caret', function() {
const model = new EditorModel([
pc.plain("hello"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 0, offset: 2});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 0, offset: 2 });
expect(lineIndex).toBe(0);
expect(nodeIndex).toBe(0);
expect(offset).toBe(2);
@ -62,8 +62,8 @@ describe('editor/caret: DOM position for caret', function() {
pc.newline(),
pc.plain("world"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 2, offset: 5});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 2, offset: 5 });
expect(lineIndex).toBe(1);
expect(nodeIndex).toBe(0);
expect(offset).toBe(5);
@ -75,8 +75,8 @@ describe('editor/caret: DOM position for caret', function() {
pc.newline(),
pc.plain("world"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 2, offset: 0});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 2, offset: 0 });
expect(lineIndex).toBe(1);
expect(nodeIndex).toBe(0);
expect(offset).toBe(0);
@ -89,8 +89,8 @@ describe('editor/caret: DOM position for caret', function() {
pc.newline(),
pc.plain("world"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 1, offset: 1});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 1, offset: 1 });
expect(lineIndex).toBe(1);
expect(nodeIndex).toBe(-1);
expect(offset).toBe(0);
@ -103,8 +103,8 @@ describe('editor/caret: DOM position for caret', function() {
pc.newline(),
pc.plain("world"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 3, offset: 0});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 3, offset: 0 });
expect(lineIndex).toBe(2);
expect(nodeIndex).toBe(0);
expect(offset).toBe(0);
@ -118,8 +118,8 @@ describe('editor/caret: DOM position for caret', function() {
pc.userPill("Alice", "@alice:hs.tld"),
pc.plain("!"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 1, offset: 0});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 1, offset: 0 });
expect(lineIndex).toBe(0);
expect(nodeIndex).toBe(0);
expect(offset).toBe(5);
@ -131,8 +131,8 @@ describe('editor/caret: DOM position for caret', function() {
pc.userPill("Alice", "@alice:hs.tld"),
pc.plain("!"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 1, offset: 2});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 1, offset: 2 });
expect(lineIndex).toBe(0);
expect(nodeIndex).toBe(2);
expect(offset).toBe(0);
@ -142,8 +142,8 @@ describe('editor/caret: DOM position for caret', function() {
const model = new EditorModel([
pc.userPill("Alice", "@alice:hs.tld"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 0, offset: 0});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 0, offset: 0 });
expect(lineIndex).toBe(0);
//presumed nodes on line are (caret, pill, caret)
expect(nodeIndex).toBe(0);
@ -154,8 +154,8 @@ describe('editor/caret: DOM position for caret', function() {
const model = new EditorModel([
pc.userPill("Alice", "@alice:hs.tld"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 0, offset: 1});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 0, offset: 1 });
expect(lineIndex).toBe(0);
//presumed nodes on line are (caret, pill, caret)
expect(nodeIndex).toBe(2);
@ -167,8 +167,8 @@ describe('editor/caret: DOM position for caret', function() {
pc.userPill("Alice", "@alice:hs.tld"),
pc.userPill("Bob", "@bob:hs.tld"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 0, offset: 1});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 0, offset: 1 });
expect(lineIndex).toBe(0);
//presumed nodes on line are (caret, pill, caret, pill, caret)
expect(nodeIndex).toBe(2);
@ -180,8 +180,8 @@ describe('editor/caret: DOM position for caret', function() {
pc.userPill("Alice", "@alice:hs.tld"),
pc.userPill("Bob", "@bob:hs.tld"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 1, offset: 0});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 1, offset: 0 });
expect(lineIndex).toBe(0);
//presumed nodes on line are (caret, pill, caret, pill, caret)
expect(nodeIndex).toBe(2);
@ -193,8 +193,8 @@ describe('editor/caret: DOM position for caret', function() {
pc.userPill("Alice", "@alice:hs.tld"),
pc.userPill("Bob", "@bob:hs.tld"),
]);
const {offset, lineIndex, nodeIndex} =
getLineAndNodePosition(model, {index: 1, offset: 1});
const { offset, lineIndex, nodeIndex } =
getLineAndNodePosition(model, { index: 1, offset: 1 });
expect(lineIndex).toBe(0);
//presumed nodes on line are (caret, pill, caret, pill, caret)
expect(nodeIndex).toBe(4);

View File

@ -15,8 +15,8 @@ limitations under the License.
*/
import '../skinned-sdk'; // Must be first for skinning to work
import {parseEvent} from "../../src/editor/deserialize";
import {createPartCreator} from "./mock";
import { parseEvent } from "../../src/editor/deserialize";
import { createPartCreator } from "./mock";
function htmlMessage(formattedBody, msgtype = "m.text") {
return {
@ -71,22 +71,22 @@ describe('editor/deserialize', function() {
describe('text messages', function() {
it('test with newlines', function() {
const parts = normalize(parseEvent(textMessage("hello\nworld"), createPartCreator()));
expect(parts[0]).toStrictEqual({type: "plain", text: "hello"});
expect(parts[1]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[2]).toStrictEqual({type: "plain", text: "world"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "hello" });
expect(parts[1]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "world" });
expect(parts.length).toBe(3);
});
it('@room pill', function() {
const parts = normalize(parseEvent(textMessage("text message for @room"), createPartCreator()));
expect(parts.length).toBe(2);
expect(parts[0]).toStrictEqual({type: "plain", text: "text message for "});
expect(parts[1]).toStrictEqual({type: "at-room-pill", text: "@room"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "text message for " });
expect(parts[1]).toStrictEqual({ type: "at-room-pill", text: "@room" });
});
it('emote', function() {
const text = "says DON'T SHOUT!";
const parts = normalize(parseEvent(textMessage(text, "m.emote"), createPartCreator()));
expect(parts.length).toBe(1);
expect(parts[0]).toStrictEqual({type: "plain", text: "/me says DON'T SHOUT!"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "/me says DON'T SHOUT!" });
});
});
describe('html messages', function() {
@ -94,159 +94,159 @@ describe('editor/deserialize', function() {
const html = "<strong>bold</strong> and <em>emphasized</em> text";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(1);
expect(parts[0]).toStrictEqual({type: "plain", text: "**bold** and _emphasized_ text"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "**bold** and _emphasized_ text" });
});
it('hyperlink', function() {
const html = 'click <a href="http://example.com/">this</a>!';
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(1);
expect(parts[0]).toStrictEqual({type: "plain", text: "click [this](http://example.com/)!"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "click [this](http://example.com/)!" });
});
it('multiple lines with paragraphs', function() {
const html = '<p>hello</p><p>world</p>';
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(4);
expect(parts[0]).toStrictEqual({type: "plain", text: "hello"});
expect(parts[1]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[2]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[3]).toStrictEqual({type: "plain", text: "world"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "hello" });
expect(parts[1]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[2]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[3]).toStrictEqual({ type: "plain", text: "world" });
});
it('multiple lines with line breaks', function() {
const html = 'hello<br>world';
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(3);
expect(parts[0]).toStrictEqual({type: "plain", text: "hello"});
expect(parts[1]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[2]).toStrictEqual({type: "plain", text: "world"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "hello" });
expect(parts[1]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "world" });
});
it('multiple lines mixing paragraphs and line breaks', function() {
const html = '<p>hello<br>warm</p><p>world</p>';
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(6);
expect(parts[0]).toStrictEqual({type: "plain", text: "hello"});
expect(parts[1]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[2]).toStrictEqual({type: "plain", text: "warm"});
expect(parts[3]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[4]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[5]).toStrictEqual({type: "plain", text: "world"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "hello" });
expect(parts[1]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "warm" });
expect(parts[3]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[4]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[5]).toStrictEqual({ type: "plain", text: "world" });
});
it('quote', function() {
const html = '<blockquote><p><em>wise</em><br><strong>words</strong></p></blockquote><p>indeed</p>';
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(6);
expect(parts[0]).toStrictEqual({type: "plain", text: "> _wise_"});
expect(parts[1]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[2]).toStrictEqual({type: "plain", text: "> **words**"});
expect(parts[3]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[4]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[5]).toStrictEqual({type: "plain", text: "indeed"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "> _wise_" });
expect(parts[1]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "> **words**" });
expect(parts[3]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[4]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[5]).toStrictEqual({ type: "plain", text: "indeed" });
});
it('user pill', function() {
const html = "Hi <a href=\"https://matrix.to/#/@alice:hs.tld\">Alice</a>!";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(3);
expect(parts[0]).toStrictEqual({type: "plain", text: "Hi "});
expect(parts[1]).toStrictEqual({type: "user-pill", text: "Alice", resourceId: "@alice:hs.tld"});
expect(parts[2]).toStrictEqual({type: "plain", text: "!"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "Hi " });
expect(parts[1]).toStrictEqual({ type: "user-pill", text: "Alice", resourceId: "@alice:hs.tld" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "!" });
});
it('user pill with displayname containing backslash', function() {
const html = "Hi <a href=\"https://matrix.to/#/@alice:hs.tld\">Alice\\</a>!";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(3);
expect(parts[0]).toStrictEqual({type: "plain", text: "Hi "});
expect(parts[1]).toStrictEqual({type: "user-pill", text: "Alice\\", resourceId: "@alice:hs.tld"});
expect(parts[2]).toStrictEqual({type: "plain", text: "!"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "Hi " });
expect(parts[1]).toStrictEqual({ type: "user-pill", text: "Alice\\", resourceId: "@alice:hs.tld" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "!" });
});
it('user pill with displayname containing opening square bracket', function() {
const html = "Hi <a href=\"https://matrix.to/#/@alice:hs.tld\">Alice[[</a>!";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(3);
expect(parts[0]).toStrictEqual({type: "plain", text: "Hi "});
expect(parts[1]).toStrictEqual({type: "user-pill", text: "Alice[[", resourceId: "@alice:hs.tld"});
expect(parts[2]).toStrictEqual({type: "plain", text: "!"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "Hi " });
expect(parts[1]).toStrictEqual({ type: "user-pill", text: "Alice[[", resourceId: "@alice:hs.tld" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "!" });
});
it('user pill with displayname containing closing square bracket', function() {
const html = "Hi <a href=\"https://matrix.to/#/@alice:hs.tld\">Alice]</a>!";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(3);
expect(parts[0]).toStrictEqual({type: "plain", text: "Hi "});
expect(parts[1]).toStrictEqual({type: "user-pill", text: "Alice]", resourceId: "@alice:hs.tld"});
expect(parts[2]).toStrictEqual({type: "plain", text: "!"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "Hi " });
expect(parts[1]).toStrictEqual({ type: "user-pill", text: "Alice]", resourceId: "@alice:hs.tld" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "!" });
});
it('room pill', function() {
const html = "Try <a href=\"https://matrix.to/#/#room:hs.tld\">#room:hs.tld</a>?";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(3);
expect(parts[0]).toStrictEqual({type: "plain", text: "Try "});
expect(parts[1]).toStrictEqual({type: "room-pill", text: "#room:hs.tld", resourceId: "#room:hs.tld"});
expect(parts[2]).toStrictEqual({type: "plain", text: "?"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "Try " });
expect(parts[1]).toStrictEqual({ type: "room-pill", text: "#room:hs.tld", resourceId: "#room:hs.tld" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "?" });
});
it('@room pill', function() {
const html = "<em>formatted</em> message for @room";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(2);
expect(parts[0]).toStrictEqual({type: "plain", text: "_formatted_ message for "});
expect(parts[1]).toStrictEqual({type: "at-room-pill", text: "@room"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "_formatted_ message for " });
expect(parts[1]).toStrictEqual({ type: "at-room-pill", text: "@room" });
});
it('inline code', function() {
const html = "there is no place like <code>127.0.0.1</code>!";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(1);
expect(parts[0]).toStrictEqual({type: "plain", text: "there is no place like `127.0.0.1`!"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "there is no place like `127.0.0.1`!" });
});
it('code block with no trailing text', function() {
const html = "<pre><code>0xDEADBEEF\n</code></pre>\n";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
console.log(parts);
expect(parts.length).toBe(5);
expect(parts[0]).toStrictEqual({type: "plain", text: "```"});
expect(parts[1]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[2]).toStrictEqual({type: "plain", text: "0xDEADBEEF"});
expect(parts[3]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[4]).toStrictEqual({type: "plain", text: "```"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "```" });
expect(parts[1]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "0xDEADBEEF" });
expect(parts[3]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[4]).toStrictEqual({ type: "plain", text: "```" });
});
// failing likely because of https://github.com/vector-im/element-web/issues/10316
xit('code block with no trailing text and no newlines', function() {
const html = "<pre><code>0xDEADBEEF</code></pre>";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(5);
expect(parts[0]).toStrictEqual({type: "plain", text: "```"});
expect(parts[1]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[2]).toStrictEqual({type: "plain", text: "0xDEADBEEF"});
expect(parts[3]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[4]).toStrictEqual({type: "plain", text: "```"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "```" });
expect(parts[1]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "0xDEADBEEF" });
expect(parts[3]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[4]).toStrictEqual({ type: "plain", text: "```" });
});
it('unordered lists', function() {
const html = "<ul><li>Oak</li><li>Spruce</li><li>Birch</li></ul>";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(5);
expect(parts[0]).toStrictEqual({type: "plain", text: "- Oak"});
expect(parts[1]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[2]).toStrictEqual({type: "plain", text: "- Spruce"});
expect(parts[3]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[4]).toStrictEqual({type: "plain", text: "- Birch"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "- Oak" });
expect(parts[1]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "- Spruce" });
expect(parts[3]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[4]).toStrictEqual({ type: "plain", text: "- Birch" });
});
it('ordered lists', function() {
const html = "<ol><li>Start</li><li>Continue</li><li>Finish</li></ol>";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(5);
expect(parts[0]).toStrictEqual({type: "plain", text: "1. Start"});
expect(parts[1]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[2]).toStrictEqual({type: "plain", text: "2. Continue"});
expect(parts[3]).toStrictEqual({type: "newline", text: "\n"});
expect(parts[4]).toStrictEqual({type: "plain", text: "3. Finish"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "1. Start" });
expect(parts[1]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[2]).toStrictEqual({ type: "plain", text: "2. Continue" });
expect(parts[3]).toStrictEqual({ type: "newline", text: "\n" });
expect(parts[4]).toStrictEqual({ type: "plain", text: "3. Finish" });
});
it('mx-reply is stripped', function() {
const html = "<mx-reply>foo</mx-reply>bar";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
expect(parts.length).toBe(1);
expect(parts[0]).toStrictEqual({type: "plain", text: "bar"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "bar" });
});
it('emote', function() {
const html = "says <em>DON'T SHOUT</em>!";
const parts = normalize(parseEvent(htmlMessage(html, "m.emote"), createPartCreator()));
expect(parts.length).toBe(1);
expect(parts[0]).toStrictEqual({type: "plain", text: "/me says _DON'T SHOUT_!"});
expect(parts[0]).toStrictEqual({ type: "plain", text: "/me says _DON'T SHOUT_!" });
});
});
});

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {diffDeletion, diffAtCaret} from "../../src/editor/diff";
import { diffDeletion, diffAtCaret } from "../../src/editor/diff";
describe('editor/diff', function() {
describe('diffDeletion', function() {

View File

@ -14,13 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import HistoryManager, {MAX_STEP_LENGTH} from "../../src/editor/history";
import HistoryManager, { MAX_STEP_LENGTH } from "../../src/editor/history";
describe('editor/history', function() {
it('push, then undo', function() {
const history = new HistoryManager();
const parts = ["hello"];
const model = {serializeParts: () => parts.slice()};
const model = { serializeParts: () => parts.slice() };
const caret1 = {};
const result1 = history.tryPush(model, caret1);
expect(result1).toEqual(true);
@ -35,7 +35,7 @@ describe('editor/history', function() {
it('push, undo, then redo', function() {
const history = new HistoryManager();
const parts = ["hello"];
const model = {serializeParts: () => parts.slice()};
const model = { serializeParts: () => parts.slice() };
history.tryPush(model, {});
parts[0] = "hello world";
const caret2 = {};
@ -51,7 +51,7 @@ describe('editor/history', function() {
it('push, undo, push, ensure you can`t redo', function() {
const history = new HistoryManager();
const parts = ["hello"];
const model = {serializeParts: () => parts.slice()};
const model = { serializeParts: () => parts.slice() };
history.tryPush(model, {});
parts[0] = "hello world";
history.tryPush(model, {});
@ -63,10 +63,10 @@ describe('editor/history', function() {
it('not every keystroke stores a history step', function() {
const history = new HistoryManager();
const parts = ["hello"];
const model = {serializeParts: () => parts.slice()};
const model = { serializeParts: () => parts.slice() };
const firstCaret = {};
history.tryPush(model, firstCaret);
const diff = {added: "o"};
const diff = { added: "o" };
let keystrokeCount = 0;
do {
parts[0] = parts[0] + diff.added;
@ -80,24 +80,24 @@ describe('editor/history', function() {
});
it('history step is added at word boundary', function() {
const history = new HistoryManager();
const model = {serializeParts: () => parts.slice()};
const model = { serializeParts: () => parts.slice() };
const parts = ["h"];
let diff = {added: "h"};
let diff = { added: "h" };
expect(history.tryPush(model, {}, "insertText", diff)).toEqual(false);
diff = {added: "i"};
diff = { added: "i" };
parts[0] = "hi";
expect(history.tryPush(model, {}, "insertText", diff)).toEqual(false);
diff = {added: " "};
diff = { added: " " };
parts[0] = "hi ";
const spaceCaret = {};
expect(history.tryPush(model, spaceCaret, "insertText", diff)).toEqual(true);
diff = {added: "y"};
diff = { added: "y" };
parts[0] = "hi y";
expect(history.tryPush(model, {}, "insertText", diff)).toEqual(false);
diff = {added: "o"};
diff = { added: "o" };
parts[0] = "hi yo";
expect(history.tryPush(model, {}, "insertText", diff)).toEqual(false);
diff = {added: "u"};
diff = { added: "u" };
parts[0] = "hi you";
expect(history.canUndo()).toEqual(true);
@ -108,11 +108,11 @@ describe('editor/history', function() {
it('keystroke that didn\'t add a step can undo', function() {
const history = new HistoryManager();
const parts = ["hello"];
const model = {serializeParts: () => parts.slice()};
const model = { serializeParts: () => parts.slice() };
const firstCaret = {};
history.tryPush(model, {});
parts[0] = "helloo";
const result = history.tryPush(model, {}, "insertText", {added: "o"});
const result = history.tryPush(model, {}, "insertText", { added: "o" });
expect(result).toEqual(false);
expect(history.canUndo()).toEqual(true);
const undoState = history.undo(model);
@ -122,11 +122,11 @@ describe('editor/history', function() {
it('undo after keystroke that didn\'t add a step is able to redo', function() {
const history = new HistoryManager();
const parts = ["hello"];
const model = {serializeParts: () => parts.slice()};
const model = { serializeParts: () => parts.slice() };
history.tryPush(model, {});
parts[0] = "helloo";
const caret = {last: true};
history.tryPush(model, caret, "insertText", {added: "o"});
const caret = { last: true };
history.tryPush(model, caret, "insertText", { added: "o" });
history.undo(model);
expect(history.canRedo()).toEqual(true);
const redoState = history.redo();
@ -136,10 +136,10 @@ describe('editor/history', function() {
it('overwriting text always stores a step', function() {
const history = new HistoryManager();
const parts = ["hello"];
const model = {serializeParts: () => parts.slice()};
const model = { serializeParts: () => parts.slice() };
const firstCaret = {};
history.tryPush(model, firstCaret);
const diff = {at: 1, added: "a", removed: "e"};
const diff = { at: 1, added: "a", removed: "e" };
const result = history.tryPush(model, {}, "insertText", diff);
expect(result).toEqual(true);
});

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {PartCreator} from "../../src/editor/parts";
import { PartCreator } from "../../src/editor/parts";
class MockAutoComplete {
constructor(updateCallback, partCreator, completions) {
@ -25,7 +25,7 @@ class MockAutoComplete {
}
close() {
this._updateCallback({close: true});
this._updateCallback({ close: true });
}
tryComplete(close = true) {
@ -40,7 +40,7 @@ class MockAutoComplete {
} else {
pill = this._partCreator.roomPill(match.resourceId);
}
this._updateCallback({replaceParts: [pill], close});
this._updateCallback({ replaceParts: [pill], close });
}
}

View File

@ -15,14 +15,14 @@ limitations under the License.
*/
import EditorModel from "../../src/editor/model";
import {createPartCreator, createRenderer} from "./mock";
import { createPartCreator, createRenderer } from "./mock";
describe('editor/model', function() {
describe('plain text manipulation', function() {
it('insert text into empty document', function() {
const renderer = createRenderer();
const model = new EditorModel([], createPartCreator(), renderer);
model.update("hello", "insertText", {offset: 5, atNodeEnd: true});
model.update("hello", "insertText", { offset: 5, atNodeEnd: true });
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(0);
expect(renderer.caret.offset).toBe(5);
@ -34,7 +34,7 @@ describe('editor/model', function() {
const renderer = createRenderer();
const pc = createPartCreator();
const model = new EditorModel([pc.plain("hello")], pc, renderer);
model.update("hello world", "insertText", {offset: 11, atNodeEnd: true});
model.update("hello world", "insertText", { offset: 11, atNodeEnd: true });
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(0);
expect(renderer.caret.offset).toBe(11);
@ -46,7 +46,7 @@ describe('editor/model', function() {
const renderer = createRenderer();
const pc = createPartCreator();
const model = new EditorModel([pc.plain("world")], pc, renderer);
model.update("hello world", "insertText", {offset: 6, atNodeEnd: false});
model.update("hello world", "insertText", { offset: 6, atNodeEnd: false });
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(0);
expect(renderer.caret.offset).toBe(6);
@ -60,7 +60,7 @@ describe('editor/model', function() {
const renderer = createRenderer();
const pc = createPartCreator();
const model = new EditorModel([pc.plain("hello")], pc, renderer);
model.update("hello\n", "insertText", {offset: 6, atNodeEnd: true});
model.update("hello\n", "insertText", { offset: 6, atNodeEnd: true });
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(1);
expect(renderer.caret.offset).toBe(1);
@ -74,7 +74,7 @@ describe('editor/model', function() {
const renderer = createRenderer();
const pc = createPartCreator();
const model = new EditorModel([pc.plain("hello")], pc, renderer);
model.update("hello\n\n\nworld!", "insertText", {offset: 14, atNodeEnd: true});
model.update("hello\n\n\nworld!", "insertText", { offset: 14, atNodeEnd: true });
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(4);
expect(renderer.caret.offset).toBe(6);
@ -99,7 +99,7 @@ describe('editor/model', function() {
pc.newline(),
pc.plain("world"),
], pc, renderer);
model.update("hello\nwarm\nworld", "insertText", {offset: 10, atNodeEnd: true});
model.update("hello\nwarm\nworld", "insertText", { offset: 10, atNodeEnd: true });
console.log(model.serializeParts());
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(2);
@ -125,7 +125,7 @@ describe('editor/model', function() {
pc.plain("try "),
pc.roomPill("#someroom"),
], pc, renderer);
model.update("try foo#someroom", "insertText", {offset: 7, atNodeEnd: false});
model.update("try foo#someroom", "insertText", { offset: 7, atNodeEnd: false });
expect(renderer.caret.index).toBe(0);
expect(renderer.caret.offset).toBe(7);
expect(model.parts.length).toBe(2);
@ -142,7 +142,7 @@ describe('editor/model', function() {
pc.roomPill("#someroom"),
pc.plain("?"),
], pc, renderer);
model.update("try #some perhapsroom?", "insertText", {offset: 17, atNodeEnd: false});
model.update("try #some perhapsroom?", "insertText", { offset: 17, atNodeEnd: false });
expect(renderer.caret.index).toBe(2);
expect(renderer.caret.offset).toBe(8);
expect(model.parts.length).toBe(3);
@ -157,7 +157,7 @@ describe('editor/model', function() {
const renderer = createRenderer();
const pc = createPartCreator();
const model = new EditorModel([pc.roomPill("#someroom")], pc, renderer);
model.update("#someroo", "deleteContentBackward", {offset: 8, atNodeEnd: true});
model.update("#someroo", "deleteContentBackward", { offset: 8, atNodeEnd: true });
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(-1);
expect(renderer.caret.offset).toBe(0);
@ -167,7 +167,7 @@ describe('editor/model', function() {
const renderer = createRenderer();
const pc = createPartCreator();
const model = new EditorModel([pc.roomPill("#someroom")], pc, renderer);
model.update("someroom", "deleteContentForward", {offset: 0, atNodeEnd: false});
model.update("someroom", "deleteContentForward", { offset: 0, atNodeEnd: false });
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(-1);
expect(renderer.caret.offset).toBe(0);
@ -177,10 +177,10 @@ describe('editor/model', function() {
describe('auto-complete', function() {
it('insert user pill', function() {
const renderer = createRenderer();
const pc = createPartCreator([{resourceId: "@alice", label: "Alice"}]);
const pc = createPartCreator([{ resourceId: "@alice", label: "Alice" }]);
const model = new EditorModel([pc.plain("hello ")], pc, renderer);
model.update("hello @a", "insertText", {offset: 8, atNodeEnd: true});
model.update("hello @a", "insertText", { offset: 8, atNodeEnd: true });
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(1);
@ -205,10 +205,10 @@ describe('editor/model', function() {
it('insert room pill', function() {
const renderer = createRenderer();
const pc = createPartCreator([{resourceId: "#riot-dev"}]);
const pc = createPartCreator([{ resourceId: "#riot-dev" }]);
const model = new EditorModel([pc.plain("hello ")], pc, renderer);
model.update("hello #r", "insertText", {offset: 8, atNodeEnd: true});
model.update("hello #r", "insertText", { offset: 8, atNodeEnd: true });
expect(renderer.count).toBe(1);
expect(renderer.caret.index).toBe(1);
@ -233,12 +233,12 @@ describe('editor/model', function() {
it('type after inserting pill', function() {
const renderer = createRenderer();
const pc = createPartCreator([{resourceId: "#riot-dev"}]);
const pc = createPartCreator([{ resourceId: "#riot-dev" }]);
const model = new EditorModel([pc.plain("hello ")], pc, renderer);
model.update("hello #r", "insertText", {offset: 8, atNodeEnd: true});
model.update("hello #r", "insertText", { offset: 8, atNodeEnd: true });
model.autoComplete.tryComplete(); // see MockAutoComplete
model.update("hello #riot-dev!!", "insertText", {offset: 17, atNodeEnd: true});
model.update("hello #riot-dev!!", "insertText", { offset: 17, atNodeEnd: true });
expect(renderer.count).toBe(3);
expect(renderer.caret.index).toBe(2);
@ -254,10 +254,10 @@ describe('editor/model', function() {
it('pasting text does not trigger auto-complete', function() {
const renderer = createRenderer();
const pc = createPartCreator([{resourceId: "#define-room"}]);
const pc = createPartCreator([{ resourceId: "#define-room" }]);
const model = new EditorModel([pc.plain("try ")], pc, renderer);
model.update("try #define", "insertFromPaste", {offset: 11, atNodeEnd: true});
model.update("try #define", "insertFromPaste", { offset: 11, atNodeEnd: true });
expect(model.autoComplete).toBeFalsy();
expect(renderer.caret.index).toBe(0);
@ -269,10 +269,10 @@ describe('editor/model', function() {
it('dropping text does not trigger auto-complete', function() {
const renderer = createRenderer();
const pc = createPartCreator([{resourceId: "#define-room"}]);
const pc = createPartCreator([{ resourceId: "#define-room" }]);
const model = new EditorModel([pc.plain("try ")], pc, renderer);
model.update("try #define", "insertFromDrop", {offset: 11, atNodeEnd: true});
model.update("try #define", "insertFromDrop", { offset: 11, atNodeEnd: true });
expect(model.autoComplete).toBeFalsy();
expect(renderer.caret.index).toBe(0);
@ -284,17 +284,17 @@ describe('editor/model', function() {
it('insert room pill without splitting at the colon', () => {
const renderer = createRenderer();
const pc = createPartCreator([{resourceId: "#room:server"}]);
const pc = createPartCreator([{ resourceId: "#room:server" }]);
const model = new EditorModel([], pc, renderer);
model.update("#roo", "insertText", {offset: 4, atNodeEnd: true});
model.update("#roo", "insertText", { offset: 4, atNodeEnd: true });
expect(renderer.count).toBe(1);
expect(model.parts.length).toBe(1);
expect(model.parts[0].type).toBe("pill-candidate");
expect(model.parts[0].text).toBe("#roo");
model.update("#room:s", "insertText", {offset: 7, atNodeEnd: true});
model.update("#room:s", "insertText", { offset: 7, atNodeEnd: true });
expect(renderer.count).toBe(2);
expect(model.parts.length).toBe(1);
@ -304,10 +304,10 @@ describe('editor/model', function() {
it('allow typing e-mail addresses without splitting at the @', () => {
const renderer = createRenderer();
const pc = createPartCreator([{resourceId: "@alice", label: "Alice"}]);
const pc = createPartCreator([{ resourceId: "@alice", label: "Alice" }]);
const model = new EditorModel([], pc, renderer);
model.update("foo@a", "insertText", {offset: 5, atNodeEnd: true});
model.update("foo@a", "insertText", { offset: 5, atNodeEnd: true });
expect(renderer.count).toBe(1);
expect(model.parts.length).toBe(1);

View File

@ -15,10 +15,10 @@ limitations under the License.
*/
import EditorModel from "../../src/editor/model";
import {createPartCreator, createRenderer} from "./mock";
import {toggleInlineFormat} from "../../src/editor/operations";
import { createPartCreator, createRenderer } from "./mock";
import { toggleInlineFormat } from "../../src/editor/operations";
const SERIALIZED_NEWLINE = {"text": "\n", "type": "newline"};
const SERIALIZED_NEWLINE = { "text": "\n", "type": "newline" };
describe('editor/operations: formatting operations', () => {
describe('toggleInlineFormat', () => {
@ -33,9 +33,9 @@ describe('editor/operations: formatting operations', () => {
model.positionForOffset(11, false)); // around "world"
expect(range.parts[0].text).toBe("world");
expect(model.serializeParts()).toEqual([{"text": "hello world!", "type": "plain"}]);
expect(model.serializeParts()).toEqual([{ "text": "hello world!", "type": "plain" }]);
toggleInlineFormat(range, "_");
expect(model.serializeParts()).toEqual([{"text": "hello _world_!", "type": "plain"}]);
expect(model.serializeParts()).toEqual([{ "text": "hello _world_!", "type": "plain" }]);
});
it('works for parts of words', () => {
@ -49,9 +49,9 @@ describe('editor/operations: formatting operations', () => {
model.positionForOffset(10, false)); // around "orl"
expect(range.parts[0].text).toBe("orl");
expect(model.serializeParts()).toEqual([{"text": "hello world!", "type": "plain"}]);
expect(model.serializeParts()).toEqual([{ "text": "hello world!", "type": "plain" }]);
toggleInlineFormat(range, "*");
expect(model.serializeParts()).toEqual([{"text": "hello w*orl*d!", "type": "plain"}]);
expect(model.serializeParts()).toEqual([{ "text": "hello w*orl*d!", "type": "plain" }]);
});
it('works for around pills', () => {
@ -68,15 +68,15 @@ describe('editor/operations: formatting operations', () => {
expect(range.parts.map(p => p.text).join("")).toBe("there @room, how are you");
expect(model.serializeParts()).toEqual([
{"text": "hello there ", "type": "plain"},
{"text": "@room", "type": "at-room-pill"},
{"text": ", how are you doing?", "type": "plain"},
{ "text": "hello there ", "type": "plain" },
{ "text": "@room", "type": "at-room-pill" },
{ "text": ", how are you doing?", "type": "plain" },
]);
toggleInlineFormat(range, "_");
expect(model.serializeParts()).toEqual([
{"text": "hello _there ", "type": "plain"},
{"text": "@room", "type": "at-room-pill"},
{"text": ", how are you_ doing?", "type": "plain"},
{ "text": "hello _there ", "type": "plain" },
{ "text": "@room", "type": "at-room-pill" },
{ "text": ", how are you_ doing?", "type": "plain" },
]);
});
@ -94,15 +94,15 @@ describe('editor/operations: formatting operations', () => {
expect(range.parts.map(p => p.text).join("")).toBe("world,\nhow");
expect(model.serializeParts()).toEqual([
{"text": "hello world,", "type": "plain"},
{ "text": "hello world,", "type": "plain" },
SERIALIZED_NEWLINE,
{"text": "how are you doing?", "type": "plain"},
{ "text": "how are you doing?", "type": "plain" },
]);
toggleInlineFormat(range, "**");
expect(model.serializeParts()).toEqual([
{"text": "hello **world,", "type": "plain"},
{ "text": "hello **world,", "type": "plain" },
SERIALIZED_NEWLINE,
{"text": "how** are you doing?", "type": "plain"},
{ "text": "how** are you doing?", "type": "plain" },
]);
});
@ -125,9 +125,9 @@ describe('editor/operations: formatting operations', () => {
expect(model.serializeParts()).toEqual([
SERIALIZED_NEWLINE,
SERIALIZED_NEWLINE,
{"text": "hello world,", "type": "plain"},
{ "text": "hello world,", "type": "plain" },
SERIALIZED_NEWLINE,
{"text": "how are you doing?", "type": "plain"},
{ "text": "how are you doing?", "type": "plain" },
SERIALIZED_NEWLINE,
SERIALIZED_NEWLINE,
]);
@ -135,9 +135,9 @@ describe('editor/operations: formatting operations', () => {
expect(model.serializeParts()).toEqual([
SERIALIZED_NEWLINE,
SERIALIZED_NEWLINE,
{"text": "**hello world,", "type": "plain"},
{ "text": "**hello world,", "type": "plain" },
SERIALIZED_NEWLINE,
{"text": "how are you doing?**", "type": "plain"},
{ "text": "how are you doing?**", "type": "plain" },
SERIALIZED_NEWLINE,
SERIALIZED_NEWLINE,
]);
@ -158,32 +158,32 @@ describe('editor/operations: formatting operations', () => {
let range = model.startRange(model.positionForOffset(0, true), model.getPositionAtEnd()); // select-all
expect(model.serializeParts()).toEqual([
{"text": "hello world,", "type": "plain"},
{ "text": "hello world,", "type": "plain" },
SERIALIZED_NEWLINE,
{"text": "how are you doing?", "type": "plain"},
{ "text": "how are you doing?", "type": "plain" },
SERIALIZED_NEWLINE,
SERIALIZED_NEWLINE,
{"text": "new paragraph", "type": "plain"},
{ "text": "new paragraph", "type": "plain" },
]);
toggleInlineFormat(range, "__");
expect(model.serializeParts()).toEqual([
{"text": "__hello world,", "type": "plain"},
{ "text": "__hello world,", "type": "plain" },
SERIALIZED_NEWLINE,
{"text": "how are you doing?__", "type": "plain"},
{ "text": "how are you doing?__", "type": "plain" },
SERIALIZED_NEWLINE,
SERIALIZED_NEWLINE,
{"text": "__new paragraph__", "type": "plain"},
{ "text": "__new paragraph__", "type": "plain" },
]);
range = model.startRange(model.positionForOffset(0, true), model.getPositionAtEnd()); // select-all
console.log("RANGE", range.parts);
toggleInlineFormat(range, "__");
expect(model.serializeParts()).toEqual([
{"text": "hello world,", "type": "plain"},
{ "text": "hello world,", "type": "plain" },
SERIALIZED_NEWLINE,
{"text": "how are you doing?", "type": "plain"},
{ "text": "how are you doing?", "type": "plain" },
SERIALIZED_NEWLINE,
SERIALIZED_NEWLINE,
{"text": "new paragraph", "type": "plain"},
{ "text": "new paragraph", "type": "plain" },
]);
});
});

View File

@ -15,7 +15,7 @@ limitations under the License.
*/
import EditorModel from "../../src/editor/model";
import {createPartCreator} from "./mock";
import { createPartCreator } from "./mock";
function createRenderer() {
const render = (c) => {

View File

@ -15,7 +15,7 @@ limitations under the License.
*/
import EditorModel from "../../src/editor/model";
import {createPartCreator, createRenderer} from "./mock";
import { createPartCreator, createRenderer } from "./mock";
const pillChannel = "#riot-dev:matrix.org";

View File

@ -15,8 +15,8 @@ limitations under the License.
*/
import EditorModel from "../../src/editor/model";
import {htmlSerializeIfNeeded} from "../../src/editor/serialize";
import {createPartCreator} from "./mock";
import { htmlSerializeIfNeeded } from "../../src/editor/serialize";
import { createPartCreator } from "./mock";
describe('editor/serialize', function() {
it('user pill turns message into html', function() {