Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
47b7ef5d
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,发现更多精彩内容 >>
提交
47b7ef5d
编写于
11月 23, 2015
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #312
上级
203f945e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
121 addition
and
7 deletion
+121
-7
src/vs/editor/contrib/find/browser/find.ts
src/vs/editor/contrib/find/browser/find.ts
+1
-1
src/vs/editor/contrib/find/browser/findWidget.ts
src/vs/editor/contrib/find/browser/findWidget.ts
+1
-1
src/vs/editor/contrib/find/common/findModel.ts
src/vs/editor/contrib/find/common/findModel.ts
+71
-5
src/vs/editor/contrib/find/common/replaceAllCommand.ts
src/vs/editor/contrib/find/common/replaceAllCommand.ts
+0
-0
src/vs/editor/contrib/find/test/common/findModel.test.ts
src/vs/editor/contrib/find/test/common/findModel.test.ts
+48
-0
未找到文件。
src/vs/editor/contrib/find/browser/find.ts
浏览文件 @
47b7ef5d
...
...
@@ -9,7 +9,7 @@ import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
import
{
CommonEditorRegistry
,
ContextKey
,
EditorActionDescriptor
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
EditorAction
,
Behaviour
}
from
'
vs/editor/common/editorAction
'
;
import
FindWidget
=
require
(
'
./findWidget
'
);
import
FindModel
=
require
(
'
.
/findModel
'
);
import
FindModel
=
require
(
'
vs/editor/contrib/find/common
/findModel
'
);
import
nls
=
require
(
'
vs/nls
'
);
import
EventEmitter
=
require
(
'
vs/base/common/eventEmitter
'
);
import
EditorBrowser
=
require
(
'
vs/editor/browser/editorBrowser
'
);
...
...
src/vs/editor/contrib/find/browser/findWidget.ts
浏览文件 @
47b7ef5d
...
...
@@ -16,7 +16,7 @@ import InputBox = require('vs/base/browser/ui/inputbox/inputBox');
import
Findinput
=
require
(
'
vs/base/browser/ui/findinput/findInput
'
);
import
EditorBrowser
=
require
(
'
vs/editor/browser/editorBrowser
'
);
import
EditorCommon
=
require
(
'
vs/editor/common/editorCommon
'
);
import
FindModel
=
require
(
'
.
/findModel
'
);
import
FindModel
=
require
(
'
vs/editor/contrib/find/common
/findModel
'
);
import
Lifecycle
=
require
(
'
vs/base/common/lifecycle
'
);
import
{
CommonKeybindings
}
from
'
vs/base/common/keyCodes
'
;
...
...
src/vs/editor/contrib/find/
browser
/findModel.ts
→
src/vs/editor/contrib/find/
common
/findModel.ts
浏览文件 @
47b7ef5d
...
...
@@ -214,7 +214,7 @@ export class FindModelBoundToEditorModel extends Events.EventEmitter implements
this
.
findScopeDecorationId
=
decorations
[
0
];
}
this
.
addMatchesDecorations
(
changeAccessor
,
this
.
editor
.
getModel
().
findMatches
(
this
.
searchString
,
this
.
_getSearchRange
(),
this
.
isRegex
,
this
.
matchCase
,
this
.
wholeWord
));
this
.
addMatchesDecorations
(
changeAccessor
,
this
.
_findMatches
(
));
});
this
.
highlightedDecorationId
=
null
;
...
...
@@ -326,7 +326,6 @@ export class FindModelBoundToEditorModel extends Events.EventEmitter implements
}
}
private
setSelectionToDecoration
(
decorationId
:
string
):
void
{
this
.
editor
.
changeDecorations
((
changeAccessor
:
EditorCommon
.
IModelDecorationsChangeAccessor
)
=>
{
if
(
this
.
highlightedDecorationId
!==
null
)
{
...
...
@@ -346,8 +345,10 @@ export class FindModelBoundToEditorModel extends Events.EventEmitter implements
if
(
!
this
.
isRegex
)
{
return
this
.
replaceString
;
}
var
regexp
=
Strings
.
createRegExp
(
this
.
searchString
,
this
.
isRegex
,
this
.
matchCase
,
this
.
wholeWord
);
return
matchedString
.
replace
(
regexp
,
this
.
replaceString
);
let
regexp
=
Strings
.
createRegExp
(
this
.
searchString
,
this
.
isRegex
,
this
.
matchCase
,
this
.
wholeWord
);
// Parse the replace string to support that \t or \n mean the right thing
let
parsedReplaceString
=
parseReplaceString
(
this
.
replaceString
);
return
matchedString
.
replace
(
regexp
,
parsedReplaceString
);
}
public
replace
():
void
{
...
...
@@ -379,6 +380,10 @@ export class FindModelBoundToEditorModel extends Events.EventEmitter implements
}
}
private
_findMatches
(
limitResultCount
?:
number
):
EditorCommon
.
IEditorRange
[]
{
return
this
.
editor
.
getModel
().
findMatches
(
this
.
searchString
,
this
.
_getSearchRange
(),
this
.
isRegex
,
this
.
matchCase
,
this
.
wholeWord
,
limitResultCount
);
}
public
replaceAll
():
void
{
if
(
this
.
decorations
.
length
===
0
)
{
return
;
...
...
@@ -387,7 +392,7 @@ export class FindModelBoundToEditorModel extends Events.EventEmitter implements
let
model
=
this
.
editor
.
getModel
();
// Get all the ranges (even more than the highlighted ones)
let
ranges
=
this
.
editor
.
getModel
().
findMatches
(
this
.
searchString
,
this
.
_getSearchRange
(),
this
.
isRegex
,
this
.
matchCase
,
this
.
wholeWord
,
Number
.
MAX_VALUE
);
let
ranges
=
this
.
_findMatches
(
Number
.
MAX_VALUE
);
// Remove all decorations
this
.
editor
.
changeDecorations
((
changeAccessor
:
EditorCommon
.
IModelDecorationsChangeAccessor
)
=>
{
...
...
@@ -474,3 +479,64 @@ export class FindModelBoundToEditorModel extends Events.EventEmitter implements
}
const
BACKSLASH_CHAR_CODE
=
'
\\
'
.
charCodeAt
(
0
);
const
n_CHAR_CODE
=
'
n
'
.
charCodeAt
(
0
);
const
t_CHAR_CODE
=
'
t
'
.
charCodeAt
(
0
);
/**
* \n => LF
* \t => TAB
* \\ => \
* everything else stays untouched
*/
export
function
parseReplaceString
(
input
:
string
):
string
{
if
(
!
input
||
input
.
length
===
0
)
{
return
input
;
}
let
substrFrom
=
0
,
result
=
''
;
for
(
let
i
=
0
,
len
=
input
.
length
;
i
<
len
;
i
++
)
{
let
chCode
=
input
.
charCodeAt
(
i
);
if
(
chCode
===
BACKSLASH_CHAR_CODE
)
{
// move to next char
i
++
;
if
(
i
>=
len
)
{
// string ends with a \
break
;
}
let
nextChCode
=
input
.
charCodeAt
(
i
);
let
replaceWithCharacter
:
string
=
null
;
switch
(
nextChCode
)
{
case
BACKSLASH_CHAR_CODE
:
// \\ => \
replaceWithCharacter
=
'
\\
'
;
break
;
case
n_CHAR_CODE
:
// \n => LF
replaceWithCharacter
=
'
\n
'
;
break
;
case
t_CHAR_CODE
:
// \t => TAB
replaceWithCharacter
=
'
\t
'
;
break
;
}
if
(
replaceWithCharacter
)
{
result
+=
input
.
substring
(
substrFrom
,
i
-
1
)
+
replaceWithCharacter
;
substrFrom
=
i
+
1
;
}
}
}
if
(
substrFrom
===
0
)
{
// no replacement occured
return
input
;
}
return
result
+
input
.
substring
(
substrFrom
);
}
src/vs/editor/contrib/find/
browser
/replaceAllCommand.ts
→
src/vs/editor/contrib/find/
common
/replaceAllCommand.ts
浏览文件 @
47b7ef5d
文件已移动
src/vs/editor/contrib/find/test/common/findModel.test.ts
0 → 100644
浏览文件 @
47b7ef5d
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
assert
=
require
(
'
assert
'
);
import
{
FindModelBoundToEditorModel
,
parseReplaceString
}
from
'
vs/editor/contrib/find/common/findModel
'
;
suite
(
'
FindModel
'
,
()
=>
{
test
(
'
parseFindWidgetString
'
,
()
=>
{
let
testParse
=
(
input
:
string
,
expected
:
string
)
=>
{
let
actual
=
parseReplaceString
(
input
);
assert
.
equal
(
actual
,
expected
);
let
actual2
=
parseReplaceString
(
'
hello
'
+
input
+
'
hi
'
);
assert
.
equal
(
actual2
,
'
hello
'
+
expected
+
'
hi
'
);
};
// no backslash => no treatment
testParse
(
'
hello
'
,
'
hello
'
);
// \t => TAB
testParse
(
'
\\
thello
'
,
'
\t
hello
'
);
// \n => LF
testParse
(
'
\\
nhello
'
,
'
\n
hello
'
);
// \\t => \t
testParse
(
'
\\\\
thello
'
,
'
\\
thello
'
);
// \\\t => \TAB
testParse
(
'
\\\\\\
thello
'
,
'
\\\t
hello
'
);
// \\\\t => \\t
testParse
(
'
\\\\\\\\
thello
'
,
'
\\\\
thello
'
);
// \ at the end => no treatment
testParse
(
'
hello
\\
'
,
'
hello
\\
'
);
// \ with unknown char => no treatment
testParse
(
'
hello
\\
x
'
,
'
hello
\\
x
'
);
// \ with back reference => no treatment
testParse
(
'
hello
\\
0
'
,
'
hello
\\
0
'
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录