Merge remote-tracking branch 'upstream/develop' into maths-parsing-latex

This commit is contained in:
Sven Mäder 2021-04-06 12:34:51 +02:00
commit 3c1169c7a2
654 changed files with 36969 additions and 10283 deletions

View file

@ -68,24 +68,24 @@ export default class AutocompleteWrapperModel {
this.updateCallback({close: true});
}
public async onTab(e: KeyboardEvent) {
/**
* If there is no current autocompletion, start one and move to the first selection.
*/
public async startSelection() {
const acComponent = this.getAutocompleterComponent();
if (acComponent.countCompletions() === 0) {
// Force completions to show for the text currently entered
await acComponent.forceComplete();
// Select the first item by moving "down"
await acComponent.moveSelection(+1);
} else {
await acComponent.moveSelection(e.shiftKey ? -1 : +1);
}
}
public onUpArrow(e: KeyboardEvent) {
public selectPreviousSelection() {
this.getAutocompleterComponent().moveSelection(-1);
}
public onDownArrow(e: KeyboardEvent) {
public selectNextSelection() {
this.getAutocompleterComponent().moveSelection(+1);
}

View file

@ -60,6 +60,11 @@ function parseLink(a: HTMLAnchorElement, partCreator: PartCreator) {
}
}
function parseImage(img: HTMLImageElement, partCreator: PartCreator) {
const { src } = img;
return partCreator.plain(`![${img.alt.replace(/[[\\\]]/g, c => "\\" + c)}](${src})`);
}
function parseCodeBlock(n: HTMLElement, partCreator: PartCreator) {
const parts = [];
let language = "";
@ -102,6 +107,8 @@ function parseElement(n: HTMLElement, partCreator: PartCreator, lastNode: HTMLEl
return parseHeader(n, partCreator);
case "A":
return parseLink(<HTMLAnchorElement>n, partCreator);
case "IMG":
return parseImage(<HTMLImageElement>n, partCreator);
case "BR":
return partCreator.newline();
case "EM":

View file

@ -189,7 +189,13 @@ abstract class PlainBasePart extends BasePart {
if (chr !== "@" && chr !== "#" && chr !== ":" && chr !== "+") {
return true;
}
// only split if the previous character is a space
// split if we are at the beginning of the part text
if (offset === 0) {
return false;
}
// or split if the previous character is a space
// or if it is a + and this is a :
return this._text[offset - 1] !== " " &&
(this._text[offset - 1] !== "+" || chr !== ":");
@ -329,8 +335,8 @@ class NewlinePart extends BasePart implements IBasePart {
}
class RoomPillPart extends PillPart {
constructor(displayAlias, private room: Room) {
super(displayAlias, displayAlias);
constructor(resourceId: string, label: string, private room: Room) {
super(resourceId, label);
}
setAvatar(node: HTMLElement) {
@ -357,6 +363,10 @@ class RoomPillPart extends PillPart {
}
class AtRoomPillPart extends RoomPillPart {
constructor(text: string, room: Room) {
super(text, text, room);
}
get type(): IPillPart["type"] {
return Type.AtRoomPill;
}
@ -521,7 +531,7 @@ export class PartCreator {
r.getAltAliases().includes(alias);
});
}
return new RoomPillPart(alias, room);
return new RoomPillPart(alias, room ? room.name : alias, room);
}
atRoomPill(text: string) {

View file

@ -34,6 +34,10 @@ export function mdSerialize(model: EditorModel) {
case "at-room-pill":
return html + part.text;
case "room-pill":
// Here we use the resourceId for compatibility with non-rich text clients
// See https://github.com/vector-im/element-web/issues/16660
return html +
`[${part.resourceId.replace(/[[\\\]]/g, c => "\\" + c)}](${makeGenericPermalink(part.resourceId)})`;
case "user-pill":
return html +
`[${part.text.replace(/[[\\\]]/g, c => "\\" + c)}](${makeGenericPermalink(part.resourceId)})`;
@ -156,6 +160,9 @@ export function textSerialize(model: EditorModel) {
case "at-room-pill":
return text + part.text;
case "room-pill":
// Here we use the resourceId for compatibility with non-rich text clients
// See https://github.com/vector-im/element-web/issues/16660
return text + `${part.resourceId}`;
case "user-pill":
return text + `${part.text}`;
}