提交 9a4d2bf4 编写于 作者: A Alex Dima

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

上级 41f3c97a
......@@ -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; };
}
\ No newline at end of file
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;
}
......@@ -5,7 +5,7 @@
'use strict';
import {onUnexpectedError} from 'vs/base/common/errors';
import {IHTMLContentElement} from 'vs/base/common/htmlContent';
import {IHTMLContentElement, htmlContentElementArrEquals} from 'vs/base/common/htmlContent';
import * as strings from 'vs/base/common/strings';
import {TPromise} from 'vs/base/common/winjs.base';
import {IdGenerator} from 'vs/editor/common/core/idGenerator';
......@@ -706,43 +706,6 @@ class ModelDecorationOptions implements editorCommon.IModelDecorationOptions {
this.inlineClassName = cleanClassName(options.inlineClassName||strings.empty);
}
private static _htmlContentEquals(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
&& ModelDecorationOptions._htmlContentArrEquals(a.children, b.children)
);
}
private static _htmlContentArrEquals(a:IHTMLContentElement[], b:IHTMLContentElement[]): boolean {
if (!a) {
return (!b);
}
if (!b) {
return false;
}
let aLen = a.length,
bLen = b.length;
if (aLen !== bLen) {
return false;
}
for (let i = 0; i < aLen; i++) {
if (!ModelDecorationOptions._htmlContentEquals(a[i], b[i])) {
return false;
}
}
return true;
}
private static _overviewRulerEquals(a:editorCommon.IModelDecorationOverviewRulerOptions, b:editorCommon.IModelDecorationOverviewRulerOptions): boolean {
return (
a.color === b.color
......@@ -761,7 +724,7 @@ class ModelDecorationOptions implements editorCommon.IModelDecorationOptions {
&& this.glyphMarginClassName === other.glyphMarginClassName
&& this.linesDecorationsClassName === other.linesDecorationsClassName
&& this.inlineClassName === other.inlineClassName
&& ModelDecorationOptions._htmlContentArrEquals(this.htmlMessage, other.htmlMessage)
&& htmlContentElementArrEquals(this.htmlMessage, other.htmlMessage)
&& ModelDecorationOptions._overviewRulerEquals(this.overviewRuler, other.overviewRuler)
);
}
......
......@@ -564,6 +564,45 @@ suite('deltaDecorations', () => {
);
});
test('issue #4317: editor.setDecorations doesn\'t update the hover message', () => {
let model = new Model('Hello world!', Model.DEFAULT_CREATION_OPTIONS, null);
let ids = model.deltaDecorations([], [{
range: {
startLineNumber: 1,
startColumn: 1,
endLineNumber: 100,
endColumn: 1
},
options: {
htmlMessage: [{
markdown: 'hello1'
}]
}
}]);
ids = model.deltaDecorations(ids, [{
range: {
startLineNumber: 1,
startColumn: 1,
endLineNumber: 100,
endColumn: 1
},
options: {
htmlMessage: [{
markdown: 'hello2'
}]
}
}]);
let actualDecoration = model.getDecorationOptions(ids[0]);
assert.equal(actualDecoration.htmlMessage[0].markdown, 'hello2');
model.dispose();
});
test('model doesn\'t get confused with individual tracked ranges', () => {
var model = new Model([
'Hello world,',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册