Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
29a859d4
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,发现更多精彩内容 >>
提交
29a859d4
编写于
3月 08, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add faster path for a large replaceAll (#21434)
上级
7958bede
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
43 addition
and
7 deletion
+43
-7
src/vs/editor/contrib/find/common/findModel.ts
src/vs/editor/contrib/find/common/findModel.ts
+43
-7
未找到文件。
src/vs/editor/contrib/find/common/findModel.ts
浏览文件 @
29a859d4
...
...
@@ -7,7 +7,7 @@
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
ReplacePattern
,
parseReplaceString
}
from
'
vs/editor/contrib/find/common/replacePattern
'
;
import
{
ReplaceCommand
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
ReplaceCommand
,
ReplaceCommandThatPreservesSelection
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
...
...
@@ -18,6 +18,7 @@ import { Selection } from 'vs/editor/common/core/selection';
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
IKeybindings
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
Constants
}
from
'
vs/editor/common/core/uint
'
;
import
{
SearchParams
}
from
'
vs/editor/common/model/textModelSearch
'
;
export
const
ToggleCaseSensitiveKeybinding
:
IKeybindings
=
{
primary
:
KeyMod
.
Alt
|
KeyCode
.
KEY_C
,
...
...
@@ -223,7 +224,7 @@ export class FindModelBoundToEditorModel {
before
=
searchRange
.
getEndPosition
();
}
let
{
lineNumber
,
column
}
=
before
;
let
{
lineNumber
,
column
}
=
before
;
let
model
=
this
.
_editor
.
getModel
();
let
position
=
new
Position
(
lineNumber
,
column
);
...
...
@@ -294,7 +295,7 @@ export class FindModelBoundToEditorModel {
after
=
searchRange
.
getStartPosition
();
}
let
{
lineNumber
,
column
}
=
after
;
let
{
lineNumber
,
column
}
=
after
;
let
model
=
this
.
_editor
.
getModel
();
let
position
=
new
Position
(
lineNumber
,
column
);
...
...
@@ -383,8 +384,45 @@ export class FindModelBoundToEditorModel {
return
;
}
let
findScope
=
this
.
_decorations
.
getFindScope
();
let
replacePattern
=
this
.
_getReplacePattern
();
const
findScope
=
this
.
_decorations
.
getFindScope
();
if
(
findScope
===
null
&&
this
.
_state
.
matchesCount
>=
MATCHES_LIMIT
)
{
// Doing a replace on the entire file that is over 1k matches
this
.
_largeReplaceAll
();
}
else
{
this
.
_regularReplaceAll
(
findScope
);
}
this
.
research
(
false
);
}
private
_largeReplaceAll
():
void
{
const
searchParams
=
new
SearchParams
(
this
.
_state
.
searchString
,
this
.
_state
.
isRegex
,
this
.
_state
.
matchCase
,
this
.
_state
.
wholeWord
);
const
searchData
=
searchParams
.
parseSearchRequest
();
if
(
!
searchData
)
{
return
;
}
const
model
=
this
.
_editor
.
getModel
();
const
modelText
=
model
.
getValue
(
editorCommon
.
EndOfLinePreference
.
LF
);
const
fullModelRange
=
model
.
getFullModelRange
();
const
replacePattern
=
this
.
_getReplacePattern
();
let
resultText
:
string
;
if
(
replacePattern
.
hasReplacementPatterns
)
{
resultText
=
modelText
.
replace
(
searchData
.
regex
,
function
()
{
return
replacePattern
.
buildReplaceString
(
<
string
[]
><
any
>
arguments
);
});
}
else
{
resultText
=
modelText
.
replace
(
searchData
.
regex
,
replacePattern
.
buildReplaceString
(
null
));
}
let
command
=
new
ReplaceCommandThatPreservesSelection
(
fullModelRange
,
resultText
,
this
.
_editor
.
getSelection
());
this
.
_executeEditorCommand
(
'
replaceAll
'
,
command
);
}
private
_regularReplaceAll
(
findScope
:
Range
):
void
{
const
replacePattern
=
this
.
_getReplacePattern
();
// Get all the ranges (even more than the highlighted ones)
let
matches
=
this
.
_findMatches
(
findScope
,
replacePattern
.
hasReplacementPatterns
,
Constants
.
MAX_SAFE_SMALL_INTEGER
);
...
...
@@ -395,8 +433,6 @@ export class FindModelBoundToEditorModel {
let
command
=
new
ReplaceAllCommand
(
this
.
_editor
.
getSelection
(),
matches
.
map
(
m
=>
m
.
range
),
replaceStrings
);
this
.
_executeEditorCommand
(
'
replaceAll
'
,
command
);
this
.
research
(
false
);
}
public
selectAllMatches
():
void
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录