Auto-fix lint errors
This commit is contained in:
parent
4c5720a573
commit
ae0a8b8da4
625 changed files with 3170 additions and 3232 deletions
|
@ -15,11 +15,11 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {KeyboardEvent} from "react";
|
||||
import { KeyboardEvent } from "react";
|
||||
|
||||
import {Part, CommandPartCreator, PartCreator} from "./parts";
|
||||
import { Part, CommandPartCreator, PartCreator } from "./parts";
|
||||
import DocumentPosition from "./position";
|
||||
import {ICompletion} from "../autocomplete/Autocompleter";
|
||||
import { ICompletion } from "../autocomplete/Autocompleter";
|
||||
import Autocomplete from "../components/views/rooms/Autocomplete";
|
||||
|
||||
export interface ICallback {
|
||||
|
@ -52,7 +52,7 @@ export default class AutocompleteWrapperModel {
|
|||
}
|
||||
|
||||
public close() {
|
||||
this.updateCallback({close: true});
|
||||
this.updateCallback({ close: true });
|
||||
}
|
||||
|
||||
public hasSelection() {
|
||||
|
@ -65,7 +65,7 @@ export default class AutocompleteWrapperModel {
|
|||
}
|
||||
|
||||
public onEnter() {
|
||||
this.updateCallback({close: true});
|
||||
this.updateCallback({ close: true });
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +117,7 @@ export default class AutocompleteWrapperModel {
|
|||
}
|
||||
|
||||
private partForCompletion(completion: ICompletion) {
|
||||
const {completionId} = completion;
|
||||
const { completionId } = completion;
|
||||
const text = completion.completion;
|
||||
switch (completion.type) {
|
||||
case "room":
|
||||
|
|
|
@ -15,11 +15,11 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {needsCaretNodeBefore, needsCaretNodeAfter} from "./render";
|
||||
import { needsCaretNodeBefore, needsCaretNodeAfter } from "./render";
|
||||
import Range from "./range";
|
||||
import EditorModel from "./model";
|
||||
import DocumentPosition, {IPosition} from "./position";
|
||||
import {Part} from "./parts";
|
||||
import DocumentPosition, { IPosition } from "./position";
|
||||
import { Part } from "./parts";
|
||||
|
||||
export type Caret = Range | DocumentPosition;
|
||||
|
||||
|
@ -44,7 +44,7 @@ function setDocumentRangeSelection(editor: HTMLDivElement, model: EditorModel, r
|
|||
|
||||
export function setCaretPosition(editor: HTMLDivElement, model: EditorModel, caretPosition: IPosition) {
|
||||
const range = document.createRange();
|
||||
const {node, offset} = getNodeAndOffsetForPosition(editor, model, caretPosition);
|
||||
const { node, offset } = getNodeAndOffsetForPosition(editor, model, caretPosition);
|
||||
range.setStart(node, offset);
|
||||
range.collapse(true);
|
||||
|
||||
|
@ -68,7 +68,7 @@ export function setCaretPosition(editor: HTMLDivElement, model: EditorModel, car
|
|||
}
|
||||
|
||||
function getNodeAndOffsetForPosition(editor: HTMLDivElement, model: EditorModel, position: IPosition) {
|
||||
const {offset, lineIndex, nodeIndex} = getLineAndNodePosition(model, position);
|
||||
const { offset, lineIndex, nodeIndex } = getLineAndNodePosition(model, position);
|
||||
const lineNode = editor.childNodes[lineIndex];
|
||||
|
||||
let focusNode;
|
||||
|
@ -82,16 +82,16 @@ function getNodeAndOffsetForPosition(editor: HTMLDivElement, model: EditorModel,
|
|||
focusNode = focusNode.firstChild;
|
||||
}
|
||||
}
|
||||
return {node: focusNode, offset};
|
||||
return { node: focusNode, offset };
|
||||
}
|
||||
|
||||
export function getLineAndNodePosition(model: EditorModel, caretPosition: IPosition) {
|
||||
const {parts} = model;
|
||||
const { parts } = model;
|
||||
const partIndex = caretPosition.index;
|
||||
const lineResult = findNodeInLineForPart(parts, partIndex);
|
||||
const {lineIndex} = lineResult;
|
||||
let {nodeIndex} = lineResult;
|
||||
let {offset} = caretPosition;
|
||||
const { lineIndex } = lineResult;
|
||||
let { nodeIndex } = lineResult;
|
||||
let { offset } = caretPosition;
|
||||
// we're at an empty line between a newline part
|
||||
// and another newline part or end/start of parts.
|
||||
// set offset to 0 so it gets set to the <br> inside the line container
|
||||
|
@ -99,9 +99,9 @@ export function getLineAndNodePosition(model: EditorModel, caretPosition: IPosit
|
|||
offset = 0;
|
||||
} else {
|
||||
// move caret out of uneditable part (into caret node, or empty line br) if needed
|
||||
({nodeIndex, offset} = moveOutOfUneditablePart(parts, partIndex, nodeIndex, offset));
|
||||
({ nodeIndex, offset } = moveOutOfUneditablePart(parts, partIndex, nodeIndex, offset));
|
||||
}
|
||||
return {lineIndex, nodeIndex, offset};
|
||||
return { lineIndex, nodeIndex, offset };
|
||||
}
|
||||
|
||||
function findNodeInLineForPart(parts: Part[], partIndex: number) {
|
||||
|
@ -137,7 +137,7 @@ function findNodeInLineForPart(parts: Part[], partIndex: number) {
|
|||
}
|
||||
}
|
||||
|
||||
return {lineIndex, nodeIndex};
|
||||
return { lineIndex, nodeIndex };
|
||||
}
|
||||
|
||||
function moveOutOfUneditablePart(parts: Part[], partIndex: number, nodeIndex: number, offset: number) {
|
||||
|
@ -159,5 +159,5 @@ function moveOutOfUneditablePart(parts: Part[], partIndex: number, nodeIndex: nu
|
|||
offset = 0;
|
||||
}
|
||||
}
|
||||
return {nodeIndex, offset};
|
||||
return { nodeIndex, offset };
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ function parseAtRoomMentions(text: string, partCreator: PartCreator) {
|
|||
}
|
||||
|
||||
function parseLink(a: HTMLAnchorElement, partCreator: PartCreator) {
|
||||
const {href} = a;
|
||||
const { href } = a;
|
||||
const resourceId = getPrimaryPermalinkEntity(href); // The room/user ID
|
||||
const prefix = resourceId ? resourceId[0] : undefined; // First character of ID
|
||||
switch (prefix) {
|
||||
|
@ -297,7 +297,7 @@ export function parsePlainTextMessage(body: string, partCreator: PartCreator, is
|
|||
}, []);
|
||||
}
|
||||
|
||||
export function parseEvent(event: MatrixEvent, partCreator: PartCreator, {isQuotedMessage = false} = {}) {
|
||||
export function parseEvent(event: MatrixEvent, partCreator: PartCreator, { isQuotedMessage = false } = {}) {
|
||||
const content = event.getContent();
|
||||
let parts;
|
||||
if (content.format === "org.matrix.custom.html") {
|
||||
|
|
|
@ -35,9 +35,9 @@ function diffStringsAtEnd(oldStr: string, newStr: string): IDiff {
|
|||
const len = Math.min(oldStr.length, newStr.length);
|
||||
const startInCommon = oldStr.substr(0, len) === newStr.substr(0, len);
|
||||
if (startInCommon && oldStr.length > newStr.length) {
|
||||
return {removed: oldStr.substr(len), at: len};
|
||||
return { removed: oldStr.substr(len), at: len };
|
||||
} else if (startInCommon && oldStr.length < newStr.length) {
|
||||
return {added: newStr.substr(len), at: len};
|
||||
return { added: newStr.substr(len), at: len };
|
||||
} else {
|
||||
const commonStartLen = firstDiff(oldStr, newStr);
|
||||
return {
|
||||
|
@ -55,7 +55,7 @@ export function diffDeletion(oldStr: string, newStr: string): IDiff {
|
|||
}
|
||||
const firstDiffIdx = firstDiff(oldStr, newStr);
|
||||
const amount = oldStr.length - newStr.length;
|
||||
return {at: firstDiffIdx, removed: oldStr.substr(firstDiffIdx, amount)};
|
||||
return { at: firstDiffIdx, removed: oldStr.substr(firstDiffIdx, amount) };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {CARET_NODE_CHAR, isCaretNode} from "./render";
|
||||
import { CARET_NODE_CHAR, isCaretNode } from "./render";
|
||||
import DocumentOffset from "./offset";
|
||||
|
||||
type Predicate = (node: Node) => boolean;
|
||||
|
@ -44,8 +44,8 @@ export function walkDOMDepthFirst(rootNode: Node, enterNodeCallback: Predicate,
|
|||
}
|
||||
|
||||
export function getCaretOffsetAndText(editor: HTMLDivElement, sel: Selection) {
|
||||
const {offset, text} = getSelectionOffsetAndText(editor, sel.focusNode, sel.focusOffset);
|
||||
return {caret: offset, text};
|
||||
const { offset, text } = getSelectionOffsetAndText(editor, sel.focusNode, sel.focusOffset);
|
||||
return { caret: offset, text };
|
||||
}
|
||||
|
||||
function tryReduceSelectionToTextNode(selectionNode: Node, selectionOffset: number) {
|
||||
|
@ -86,10 +86,10 @@ function tryReduceSelectionToTextNode(selectionNode: Node, selectionOffset: numb
|
|||
}
|
||||
|
||||
function getSelectionOffsetAndText(editor: HTMLDivElement, selectionNode: Node, selectionOffset: number) {
|
||||
const {node, characterOffset} = tryReduceSelectionToTextNode(selectionNode, selectionOffset);
|
||||
const {text, offsetToNode} = getTextAndOffsetToNode(editor, node);
|
||||
const { node, characterOffset } = tryReduceSelectionToTextNode(selectionNode, selectionOffset);
|
||||
const { text, offsetToNode } = getTextAndOffsetToNode(editor, node);
|
||||
const offset = getCaret(node, offsetToNode, characterOffset);
|
||||
return {offset, text};
|
||||
return { offset, text };
|
||||
}
|
||||
|
||||
// gets the caret position details, ignoring and adjusting to
|
||||
|
@ -163,7 +163,7 @@ function getTextAndOffsetToNode(editor: HTMLDivElement, selectionNode: Node) {
|
|||
|
||||
walkDOMDepthFirst(editor, enterNodeCallback, leaveNodeCallback);
|
||||
|
||||
return {text, offsetToNode};
|
||||
return { text, offsetToNode };
|
||||
}
|
||||
|
||||
// get text value of text node, ignoring ZWS if it's a caret node
|
||||
|
|
|
@ -15,9 +15,9 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import EditorModel from "./model";
|
||||
import {IDiff} from "./diff";
|
||||
import {SerializedPart} from "./parts";
|
||||
import {Caret} from "./caret";
|
||||
import { IDiff } from "./diff";
|
||||
import { SerializedPart } from "./parts";
|
||||
import { Caret } from "./caret";
|
||||
|
||||
interface IHistory {
|
||||
parts: SerializedPart[];
|
||||
|
@ -92,7 +92,7 @@ export default class HistoryManager {
|
|||
this.stack.pop();
|
||||
}
|
||||
const parts = model.serializeParts();
|
||||
this.stack.push({parts, caret});
|
||||
this.stack.push({ parts, caret });
|
||||
this.currentIndex = this.stack.length - 1;
|
||||
this.lastCaret = null;
|
||||
this.changedSinceLastPush = false;
|
||||
|
|
|
@ -221,7 +221,7 @@ export default class EditorModel {
|
|||
}
|
||||
|
||||
private setActivePart(pos: DocumentPosition, canOpenAutoComplete: boolean) {
|
||||
const {index} = pos;
|
||||
const { index } = pos;
|
||||
const part = this._parts[index];
|
||||
if (part) {
|
||||
if (index !== this.activePartIdx) {
|
||||
|
@ -250,7 +250,7 @@ export default class EditorModel {
|
|||
return Promise.resolve();
|
||||
}
|
||||
|
||||
private onAutoComplete = ({replaceParts, close}: ICallback) => {
|
||||
private onAutoComplete = ({ replaceParts, close }: ICallback) => {
|
||||
let pos;
|
||||
if (replaceParts) {
|
||||
this._parts.splice(this.autoCompletePartIdx, this.autoCompletePartCount, ...replaceParts);
|
||||
|
@ -295,7 +295,7 @@ export default class EditorModel {
|
|||
* usually because of non-editable parts that can only be removed in their entirety.
|
||||
*/
|
||||
removeText(pos: IPosition, len: number) {
|
||||
let {index, offset} = pos;
|
||||
let { index, offset } = pos;
|
||||
let removedOffsetDecrease = 0;
|
||||
while (len > 0) {
|
||||
// part might be undefined here
|
||||
|
@ -357,8 +357,8 @@ export default class EditorModel {
|
|||
* This can be more than the length of `str` when crossing non-editable parts, which are skipped.
|
||||
*/
|
||||
private addText(pos: IPosition, str: string, inputType: string) {
|
||||
let {index} = pos;
|
||||
const {offset} = pos;
|
||||
let { index } = pos;
|
||||
const { offset } = pos;
|
||||
let addLen = str.length;
|
||||
const part = this._parts[index];
|
||||
if (part) {
|
||||
|
|
|
@ -15,14 +15,14 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import Range from "./range";
|
||||
import {Part} from "./parts";
|
||||
import { Part } from "./parts";
|
||||
|
||||
/**
|
||||
* Some common queries and transformations on the editor model
|
||||
*/
|
||||
|
||||
export function replaceRangeAndExpandSelection(range: Range, newParts: Part[]) {
|
||||
const {model} = range;
|
||||
const { model } = range;
|
||||
model.transform(() => {
|
||||
const oldLen = range.length;
|
||||
const addedLen = range.replace(newParts);
|
||||
|
@ -33,7 +33,7 @@ export function replaceRangeAndExpandSelection(range: Range, newParts: Part[]) {
|
|||
}
|
||||
|
||||
export function replaceRangeAndMoveCaret(range: Range, newParts: Part[]) {
|
||||
const {model} = range;
|
||||
const { model } = range;
|
||||
model.transform(() => {
|
||||
const oldLen = range.length;
|
||||
const addedLen = range.replace(newParts);
|
||||
|
@ -44,7 +44,7 @@ export function replaceRangeAndMoveCaret(range: Range, newParts: Part[]) {
|
|||
}
|
||||
|
||||
export function rangeStartsAtBeginningOfLine(range: Range) {
|
||||
const {model} = range;
|
||||
const { model } = range;
|
||||
const startsWithPartial = range.start.offset !== 0;
|
||||
const isFirstPart = range.start.index === 0;
|
||||
const previousIsNewline = !isFirstPart && model.parts[range.start.index - 1].type === "newline";
|
||||
|
@ -52,7 +52,7 @@ export function rangeStartsAtBeginningOfLine(range: Range) {
|
|||
}
|
||||
|
||||
export function rangeEndsAtEndOfLine(range: Range) {
|
||||
const {model} = range;
|
||||
const { model } = range;
|
||||
const lastPart = model.parts[range.end.index];
|
||||
const endsWithPartial = range.end.offset !== lastPart.text.length;
|
||||
const isLastPart = range.end.index === model.parts.length - 1;
|
||||
|
@ -61,8 +61,8 @@ export function rangeEndsAtEndOfLine(range: Range) {
|
|||
}
|
||||
|
||||
export function formatRangeAsQuote(range: Range) {
|
||||
const {model, parts} = range;
|
||||
const {partCreator} = model;
|
||||
const { model, parts } = range;
|
||||
const { partCreator } = model;
|
||||
for (let i = 0; i < parts.length; ++i) {
|
||||
const part = parts[i];
|
||||
if (part.type === "newline") {
|
||||
|
@ -82,8 +82,8 @@ export function formatRangeAsQuote(range: Range) {
|
|||
}
|
||||
|
||||
export function formatRangeAsCode(range: Range) {
|
||||
const {model, parts} = range;
|
||||
const {partCreator} = model;
|
||||
const { model, parts } = range;
|
||||
const { partCreator } = model;
|
||||
const needsBlock = parts.some(p => p.type === "newline");
|
||||
if (needsBlock) {
|
||||
parts.unshift(partCreator.plain("```"), partCreator.newline());
|
||||
|
@ -108,8 +108,8 @@ const isBlank = part => !part.text || !/\S/.test(part.text);
|
|||
const isNL = part => part.type === "newline";
|
||||
|
||||
export function toggleInlineFormat(range: Range, prefix: string, suffix = prefix) {
|
||||
const {model, parts} = range;
|
||||
const {partCreator} = model;
|
||||
const { model, parts } = range;
|
||||
const { partCreator } = model;
|
||||
|
||||
// compute paragraph [start, end] indexes
|
||||
const paragraphIndexes = [];
|
||||
|
|
|
@ -15,9 +15,9 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {MatrixClient} from "matrix-js-sdk/src/client";
|
||||
import {RoomMember} from "matrix-js-sdk/src/models/room-member";
|
||||
import {Room} from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
|
||||
import AutocompleteWrapperModel, {
|
||||
GetAutocompleterComponent,
|
||||
|
@ -466,7 +466,7 @@ export class PartCreator {
|
|||
constructor(private room: Room, private client: MatrixClient, autoCompleteCreator: AutoCompleteCreator = null) {
|
||||
// pre-create the creator as an object even without callback so it can already be passed
|
||||
// to PillCandidatePart (e.g. while deserializing) and set later on
|
||||
this.autoCompleteCreator = {create: autoCompleteCreator && autoCompleteCreator(this)};
|
||||
this.autoCompleteCreator = { create: autoCompleteCreator && autoCompleteCreator(this) };
|
||||
}
|
||||
|
||||
setAutoCompleteCreator(autoCompleteCreator: AutoCompleteCreator) {
|
||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
import DocumentOffset from "./offset";
|
||||
import EditorModel from "./model";
|
||||
import {Part} from "./parts";
|
||||
import { Part } from "./parts";
|
||||
|
||||
export interface IPosition {
|
||||
index: number;
|
||||
|
@ -62,8 +62,8 @@ export default class DocumentPosition implements IPosition {
|
|||
return this;
|
||||
}
|
||||
|
||||
let {index, offset} = this;
|
||||
const {parts} = model;
|
||||
let { index, offset } = this;
|
||||
const { parts } = model;
|
||||
while (index < parts.length) {
|
||||
const part = parts[index];
|
||||
while (offset < part.text.length) {
|
||||
|
@ -87,7 +87,7 @@ export default class DocumentPosition implements IPosition {
|
|||
return this;
|
||||
}
|
||||
|
||||
let {index, offset} = this;
|
||||
let { index, offset } = this;
|
||||
const parts = model.parts;
|
||||
while (index >= 0) {
|
||||
const part = parts[index];
|
||||
|
|
|
@ -15,8 +15,8 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import EditorModel from "./model";
|
||||
import DocumentPosition, {Predicate} from "./position";
|
||||
import {Part} from "./parts";
|
||||
import DocumentPosition, { Predicate } from "./position";
|
||||
import { Part } from "./parts";
|
||||
|
||||
const whitespacePredicate: Predicate = (index, offset, part) => {
|
||||
return part.text[offset].trim() === "";
|
||||
|
|
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {Part} from "./parts";
|
||||
import { Part } from "./parts";
|
||||
import EditorModel from "./model";
|
||||
|
||||
export function needsCaretNodeBefore(part: Part, prevPart: Part) {
|
||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import Markdown from '../Markdown';
|
||||
import {makeGenericPermalink} from "../utils/permalinks/Permalinks";
|
||||
import { makeGenericPermalink } from "../utils/permalinks/Permalinks";
|
||||
import EditorModel from "./model";
|
||||
import { AllHtmlEntities } from 'html-entities';
|
||||
import SettingsStore from '../settings/SettingsStore';
|
||||
|
@ -45,7 +45,7 @@ export function mdSerialize(model: EditorModel) {
|
|||
}, "");
|
||||
}
|
||||
|
||||
export function htmlSerializeIfNeeded(model: EditorModel, {forceHTML = false} = {}) {
|
||||
export function htmlSerializeIfNeeded(model: EditorModel, { forceHTML = false } = {}) {
|
||||
let md = mdSerialize(model);
|
||||
// copy of raw input to remove unwanted math later
|
||||
const orig = md;
|
||||
|
@ -142,9 +142,9 @@ export function htmlSerializeIfNeeded(model: EditorModel, {forceHTML = false} =
|
|||
|
||||
// add fallback output for latex math, which should not be interpreted as markdown
|
||||
phtml('div, span').each(function(i, e) {
|
||||
const tex = phtml(e).attr('data-mx-maths')
|
||||
const tex = phtml(e).attr('data-mx-maths');
|
||||
if (tex) {
|
||||
phtml(e).html(`<code>${tex}</code>`)
|
||||
phtml(e).html(`<code>${tex}</code>`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -200,18 +200,18 @@ export function stripEmoteCommand(model: EditorModel) {
|
|||
|
||||
export function stripPrefix(model: EditorModel, prefix: string) {
|
||||
model = model.clone();
|
||||
model.removeText({index: 0, offset: 0}, prefix.length);
|
||||
model.removeText({ index: 0, offset: 0 }, prefix.length);
|
||||
return model;
|
||||
}
|
||||
|
||||
export function unescapeMessage(model: EditorModel) {
|
||||
const {parts} = model;
|
||||
const { parts } = model;
|
||||
if (parts.length) {
|
||||
const firstPart = parts[0];
|
||||
// only unescape \/ to / at start of editor
|
||||
if (firstPart.type === "plain" && firstPart.text.startsWith("\\/")) {
|
||||
model = model.clone();
|
||||
model.removeText({index: 0, offset: 0}, 1);
|
||||
model.removeText({ index: 0, offset: 0 }, 1);
|
||||
}
|
||||
}
|
||||
return model;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue