Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9413602d
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,发现更多精彩内容 >>
未验证
提交
9413602d
编写于
7月 03, 2020
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #101483: check state after await and make tests async
上级
8cd23cf0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
125 addition
and
98 deletion
+125
-98
src/vs/editor/contrib/find/findController.ts
src/vs/editor/contrib/find/findController.ts
+25
-16
src/vs/editor/contrib/find/test/findController.test.ts
src/vs/editor/contrib/find/test/findController.test.ts
+82
-82
src/vs/editor/test/browser/testCodeEditor.ts
src/vs/editor/test/browser/testCodeEditor.ts
+18
-0
未找到文件。
src/vs/editor/contrib/find/findController.ts
浏览文件 @
9413602d
...
...
@@ -280,6 +280,12 @@ export class CommonFindController extends Disposable implements IEditorContribut
if
(
!
stateChanges
.
searchString
&&
opts
.
seedSearchStringFromGlobalClipboard
)
{
let
selectionSearchString
=
await
this
.
getGlobalBufferTerm
();
if
(
!
this
.
_editor
.
hasModel
())
{
// the editor has lost its model in the meantime
return
;
}
if
(
selectionSearchString
)
{
stateChanges
.
searchString
=
selectionSearchString
;
}
...
...
@@ -364,13 +370,14 @@ export class CommonFindController extends Disposable implements IEditorContribut
return
''
;
}
public
async
setGlobalBufferTerm
(
text
:
string
)
{
public
setGlobalBufferTerm
(
text
:
string
):
void
{
if
(
this
.
_editor
.
getOption
(
EditorOption
.
find
).
globalFindClipboard
&&
this
.
_clipboardService
&&
this
.
_editor
.
hasModel
()
&&
!
this
.
_editor
.
getModel
().
isTooLargeForSyncing
()
)
{
await
this
.
_clipboardService
.
writeFindText
(
text
);
// intentionally not awaited
this
.
_clipboardService
.
writeFindText
(
text
);
}
}
}
...
...
@@ -424,10 +431,12 @@ export class FindController extends CommonFindController implements IFindControl
await
super
.
_start
(
opts
);
if
(
opts
.
shouldFocus
===
FindStartFocusAction
.
FocusReplaceInput
)
{
this
.
_widget
!
.
focusReplaceInput
();
}
else
if
(
opts
.
shouldFocus
===
FindStartFocusAction
.
FocusFindInput
)
{
this
.
_widget
!
.
focusFindInput
();
if
(
this
.
_widget
)
{
if
(
opts
.
shouldFocus
===
FindStartFocusAction
.
FocusReplaceInput
)
{
this
.
_widget
.
focusReplaceInput
();
}
else
if
(
opts
.
shouldFocus
===
FindStartFocusAction
.
FocusFindInput
)
{
this
.
_widget
.
focusFindInput
();
}
}
}
...
...
@@ -470,10 +479,10 @@ export class StartFindAction extends EditorAction {
});
}
public
run
(
accessor
:
ServicesAccessor
|
null
,
editor
:
ICodeEditor
):
void
{
public
async
run
(
accessor
:
ServicesAccessor
|
null
,
editor
:
ICodeEditor
):
Promise
<
void
>
{
let
controller
=
CommonFindController
.
get
(
editor
);
if
(
controller
)
{
controller
.
start
({
await
controller
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
editor
.
getOption
(
EditorOption
.
find
).
seedSearchStringFromSelection
,
seedSearchStringFromGlobalClipboard
:
editor
.
getOption
(
EditorOption
.
find
).
globalFindClipboard
,
...
...
@@ -508,7 +517,7 @@ export class StartFindWithSelectionAction extends EditorAction {
public
async
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
Promise
<
void
>
{
let
controller
=
CommonFindController
.
get
(
editor
);
if
(
controller
)
{
controller
.
start
({
await
controller
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
true
,
seedSearchStringFromGlobalClipboard
:
false
,
...
...
@@ -518,15 +527,15 @@ export class StartFindWithSelectionAction extends EditorAction {
loop
:
editor
.
getOption
(
EditorOption
.
find
).
loop
});
return
controller
.
setGlobalBufferTerm
(
controller
.
getState
().
searchString
);
controller
.
setGlobalBufferTerm
(
controller
.
getState
().
searchString
);
}
}
}
export
abstract
class
MatchFindAction
extends
EditorAction
{
public
run
(
accessor
:
ServicesAccessor
|
null
,
editor
:
ICodeEditor
):
void
{
public
async
run
(
accessor
:
ServicesAccessor
|
null
,
editor
:
ICodeEditor
):
Promise
<
void
>
{
let
controller
=
CommonFindController
.
get
(
editor
);
if
(
controller
&&
!
this
.
_run
(
controller
))
{
controller
.
start
({
await
controller
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
(
controller
.
getState
().
searchString
.
length
===
0
)
&&
editor
.
getOption
(
EditorOption
.
find
).
seedSearchStringFromSelection
,
seedSearchStringFromGlobalClipboard
:
true
,
...
...
@@ -629,7 +638,7 @@ export class PreviousMatchFindAction2 extends MatchFindAction {
}
export
abstract
class
SelectionMatchFindAction
extends
EditorAction
{
public
run
(
accessor
:
ServicesAccessor
|
null
,
editor
:
ICodeEditor
):
void
{
public
async
run
(
accessor
:
ServicesAccessor
|
null
,
editor
:
ICodeEditor
):
Promise
<
void
>
{
let
controller
=
CommonFindController
.
get
(
editor
);
if
(
!
controller
)
{
return
;
...
...
@@ -639,7 +648,7 @@ export abstract class SelectionMatchFindAction extends EditorAction {
controller
.
setSearchString
(
selectionSearchString
);
}
if
(
!
this
.
_run
(
controller
))
{
controller
.
start
({
await
controller
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
editor
.
getOption
(
EditorOption
.
find
).
seedSearchStringFromSelection
,
seedSearchStringFromGlobalClipboard
:
false
,
...
...
@@ -720,7 +729,7 @@ export class StartFindReplaceAction extends EditorAction {
});
}
public
run
(
accessor
:
ServicesAccessor
|
null
,
editor
:
ICodeEditor
):
void
{
public
async
run
(
accessor
:
ServicesAccessor
|
null
,
editor
:
ICodeEditor
):
Promise
<
void
>
{
if
(
!
editor
.
hasModel
()
||
editor
.
getOption
(
EditorOption
.
readOnly
))
{
return
;
}
...
...
@@ -745,7 +754,7 @@ export class StartFindReplaceAction extends EditorAction {
if
(
controller
)
{
controller
.
start
({
await
controller
.
start
({
forceRevealReplace
:
true
,
seedSearchStringFromSelection
:
seedSearchStringFromSelection
,
seedSearchStringFromGlobalClipboard
:
editor
.
getOption
(
EditorOption
.
find
).
seedSearchStringFromSelection
,
...
...
src/vs/editor/contrib/find/test/findController.test.ts
浏览文件 @
9413602d
...
...
@@ -14,7 +14,7 @@ import { Range } from 'vs/editor/common/core/range';
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
CommonFindController
,
FindStartFocusAction
,
IFindStartOptions
,
NextMatchFindAction
,
NextSelectionMatchFindAction
,
StartFindAction
,
StartFindReplaceAction
}
from
'
vs/editor/contrib/find/findController
'
;
import
{
CONTEXT_FIND_INPUT_FOCUSED
}
from
'
vs/editor/contrib/find/findModel
'
;
import
{
withTestCodeEditor
}
from
'
vs/editor/test/browser/testCodeEditor
'
;
import
{
with
Async
TestCodeEditor
}
from
'
vs/editor/test/browser/testCodeEditor
'
;
import
{
IClipboardService
}
from
'
vs/platform/clipboard/common/clipboardService
'
;
import
{
IContextKey
,
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
...
...
@@ -55,7 +55,7 @@ function fromSelection(slc: Selection): number[] {
return
[
slc
.
startLineNumber
,
slc
.
startColumn
,
slc
.
endLineNumber
,
slc
.
endColumn
];
}
suite
(
'
FindController
'
,
()
=>
{
suite
(
'
FindController
'
,
async
()
=>
{
let
queryState
:
{
[
key
:
string
]:
any
;
}
=
{};
let
clipboardState
=
''
;
let
serviceCollection
=
new
ServiceCollection
();
...
...
@@ -77,13 +77,13 @@ suite('FindController', () => {
});
}
/* test('stores to the global clipboard buffer on start find action', () => {
with
TestCodeEditor([
/* test('stores to the global clipboard buffer on start find action',
async
() => {
await withAsync
TestCodeEditor([
'ABC',
'ABC',
'XYZ',
'ABC'
], { serviceCollection: serviceCollection }, (editor) => {
], { serviceCollection: serviceCollection },
async
(editor) => {
clipboardState = '';
if (!platform.isMacintosh) {
assert.ok(true);
...
...
@@ -101,13 +101,13 @@ suite('FindController', () => {
});
});
test('reads from the global clipboard buffer on next find action if buffer exists', () => {
with
TestCodeEditor([
test('reads from the global clipboard buffer on next find action if buffer exists',
async
() => {
await withAsync
TestCodeEditor([
'ABC',
'ABC',
'XYZ',
'ABC'
], { serviceCollection: serviceCollection }, (editor) => {
], { serviceCollection: serviceCollection },
async
(editor) => {
clipboardState = 'ABC';
if (!platform.isMacintosh) {
...
...
@@ -128,13 +128,13 @@ suite('FindController', () => {
});
});
test('writes to the global clipboard buffer when text changes', () => {
with
TestCodeEditor([
test('writes to the global clipboard buffer when text changes',
async
() => {
await withAsync
TestCodeEditor([
'ABC',
'ABC',
'XYZ',
'ABC'
], { serviceCollection: serviceCollection }, (editor) => {
], { serviceCollection: serviceCollection },
async
(editor) => {
clipboardState = '';
if (!platform.isMacintosh) {
assert.ok(true);
...
...
@@ -152,13 +152,13 @@ suite('FindController', () => {
});
}); */
test
(
'
issue #1857: F3, Find Next, acts like "Find Under Cursor"
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #1857: F3, Find Next, acts like "Find Under Cursor"
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
ABC
'
,
'
ABC
'
,
'
XYZ
'
,
'
ABC
'
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
clipboardState
=
''
;
// The cursor is at the very top, of the file, at the first ABC
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
...
...
@@ -167,7 +167,7 @@ suite('FindController', () => {
let
nextMatchFindAction
=
new
NextMatchFindAction
();
// I hit Ctrl+F to show the Find dialog
startFindAction
.
run
(
null
,
editor
);
await
startFindAction
.
run
(
null
,
editor
);
// I type ABC.
findState
.
change
({
searchString
:
'
A
'
},
true
);
...
...
@@ -201,7 +201,7 @@ suite('FindController', () => {
assert
.
deepEqual
(
fromSelection
(
editor
.
getSelection
()
!
),
[
1
,
4
,
1
,
4
]);
// I hit F3 to "Find Next" to find the next occurrence of ABC, but instead it searches for XYZ.
nextMatchFindAction
.
run
(
null
,
editor
);
await
nextMatchFindAction
.
run
(
null
,
editor
);
assert
.
equal
(
findState
.
searchString
,
'
ABC
'
);
assert
.
equal
(
findController
.
hasFocus
,
false
);
...
...
@@ -210,10 +210,10 @@ suite('FindController', () => {
});
});
test
(
'
issue #3090: F3 does not loop with two matches on a single line
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #3090: F3 does not loop with two matches on a single line
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
import nls = require(
\'
vs/nls
\'
);
'
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
clipboardState
=
''
;
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
let
nextMatchFindAction
=
new
NextMatchFindAction
();
...
...
@@ -223,22 +223,22 @@ suite('FindController', () => {
column
:
9
});
nextMatchFindAction
.
run
(
null
,
editor
);
await
nextMatchFindAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
fromSelection
(
editor
.
getSelection
()
!
),
[
1
,
26
,
1
,
29
]);
nextMatchFindAction
.
run
(
null
,
editor
);
await
nextMatchFindAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
fromSelection
(
editor
.
getSelection
()
!
),
[
1
,
8
,
1
,
11
]);
findController
.
dispose
();
});
});
test
(
'
issue #6149: Auto-escape highlighted text for search and replace regex mode
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #6149: Auto-escape highlighted text for search and replace regex mode
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
var x = (3 * 5)
'
,
'
var y = (3 * 5)
'
,
'
var z = (3 * 5)
'
,
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
clipboardState
=
''
;
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
let
startFindAction
=
new
StartFindAction
();
...
...
@@ -247,22 +247,22 @@ suite('FindController', () => {
editor
.
setSelection
(
new
Selection
(
1
,
9
,
1
,
13
));
findController
.
toggleRegex
();
startFindAction
.
run
(
null
,
editor
);
await
startFindAction
.
run
(
null
,
editor
);
nextMatchFindAction
.
run
(
null
,
editor
);
await
nextMatchFindAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
fromSelection
(
editor
.
getSelection
()
!
),
[
2
,
9
,
2
,
13
]);
nextMatchFindAction
.
run
(
null
,
editor
);
await
nextMatchFindAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
fromSelection
(
editor
.
getSelection
()
!
),
[
1
,
9
,
1
,
13
]);
findController
.
dispose
();
});
});
test
(
'
issue #41027: Don
\'
t replace find input value on replace action if find input is active
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #41027: Don
\'
t replace find input value on replace action if find input is active
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
test
'
,
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
let
testRegexString
=
'
tes.
'
;
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
let
nextMatchFindAction
=
new
NextMatchFindAction
();
...
...
@@ -270,7 +270,7 @@ suite('FindController', () => {
findController
.
toggleRegex
();
findController
.
setSearchString
(
testRegexString
);
findController
.
start
({
await
findController
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
false
,
seedSearchStringFromGlobalClipboard
:
false
,
...
...
@@ -279,8 +279,8 @@ suite('FindController', () => {
updateSearchScope
:
false
,
loop
:
true
});
nextMatchFindAction
.
run
(
null
,
editor
);
startFindReplaceAction
.
run
(
null
,
editor
);
await
nextMatchFindAction
.
run
(
null
,
editor
);
await
startFindReplaceAction
.
run
(
null
,
editor
);
assert
.
equal
(
findController
.
getState
().
searchString
,
testRegexString
);
...
...
@@ -288,15 +288,15 @@ suite('FindController', () => {
});
});
test
(
'
issue #9043: Clear search scope when find widget is hidden
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #9043: Clear search scope when find widget is hidden
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
var x = (3 * 5)
'
,
'
var y = (3 * 5)
'
,
'
var z = (3 * 5)
'
,
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
clipboardState
=
''
;
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
findController
.
start
({
await
findController
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
false
,
seedSearchStringFromGlobalClipboard
:
false
,
...
...
@@ -319,15 +319,15 @@ suite('FindController', () => {
});
});
test
(
'
issue #18111: Regex replace with single space replaces with no space
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #18111: Regex replace with single space replaces with no space
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
HRESULT OnAmbientPropertyChange(DISPID dispid);
'
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
clipboardState
=
''
;
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
let
startFindAction
=
new
StartFindAction
();
startFindAction
.
run
(
null
,
editor
);
await
startFindAction
.
run
(
null
,
editor
);
findController
.
getState
().
change
({
searchString
:
'
\\
b
\\
s{3}
\\
b
'
,
replaceString
:
'
'
,
isRegex
:
true
},
false
);
findController
.
moveToNextMatch
();
...
...
@@ -344,17 +344,17 @@ suite('FindController', () => {
});
});
test
(
'
issue #24714: Regular expression with ^ in search & replace
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #24714: Regular expression with ^ in search & replace
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
''
,
'
line2
'
,
'
line3
'
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
clipboardState
=
''
;
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
let
startFindAction
=
new
StartFindAction
();
startFindAction
.
run
(
null
,
editor
);
await
startFindAction
.
run
(
null
,
editor
);
findController
.
getState
().
change
({
searchString
:
'
^
'
,
replaceString
:
'
x
'
,
isRegex
:
true
},
false
);
findController
.
moveToNextMatch
();
...
...
@@ -371,12 +371,12 @@ suite('FindController', () => {
});
});
test
(
'
issue #38232: Find Next Selection, regex enabled
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #38232: Find Next Selection, regex enabled
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
([funny]
'
,
''
,
'
([funny]
'
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
clipboardState
=
''
;
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
let
nextSelectionMatchFindAction
=
new
NextSelectionMatchFindAction
();
...
...
@@ -388,7 +388,7 @@ suite('FindController', () => {
editor
.
setSelection
(
new
Selection
(
1
,
1
,
1
,
9
));
// cmd+f3
nextSelectionMatchFindAction
.
run
(
null
,
editor
);
await
nextSelectionMatchFindAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
editor
.
getSelections
()
!
.
map
(
fromSelection
),
[
[
3
,
1
,
3
,
9
]
...
...
@@ -398,19 +398,19 @@ suite('FindController', () => {
});
});
test
(
'
issue #38232: Find Next Selection, regex enabled, find widget open
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #38232: Find Next Selection, regex enabled, find widget open
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
([funny]
'
,
''
,
'
([funny]
'
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
clipboardState
=
''
;
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
let
startFindAction
=
new
StartFindAction
();
let
nextSelectionMatchFindAction
=
new
NextSelectionMatchFindAction
();
// cmd+f - open find widget
startFindAction
.
run
(
null
,
editor
);
await
startFindAction
.
run
(
null
,
editor
);
// toggle regex
findController
.
getState
().
change
({
isRegex
:
true
},
false
);
...
...
@@ -419,7 +419,7 @@ suite('FindController', () => {
editor
.
setSelection
(
new
Selection
(
1
,
1
,
1
,
9
));
// cmd+f3
nextSelectionMatchFindAction
.
run
(
null
,
editor
);
await
nextSelectionMatchFindAction
.
run
(
null
,
editor
);
assert
.
deepEqual
(
editor
.
getSelections
()
!
.
map
(
fromSelection
),
[
[
3
,
1
,
3
,
9
]
...
...
@@ -430,7 +430,7 @@ suite('FindController', () => {
});
});
suite
(
'
FindController query options persistence
'
,
()
=>
{
suite
(
'
FindController query options persistence
'
,
async
()
=>
{
let
queryState
:
{
[
key
:
string
]:
any
;
}
=
{};
queryState
[
'
editor.isRegex
'
]
=
false
;
queryState
[
'
editor.matchCase
'
]
=
false
;
...
...
@@ -447,13 +447,13 @@ suite('FindController query options persistence', () => {
remove
:
()
=>
undefined
}
as
any
);
test
(
'
matchCase
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
matchCase
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
abc
'
,
'
ABC
'
,
'
XYZ
'
,
'
ABC
'
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
queryState
=
{
'
editor.isRegex
'
:
false
,
'
editor.matchCase
'
:
true
,
'
editor.wholeWord
'
:
false
};
// The cursor is at the very top, of the file, at the first ABC
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
...
...
@@ -461,7 +461,7 @@ suite('FindController query options persistence', () => {
let
startFindAction
=
new
StartFindAction
();
// I hit Ctrl+F to show the Find dialog
startFindAction
.
run
(
null
,
editor
);
await
startFindAction
.
run
(
null
,
editor
);
// I type ABC.
findState
.
change
({
searchString
:
'
ABC
'
},
true
);
...
...
@@ -474,13 +474,13 @@ suite('FindController query options persistence', () => {
queryState
=
{
'
editor.isRegex
'
:
false
,
'
editor.matchCase
'
:
false
,
'
editor.wholeWord
'
:
true
};
test
(
'
wholeWord
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
wholeWord
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
ABC
'
,
'
AB
'
,
'
XYZ
'
,
'
ABC
'
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
queryState
=
{
'
editor.isRegex
'
:
false
,
'
editor.matchCase
'
:
false
,
'
editor.wholeWord
'
:
true
};
// The cursor is at the very top, of the file, at the first ABC
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
...
...
@@ -488,7 +488,7 @@ suite('FindController query options persistence', () => {
let
startFindAction
=
new
StartFindAction
();
// I hit Ctrl+F to show the Find dialog
startFindAction
.
run
(
null
,
editor
);
await
startFindAction
.
run
(
null
,
editor
);
// I type AB.
findState
.
change
({
searchString
:
'
AB
'
},
true
);
...
...
@@ -499,13 +499,13 @@ suite('FindController query options persistence', () => {
});
});
test
(
'
toggling options is saved
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
toggling options is saved
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
ABC
'
,
'
AB
'
,
'
XYZ
'
,
'
ABC
'
],
{
serviceCollection
:
serviceCollection
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
},
async
(
editor
)
=>
{
queryState
=
{
'
editor.isRegex
'
:
false
,
'
editor.matchCase
'
:
false
,
'
editor.wholeWord
'
:
true
};
// The cursor is at the very top, of the file, at the first ABC
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
...
...
@@ -516,17 +516,17 @@ suite('FindController query options persistence', () => {
});
});
test
(
'
issue #27083: Update search scope once find widget becomes visible
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #27083: Update search scope once find widget becomes visible
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
var x = (3 * 5)
'
,
'
var y = (3 * 5)
'
,
'
var z = (3 * 5)
'
,
],
{
serviceCollection
:
serviceCollection
,
find
:
{
autoFindInSelection
:
'
always
'
,
globalFindClipboard
:
false
}
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
,
find
:
{
autoFindInSelection
:
'
always
'
,
globalFindClipboard
:
false
}
},
async
(
editor
)
=>
{
// clipboardState = '';
editor
.
setSelection
(
new
Range
(
1
,
1
,
2
,
1
));
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
findController
.
start
({
await
findController
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
false
,
seedSearchStringFromGlobalClipboard
:
false
,
...
...
@@ -540,17 +540,17 @@ suite('FindController query options persistence', () => {
});
});
test
(
'
issue #58604: Do not update searchScope if it is empty
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #58604: Do not update searchScope if it is empty
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
var x = (3 * 5)
'
,
'
var y = (3 * 5)
'
,
'
var z = (3 * 5)
'
,
],
{
serviceCollection
:
serviceCollection
,
find
:
{
autoFindInSelection
:
'
always
'
,
globalFindClipboard
:
false
}
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
,
find
:
{
autoFindInSelection
:
'
always
'
,
globalFindClipboard
:
false
}
},
async
(
editor
)
=>
{
// clipboardState = '';
editor
.
setSelection
(
new
Range
(
1
,
2
,
1
,
2
));
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
findController
.
start
({
await
findController
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
false
,
seedSearchStringFromGlobalClipboard
:
false
,
...
...
@@ -564,17 +564,17 @@ suite('FindController query options persistence', () => {
});
});
test
(
'
issue #58604: Update searchScope if it is not empty
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #58604: Update searchScope if it is not empty
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
var x = (3 * 5)
'
,
'
var y = (3 * 5)
'
,
'
var z = (3 * 5)
'
,
],
{
serviceCollection
:
serviceCollection
,
find
:
{
autoFindInSelection
:
'
always
'
,
globalFindClipboard
:
false
}
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
,
find
:
{
autoFindInSelection
:
'
always
'
,
globalFindClipboard
:
false
}
},
async
(
editor
)
=>
{
// clipboardState = '';
editor
.
setSelection
(
new
Range
(
1
,
2
,
1
,
3
));
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
findController
.
start
({
await
findController
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
false
,
seedSearchStringFromGlobalClipboard
:
false
,
...
...
@@ -589,17 +589,17 @@ suite('FindController query options persistence', () => {
});
test
(
'
issue #27083: Find in selection when multiple lines are selected
'
,
()
=>
{
with
TestCodeEditor
([
test
(
'
issue #27083: Find in selection when multiple lines are selected
'
,
async
()
=>
{
await
withAsync
TestCodeEditor
([
'
var x = (3 * 5)
'
,
'
var y = (3 * 5)
'
,
'
var z = (3 * 5)
'
,
],
{
serviceCollection
:
serviceCollection
,
find
:
{
autoFindInSelection
:
'
multiline
'
,
globalFindClipboard
:
false
}
},
(
editor
)
=>
{
],
{
serviceCollection
:
serviceCollection
,
find
:
{
autoFindInSelection
:
'
multiline
'
,
globalFindClipboard
:
false
}
},
async
(
editor
)
=>
{
// clipboardState = '';
editor
.
setSelection
(
new
Range
(
1
,
6
,
2
,
1
));
let
findController
=
editor
.
registerAndInstantiateContribution
(
TestFindController
.
ID
,
TestFindController
);
findController
.
start
({
await
findController
.
start
({
forceRevealReplace
:
false
,
seedSearchStringFromSelection
:
false
,
seedSearchStringFromGlobalClipboard
:
false
,
...
...
src/vs/editor/test/browser/testCodeEditor.ts
浏览文件 @
9413602d
...
...
@@ -96,6 +96,24 @@ export function withTestCodeEditor(text: string | string[] | null, options: Test
editor
.
dispose
();
}
export
async
function
withAsyncTestCodeEditor
(
text
:
string
|
string
[]
|
null
,
options
:
TestCodeEditorCreationOptions
,
callback
:
(
editor
:
ITestCodeEditor
,
viewModel
:
ViewModel
)
=>
Promise
<
void
>
):
Promise
<
void
>
{
// create a model if necessary and remember it in order to dispose it.
if
(
!
options
.
model
)
{
if
(
typeof
text
===
'
string
'
)
{
options
.
model
=
createTextModel
(
text
);
}
else
if
(
text
)
{
options
.
model
=
createTextModel
(
text
.
join
(
'
\n
'
));
}
}
const
editor
=
createTestCodeEditor
(
options
);
const
viewModel
=
editor
.
getViewModel
()
!
;
viewModel
.
setHasFocus
(
true
);
await
callback
(
<
ITestCodeEditor
>
editor
,
editor
.
getViewModel
()
!
);
editor
.
dispose
();
}
export
function
createTestCodeEditor
(
options
:
TestCodeEditorCreationOptions
):
ITestCodeEditor
{
const
model
=
options
.
model
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录