Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
41e35e5a
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
41e35e5a
编写于
9月 09, 2016
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tests for range highlight
上级
7c1d8ed4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
186 addition
and
12 deletion
+186
-12
src/vs/editor/test/common/mocks/mockCodeEditor.ts
src/vs/editor/test/common/mocks/mockCodeEditor.ts
+17
-10
src/vs/workbench/common/editor/rangeDecorations.ts
src/vs/workbench/common/editor/rangeDecorations.ts
+1
-2
src/vs/workbench/test/common/editor/rangeDecorations.test.ts
src/vs/workbench/test/common/editor/rangeDecorations.test.ts
+168
-0
未找到文件。
src/vs/editor/test/common/mocks/mockCodeEditor.ts
浏览文件 @
41e35e5a
...
@@ -61,6 +61,14 @@ export class MockCodeEditor extends CommonCodeEditor {
...
@@ -61,6 +61,14 @@ export class MockCodeEditor extends CommonCodeEditor {
this
.
_contributions
[
r
.
getId
()]
=
r
;
this
.
_contributions
[
r
.
getId
()]
=
r
;
return
r
;
return
r
;
}
}
public
dispose
()
{
super
.
dispose
();
if
(
this
.
model
)
{
this
.
model
.
dispose
();
}
this
.
_contextKeyService
.
dispose
();
}
}
}
export
class
MockScopeLocation
implements
IContextKeyServiceTarget
{
export
class
MockScopeLocation
implements
IContextKeyServiceTarget
{
...
@@ -72,6 +80,12 @@ export class MockScopeLocation implements IContextKeyServiceTarget {
...
@@ -72,6 +80,12 @@ export class MockScopeLocation implements IContextKeyServiceTarget {
}
}
export
function
withMockCodeEditor
(
text
:
string
[],
options
:
editorCommon
.
ICodeEditorWidgetCreationOptions
,
callback
:(
editor
:
MockCodeEditor
,
cursor
:
Cursor
)
=>
void
):
void
{
export
function
withMockCodeEditor
(
text
:
string
[],
options
:
editorCommon
.
ICodeEditorWidgetCreationOptions
,
callback
:(
editor
:
MockCodeEditor
,
cursor
:
Cursor
)
=>
void
):
void
{
let
editor
=
<
MockCodeEditor
>
mockCodeEditor
(
text
,
options
);
callback
(
editor
,
editor
.
getCursor
());
editor
.
dispose
();
}
export
function
mockCodeEditor
(
text
:
string
[],
options
:
editorCommon
.
ICodeEditorWidgetCreationOptions
):
CommonCodeEditor
{
let
contextKeyService
=
new
MockKeybindingService
();
let
contextKeyService
=
new
MockKeybindingService
();
...
@@ -80,17 +94,10 @@ export function withMockCodeEditor(text:string[], options:editorCommon.ICodeEdit
...
@@ -80,17 +94,10 @@ export function withMockCodeEditor(text:string[], options:editorCommon.ICodeEdit
let
instantiationService
=
new
InstantiationService
(
services
);
let
instantiationService
=
new
InstantiationService
(
services
);
let
editor
=
new
MockCodeEditor
(
new
MockScopeLocation
(),
options
,
instantiationService
,
contextKeyService
);
let
editor
=
new
MockCodeEditor
(
new
MockScopeLocation
(),
options
,
instantiationService
,
contextKeyService
);
let
model
:
Model
;
let
model
=
options
.
model
||
Model
.
createFromString
(
text
.
join
(
'
\n
'
));
if
(
!
options
.
model
)
{
if
(
model
)
{
model
=
Model
.
createFromString
(
text
.
join
(
'
\n
'
));
editor
.
setModel
(
model
);
editor
.
setModel
(
model
);
}
}
callback
(
editor
,
editor
.
getCursor
());
return
editor
;
editor
.
dispose
();
if
(
model
)
{
model
.
dispose
();
}
contextKeyService
.
dispose
();
}
}
src/vs/workbench/common/editor/rangeDecorations.ts
浏览文件 @
41e35e5a
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IEditor
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEditor
}
from
'
vs/platform/editor/common/editor
'
;
...
@@ -13,7 +12,7 @@ import {asFileEditorInput} from 'vs/workbench/common/editor';
...
@@ -13,7 +12,7 @@ import {asFileEditorInput} from 'vs/workbench/common/editor';
export
interface
IRangeHighlightDecoration
{
export
interface
IRangeHighlightDecoration
{
resource
:
URI
;
resource
:
URI
;
range
:
Range
;
range
:
editorCommon
.
I
Range
;
}
}
export
class
RangeHighlightDecorations
implements
IDisposable
{
export
class
RangeHighlightDecorations
implements
IDisposable
{
...
...
src/vs/workbench/test/common/editor/rangeDecorations.test.ts
0 → 100644
浏览文件 @
41e35e5a
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
{
TestInstantiationService
}
from
'
vs/test/utils/instantiationTestUtils
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
createMockModelService
,
TestEditorService
,
workbenchInstantiationService
}
from
'
vs/test/utils/servicesTestUtils
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
WorkbenchEditorService
=
require
(
'
vs/workbench/services/editor/common/editorService
'
);
import
{
RangeHighlightDecorations
}
from
'
vs/workbench/common/editor/rangeDecorations
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
{
mockCodeEditor
,
MockCodeEditor
}
from
'
vs/editor/test/common/mocks/mockCodeEditor
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
IEditorInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
FileEditorInput
}
from
'
vs/workbench/parts/files/common/editors/fileEditorInput
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Cursor
}
from
'
vs/editor/common/controller/cursor
'
;
suite
(
'
Editor - Range decorations
'
,
()
=>
{
let
instantiationService
:
TestInstantiationService
;
let
editorService
:
WorkbenchEditorService
.
IWorkbenchEditorService
;
let
modelService
:
IModelService
;
let
modeService
:
IModeService
;
let
codeEditor
:
editorCommon
.
ICommonCodeEditor
;
let
cursor
:
Cursor
;
let
model
:
Model
;
let
text
:
string
;
let
testObject
:
RangeHighlightDecorations
;
let
modelsToDispose
:
Model
[]
=
[];
setup
(()
=>
{
instantiationService
=
<
TestInstantiationService
>
workbenchInstantiationService
();
editorService
=
<
WorkbenchEditorService
.
IWorkbenchEditorService
>
instantiationService
.
stub
(
WorkbenchEditorService
.
IWorkbenchEditorService
,
new
TestEditorService
(
function
()
{
}));
modeService
=
instantiationService
.
stub
(
IModeService
);
modelService
=
<
IModelService
>
instantiationService
.
stub
(
IModelService
,
createMockModelService
(
instantiationService
));
text
=
'
LINE1
'
+
'
\n
'
+
'
LINE2
'
+
'
\n
'
+
'
LINE3
'
+
'
\n
'
+
'
LINE4
'
+
'
\r\n
'
+
'
LINE5
'
;
model
=
aModel
(
URI
.
file
(
'
some_file
'
));
codeEditor
=
mockCodeEditor
([],
{
model
});
cursor
=
(
<
MockCodeEditor
>
codeEditor
).
getCursor
();
mockEditorService
(
codeEditor
.
getModel
().
uri
);
instantiationService
.
stub
(
WorkbenchEditorService
.
IWorkbenchEditorService
,
'
getActiveEditor
'
,
{
getControl
:
()
=>
{
return
codeEditor
;
}
});
testObject
=
instantiationService
.
createInstance
(
RangeHighlightDecorations
);
});
teardown
(()
=>
{
codeEditor
.
dispose
();
modelsToDispose
.
forEach
(
model
=>
model
.
dispose
());
});
test
(
'
highlight range for the resource if it is an active editor
'
,
function
()
{
let
range
:
editorCommon
.
IRange
=
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
};
testObject
.
highlightRange
({
resource
:
model
.
uri
,
range
});
let
actuals
=
rangeHighlightDecorations
(
model
);
assert
.
deepEqual
([
range
],
actuals
);
});
test
(
'
remove highlight range
'
,
function
()
{
testObject
.
highlightRange
({
resource
:
model
.
uri
,
range
:
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
}});
testObject
.
removeHighlightRange
();
let
actuals
=
rangeHighlightDecorations
(
model
);
assert
.
deepEqual
([],
actuals
);
});
test
(
'
highlight range for the resource removes previous highlight
'
,
function
()
{
testObject
.
highlightRange
({
resource
:
model
.
uri
,
range
:
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
}});
let
range
:
editorCommon
.
IRange
=
{
startLineNumber
:
2
,
startColumn
:
2
,
endLineNumber
:
4
,
endColumn
:
3
};
testObject
.
highlightRange
({
resource
:
model
.
uri
,
range
});
let
actuals
=
rangeHighlightDecorations
(
model
);
assert
.
deepEqual
([
range
],
actuals
);
});
test
(
'
highlight range for a new resource removes highlight of previous resource
'
,
function
()
{
testObject
.
highlightRange
({
resource
:
model
.
uri
,
range
:
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
}
});
let
anotherModel
=
prepareActiveEditor
(
'
anotherModel
'
);
let
range
:
editorCommon
.
IRange
=
{
startLineNumber
:
2
,
startColumn
:
2
,
endLineNumber
:
4
,
endColumn
:
3
};
testObject
.
highlightRange
({
resource
:
anotherModel
.
uri
,
range
});
let
actuals
=
rangeHighlightDecorations
(
model
);
assert
.
deepEqual
([],
actuals
);
actuals
=
rangeHighlightDecorations
(
anotherModel
);
assert
.
deepEqual
([
range
],
actuals
);
});
test
(
'
highlight is removed on model change
'
,
function
()
{
testObject
.
highlightRange
({
resource
:
model
.
uri
,
range
:
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
}
});
prepareActiveEditor
(
'
anotherModel
'
);
let
actuals
=
rangeHighlightDecorations
(
model
);
assert
.
deepEqual
([],
actuals
);
});
test
(
'
highlight is removed on cursor position change
'
,
function
()
{
testObject
.
highlightRange
({
resource
:
model
.
uri
,
range
:
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
}
});
cursor
.
trigger
(
'
mouse
'
,
editorCommon
.
Handler
.
MoveTo
,
{
position
:
new
Position
(
2
,
1
)
});
let
actuals
=
rangeHighlightDecorations
(
model
);
assert
.
deepEqual
([],
actuals
);
});
test
(
'
range is not highlight if not active editor
'
,
function
()
{
let
model
=
aModel
(
URI
.
file
(
'
some model
'
));
testObject
.
highlightRange
({
resource
:
model
.
uri
,
range
:
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
}
});
let
actuals
=
rangeHighlightDecorations
(
model
);
assert
.
deepEqual
([],
actuals
);
});
test
(
'
previous highlight is not removed if not active editor
'
,
function
()
{
let
range
:
editorCommon
.
IRange
=
{
startLineNumber
:
1
,
startColumn
:
1
,
endLineNumber
:
1
,
endColumn
:
1
};
testObject
.
highlightRange
({
resource
:
model
.
uri
,
range
});
let
model1
=
aModel
(
URI
.
file
(
'
some model
'
));
testObject
.
highlightRange
({
resource
:
model1
.
uri
,
range
:
{
startLineNumber
:
2
,
startColumn
:
1
,
endLineNumber
:
2
,
endColumn
:
1
}
});
let
actuals
=
rangeHighlightDecorations
(
model
);
assert
.
deepEqual
([
range
],
actuals
);
});
function
prepareActiveEditor
(
resource
:
string
):
Model
{
let
model
=
aModel
(
URI
.
file
(
resource
));
codeEditor
.
setModel
(
model
);
mockEditorService
(
model
.
uri
);
return
model
;
}
function
aModel
(
resource
:
URI
,
content
:
string
=
text
):
Model
{
let
model
=
Model
.
createFromString
(
content
,
TextModel
.
DEFAULT_CREATION_OPTIONS
,
null
,
resource
);
modelsToDispose
.
push
(
model
);
return
model
;
}
function
mockEditorService
(
editorInput
:
IEditorInput
)
function
mockEditorService
(
resource
:
URI
)
function
mockEditorService
(
arg
:
any
)
{
let
editorInput
:
IEditorInput
=
arg
instanceof
URI
?
instantiationService
.
createInstance
(
FileEditorInput
,
arg
,
''
,
''
)
:
arg
;
instantiationService
.
stub
(
WorkbenchEditorService
.
IWorkbenchEditorService
,
'
getActiveEditorInput
'
,
editorInput
);
}
function
rangeHighlightDecorations
(
m
:
Model
):
editorCommon
.
IRange
[]
{
let
rangeHighlights
:
editorCommon
.
IRange
[]
=
[];
for
(
let
dec
of
m
.
getAllDecorations
())
{
if
(
dec
.
options
.
className
===
'
rangeHighlight
'
)
{
rangeHighlights
.
push
(
dec
.
range
);
}
}
rangeHighlights
.
sort
(
Range
.
compareRangesUsingStarts
);
return
rangeHighlights
;
}
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录