Fixes #4317: Compare all properties of IHTMLContentElement for equals check

This commit is contained in:
Alex Dima
2016-03-17 09:15:28 +01:00
parent 41f3c97a89
commit 9a4d2bf43d
3 changed files with 101 additions and 41 deletions

View File

@@ -5,6 +5,11 @@
'use strict';
export interface IHTMLContentElementCode {
language: string;
value: string;
}
export interface IHTMLContentElement {
/**
* supports **bold**, __italics__, and [[actions]]
@@ -19,5 +24,58 @@ export interface IHTMLContentElement {
isText?: boolean;
role?: string;
markdown?: string;
code?: { language: string; value: string; };
}
code?: IHTMLContentElementCode;
}
function htmlContentElementCodeEqual(a:IHTMLContentElementCode, b:IHTMLContentElementCode): boolean {
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
return (
a.language === b.language
&& a.value === b.value
);
}
function htmlContentElementEqual(a:IHTMLContentElement, b:IHTMLContentElement): boolean {
return (
a.formattedText === b.formattedText
&& a.text === b.text
&& a.className === b.className
&& a.style === b.style
&& a.customStyle === b.customStyle
&& a.tagName === b.tagName
&& a.isText === b.isText
&& a.role === b.role
&& a.markdown === b.markdown
&& htmlContentElementCodeEqual(a.code, b.code)
&& htmlContentElementArrEquals(a.children, b.children)
);
}
export function htmlContentElementArrEquals(a:IHTMLContentElement[], b:IHTMLContentElement[]): boolean {
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
let aLen = a.length,
bLen = b.length;
if (aLen !== bLen) {
return false;
}
for (let i = 0; i < aLen; i++) {
if (!htmlContentElementEqual(a[i], b[i])) {
return false;
}
}
return true;
}