Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4e196ffb
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,发现更多精彩内容 >>
提交
4e196ffb
编写于
1月 24, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #19225: Have \n match EOL sequence regardless of model's EOL sequence
上级
5c31cac0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
102 addition
and
21 deletion
+102
-21
src/vs/editor/common/model/textModelSearch.ts
src/vs/editor/common/model/textModelSearch.ts
+50
-13
src/vs/editor/test/common/model/textModelSearch.test.ts
src/vs/editor/test/common/model/textModelSearch.test.ts
+52
-8
未找到文件。
src/vs/editor/common/model/textModelSearch.ts
浏览文件 @
4e196ffb
...
...
@@ -7,7 +7,7 @@
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
FindMatch
}
from
'
vs/editor/common/editorCommon
'
;
import
{
FindMatch
,
EndOfLinePreference
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
...
...
@@ -112,9 +112,50 @@ export class TextModelSearch {
return
this
.
_doFindMatchesLineByLine
(
model
,
searchRange
,
regex
,
captureMatches
,
limitResultCount
);
}
/**
* Multiline search always executes on the lines concatenated with \n.
* We must therefore compensate for the count of \n in case the model is CRLF
*/
private
static
_getMultilineMatchRange
(
model
:
TextModel
,
deltaOffset
:
number
,
text
:
string
,
matchIndex
:
number
,
match0
:
string
):
Range
{
let
startOffset
:
number
;
if
(
model
.
getEOL
()
===
'
\r\n
'
)
{
let
lineFeedCountBeforeMatch
=
0
;
for
(
let
i
=
0
;
i
<
matchIndex
;
i
++
)
{
let
chCode
=
text
.
charCodeAt
(
i
);
if
(
chCode
===
CharCode
.
LineFeed
)
{
lineFeedCountBeforeMatch
++
;
}
}
startOffset
=
deltaOffset
+
matchIndex
+
lineFeedCountBeforeMatch
/* add as many \r as there were \n */
;
}
else
{
startOffset
=
deltaOffset
+
matchIndex
;
}
let
endOffset
:
number
;
if
(
model
.
getEOL
()
===
'
\r\n
'
)
{
let
lineFeedCountInMatch
=
0
;
for
(
let
i
=
0
,
len
=
match0
.
length
;
i
<
len
;
i
++
)
{
let
chCode
=
text
.
charCodeAt
(
i
+
matchIndex
);
if
(
chCode
===
CharCode
.
LineFeed
)
{
lineFeedCountInMatch
++
;
}
}
endOffset
=
startOffset
+
match0
.
length
+
lineFeedCountInMatch
/* add as many \r as there were \n */
;
}
else
{
endOffset
=
startOffset
+
match0
.
length
;
}
const
startPosition
=
model
.
getPositionAt
(
startOffset
);
const
endPosition
=
model
.
getPositionAt
(
endOffset
);
return
new
Range
(
startPosition
.
lineNumber
,
startPosition
.
column
,
endPosition
.
lineNumber
,
endPosition
.
column
);
}
private
static
_doFindMatchesMultiline
(
model
:
TextModel
,
searchRange
:
Range
,
searchRegex
:
RegExp
,
captureMatches
:
boolean
,
limitResultCount
:
number
):
FindMatch
[]
{
const
deltaOffset
=
model
.
getOffsetAt
(
searchRange
.
getStartPosition
());
const
text
=
model
.
getValueInRange
(
searchRange
);
// We always execute multiline search over the lines joined with \n
// This makes it that \n will match the EOL for both CRLF and LF models
// We compensate for offset errors in `_getMultilineMatchRange`
const
text
=
model
.
getValueInRange
(
searchRange
,
EndOfLinePreference
.
LF
);
const
result
:
FindMatch
[]
=
[];
let
prevStartOffset
=
0
;
...
...
@@ -131,11 +172,8 @@ export class TextModelSearch {
return
result
;
}
const
startPosition
=
model
.
getPositionAt
(
startOffset
);
const
endPosition
=
model
.
getPositionAt
(
endOffset
);
result
[
counter
++
]
=
createFindMatch
(
new
Range
(
startPosition
.
lineNumber
,
startPosition
.
column
,
endPosition
.
lineNumber
,
endPosition
.
column
),
this
.
_getMultilineMatchRange
(
model
,
deltaOffset
,
text
,
m
.
index
,
m
[
0
]
),
m
,
captureMatches
);
...
...
@@ -221,22 +259,21 @@ export class TextModelSearch {
const
searchTextStart
=
new
Position
(
searchStart
.
lineNumber
,
1
);
const
deltaOffset
=
model
.
getOffsetAt
(
searchTextStart
);
const
lineCount
=
model
.
getLineCount
();
const
text
=
model
.
getValueInRange
(
new
Range
(
searchTextStart
.
lineNumber
,
searchTextStart
.
column
,
lineCount
,
model
.
getLineMaxColumn
(
lineCount
)));
// We always execute multiline search over the lines joined with \n
// This makes it that \n will match the EOL for both CRLF and LF models
// We compensate for offset errors in `_getMultilineMatchRange`
const
text
=
model
.
getValueInRange
(
new
Range
(
searchTextStart
.
lineNumber
,
searchTextStart
.
column
,
lineCount
,
model
.
getLineMaxColumn
(
lineCount
)),
EndOfLinePreference
.
LF
);
searchRegex
.
lastIndex
=
searchStart
.
column
-
1
;
let
m
=
searchRegex
.
exec
(
text
);
if
(
m
)
{
const
startOffset
=
deltaOffset
+
m
.
index
;
const
endOffset
=
startOffset
+
m
[
0
].
length
;
const
startPosition
=
model
.
getPositionAt
(
startOffset
);
const
endPosition
=
model
.
getPositionAt
(
endOffset
);
return
createFindMatch
(
new
Range
(
startPosition
.
lineNumber
,
startPosition
.
column
,
endPosition
.
lineNumber
,
endPosition
.
column
),
this
.
_getMultilineMatchRange
(
model
,
deltaOffset
,
text
,
m
.
index
,
m
[
0
]
),
m
,
captureMatches
);
}
if
(
searchStart
.
lineNumber
!==
1
||
searchStart
.
column
!==
-
1
)
{
if
(
searchStart
.
lineNumber
!==
1
||
searchStart
.
column
!==
1
)
{
// Try again from the top
return
this
.
_doFindNextMatchMultiline
(
model
,
new
Position
(
1
,
1
),
searchRegex
,
captureMatches
);
}
...
...
src/vs/editor/test/common/model/textModelSearch.test.ts
浏览文件 @
4e196ffb
...
...
@@ -6,7 +6,7 @@
import
*
as
assert
from
'
assert
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
FindMatch
}
from
'
vs/editor/common/editorCommon
'
;
import
{
FindMatch
,
EndOfLineSequence
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
TextModelSearch
,
SearchParams
}
from
'
vs/editor/common/model/textModelSearch
'
;
...
...
@@ -18,13 +18,7 @@ suite('TextModelSearch', () => {
assert
.
deepEqual
(
actual
,
new
FindMatch
(
expectedRange
,
expectedMatches
));
}
function
assertFindMatches
(
text
:
string
,
searchString
:
string
,
isRegex
:
boolean
,
matchCase
:
boolean
,
wholeWord
:
boolean
,
_expected
:
[
number
,
number
,
number
,
number
][]):
void
{
let
expectedRanges
=
_expected
.
map
(
entry
=>
new
Range
(
entry
[
0
],
entry
[
1
],
entry
[
2
],
entry
[
3
]));
let
expectedMatches
=
expectedRanges
.
map
(
entry
=>
new
FindMatch
(
entry
,
null
));
let
model
=
new
TextModel
([],
TextModel
.
toRawText
(
text
,
TextModel
.
DEFAULT_CREATION_OPTIONS
));
let
searchParams
=
new
SearchParams
(
searchString
,
isRegex
,
matchCase
,
wholeWord
);
function
_assertFindMatches
(
model
:
TextModel
,
searchParams
:
SearchParams
,
expectedMatches
:
FindMatch
[]):
void
{
let
actual
=
TextModelSearch
.
findMatches
(
model
,
searchParams
,
model
.
getFullModelRange
(),
false
,
1000
);
assert
.
deepEqual
(
actual
,
expectedMatches
,
'
findMatches OK
'
);
...
...
@@ -47,8 +41,22 @@ suite('TextModelSearch', () => {
match
=
TextModelSearch
.
findPreviousMatch
(
model
,
searchParams
,
startPos
,
false
);
assert
.
deepEqual
(
match
,
expectedMatches
[
i
],
`findPrevMatch
${
startPos
}
`
);
}
}
function
assertFindMatches
(
text
:
string
,
searchString
:
string
,
isRegex
:
boolean
,
matchCase
:
boolean
,
wholeWord
:
boolean
,
_expected
:
[
number
,
number
,
number
,
number
][]):
void
{
let
expectedRanges
=
_expected
.
map
(
entry
=>
new
Range
(
entry
[
0
],
entry
[
1
],
entry
[
2
],
entry
[
3
]));
let
expectedMatches
=
expectedRanges
.
map
(
entry
=>
new
FindMatch
(
entry
,
null
));
let
searchParams
=
new
SearchParams
(
searchString
,
isRegex
,
matchCase
,
wholeWord
);
let
model
=
new
TextModel
([],
TextModel
.
toRawText
(
text
,
TextModel
.
DEFAULT_CREATION_OPTIONS
));
_assertFindMatches
(
model
,
searchParams
,
expectedMatches
);
model
.
dispose
();
let
model2
=
new
TextModel
([],
TextModel
.
toRawText
(
text
,
TextModel
.
DEFAULT_CREATION_OPTIONS
));
model2
.
setEOL
(
EndOfLineSequence
.
CRLF
);
_assertFindMatches
(
model2
,
searchParams
,
expectedMatches
);
model2
.
dispose
();
}
let
regularText
=
[
...
...
@@ -498,6 +506,42 @@ suite('TextModelSearch', () => {
model
.
dispose
();
});
test
(
'
\\
n matches
\\
r
\\
n
'
,
()
=>
{
let
model
=
new
TextModel
([],
TextModel
.
toRawText
(
'
a
\r\n
b
\r\n
c
\r\n
d
\r\n
e
\r\n
f
\r\n
g
\r\n
h
\r\n
i
'
,
TextModel
.
DEFAULT_CREATION_OPTIONS
));
assert
.
equal
(
model
.
getEOL
(),
'
\r\n
'
);
let
searchParams
=
new
SearchParams
(
'
h
\\
n
'
,
true
,
false
,
false
);
let
actual
=
TextModelSearch
.
findNextMatch
(
model
,
searchParams
,
new
Position
(
1
,
1
),
true
);
actual
=
TextModelSearch
.
findMatches
(
model
,
searchParams
,
model
.
getFullModelRange
(),
true
,
1000
)[
0
];
assertFindMatch
(
actual
,
new
Range
(
8
,
1
,
9
,
1
),
[
'
h
\n
'
]);
searchParams
=
new
SearchParams
(
'
g
\\
nh
\\
n
'
,
true
,
false
,
false
);
actual
=
TextModelSearch
.
findNextMatch
(
model
,
searchParams
,
new
Position
(
1
,
1
),
true
);
actual
=
TextModelSearch
.
findMatches
(
model
,
searchParams
,
model
.
getFullModelRange
(),
true
,
1000
)[
0
];
assertFindMatch
(
actual
,
new
Range
(
7
,
1
,
9
,
1
),
[
'
g
\n
h
\n
'
]);
searchParams
=
new
SearchParams
(
'
\\
ni
'
,
true
,
false
,
false
);
actual
=
TextModelSearch
.
findNextMatch
(
model
,
searchParams
,
new
Position
(
1
,
1
),
true
);
actual
=
TextModelSearch
.
findMatches
(
model
,
searchParams
,
model
.
getFullModelRange
(),
true
,
1000
)[
0
];
assertFindMatch
(
actual
,
new
Range
(
8
,
2
,
9
,
2
),
[
'
\n
i
'
]);
model
.
dispose
();
});
test
(
'
\\
r can never be found
'
,
()
=>
{
let
model
=
new
TextModel
([],
TextModel
.
toRawText
(
'
a
\r\n
b
\r\n
c
\r\n
d
\r\n
e
\r\n
f
\r\n
g
\r\n
h
\r\n
i
'
,
TextModel
.
DEFAULT_CREATION_OPTIONS
));
assert
.
equal
(
model
.
getEOL
(),
'
\r\n
'
);
let
searchParams
=
new
SearchParams
(
'
\\
r
\\
n
'
,
true
,
false
,
false
);
let
actual
=
TextModelSearch
.
findNextMatch
(
model
,
searchParams
,
new
Position
(
1
,
1
),
true
);
assert
.
equal
(
actual
,
null
);
assert
.
deepEqual
(
TextModelSearch
.
findMatches
(
model
,
searchParams
,
model
.
getFullModelRange
(),
true
,
1000
),
[]);
model
.
dispose
();
});
function
assertParseSearchResult
(
searchString
:
string
,
isRegex
:
boolean
,
matchCase
:
boolean
,
wholeWord
:
boolean
,
expected
:
RegExp
):
void
{
let
searchParams
=
new
SearchParams
(
searchString
,
isRegex
,
matchCase
,
wholeWord
);
let
actual
=
searchParams
.
parseSearchRequest
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录