Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
03a0c93a
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
03a0c93a
编写于
4月 30, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve breaking behaviour when using WrappingIndent
上级
6cf0724b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
47 deletion
+35
-47
src/vs/editor/common/viewModel/characterHardWrappingLineMapper.ts
...ditor/common/viewModel/characterHardWrappingLineMapper.ts
+9
-8
src/vs/editor/test/common/viewModel/characterHardWrappingLineMapper.test.ts
.../common/viewModel/characterHardWrappingLineMapper.test.ts
+26
-39
未找到文件。
src/vs/editor/common/viewModel/characterHardWrappingLineMapper.ts
浏览文件 @
03a0c93a
...
...
@@ -118,8 +118,9 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
let
wrappedTextIndent
=
''
;
const
TAB_CHAR_CODE
=
'
\t
'
.
charCodeAt
(
0
);
let
firstNonWhitespaceIndex
=
-
1
;
if
(
hardWrappingIndent
!==
WrappingIndent
.
None
)
{
let
firstNonWhitespaceIndex
=
strings
.
firstNonWhitespaceIndex
(
lineText
);
firstNonWhitespaceIndex
=
strings
.
firstNonWhitespaceIndex
(
lineText
);
if
(
firstNonWhitespaceIndex
!==
-
1
)
{
wrappedTextIndent
=
lineText
.
substring
(
0
,
firstNonWhitespaceIndex
);
for
(
let
i
=
0
;
i
<
firstNonWhitespaceIndex
;
i
++
)
{
...
...
@@ -194,19 +195,19 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
// We will break before `niceBreakLastOffset`
breakBeforeOffset
=
niceBreakOffset
;
restoreVisibleColumnFrom
=
niceBreakVisibleColumn
+
wrappedTextIndentVisibleColumn
;
restoreVisibleColumnFrom
=
niceBreakVisibleColumn
;
}
else
if
(
obtrusiveBreakOffset
!==
-
1
)
{
// We will break before `obtrusiveBreakLastOffset`
breakBeforeOffset
=
obtrusiveBreakOffset
;
restoreVisibleColumnFrom
=
obtrusiveBreakVisibleColumn
+
wrappedTextIndentVisibleColumn
;
restoreVisibleColumnFrom
=
obtrusiveBreakVisibleColumn
;
}
else
{
// We will break before `i`
breakBeforeOffset
=
i
;
restoreVisibleColumnFrom
=
0
+
wrappedTextIndentVisibleColumn
;
restoreVisibleColumnFrom
=
wrappedTextIndentVisibleColumn
;
}
...
...
@@ -235,10 +236,10 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
obtrusiveBreakVisibleColumn
=
CharacterHardWrappingLineMapperFactory
.
nextVisibleColumn
(
obtrusiveBreakVisibleColumn
,
tabSize
,
charCodeIsTab
,
charColumnSize
);
}
if
(
charCodeClass
===
CharacterClass
.
BREAK_AFTER
)
{
if
(
charCodeClass
===
CharacterClass
.
BREAK_AFTER
&&
(
hardWrappingIndent
===
WrappingIndent
.
None
||
i
>=
firstNonWhitespaceIndex
)
)
{
// This is a character that indicates that a break should happen after it
niceBreakOffset
=
i
+
1
;
niceBreakVisibleColumn
=
0
;
niceBreakVisibleColumn
=
wrappedTextIndentVisibleColumn
;
}
// CJK breaking : after break
...
...
@@ -247,14 +248,14 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
let
nextClass
=
classifier
.
classify
(
nextCode
);
if
(
nextClass
!==
CharacterClass
.
BREAK_AFTER
)
{
// Kinsoku Shori: Don't break before a trailing character, like a period
niceBreakOffset
=
i
+
1
;
niceBreakVisibleColumn
=
0
;
niceBreakVisibleColumn
=
wrappedTextIndentVisibleColumn
;
}
}
if
(
charCodeClass
===
CharacterClass
.
BREAK_OBTRUSIVE
)
{
// This is an obtrusive character that indicates that a break should happen after it
obtrusiveBreakOffset
=
i
+
1
;
obtrusiveBreakVisibleColumn
=
0
;
obtrusiveBreakVisibleColumn
=
wrappedTextIndentVisibleColumn
;
}
}
...
...
src/vs/editor/test/common/viewModel/characterHardWrappingLineMapper.test.ts
浏览文件 @
03a0c93a
...
...
@@ -9,39 +9,7 @@ import {WrappingIndent} from 'vs/editor/common/editorCommon';
import
{
CharacterHardWrappingLineMapperFactory
}
from
'
vs/editor/common/viewModel/characterHardWrappingLineMapper
'
;
import
{
ILineMapperFactory
,
ILineMapping
,
OutputPosition
}
from
'
vs/editor/common/viewModel/splitLinesCollection
'
;
function
safeGetOutputLineCount
(
mapper
:
ILineMapping
):
number
{
if
(
!
mapper
)
{
return
1
;
}
return
mapper
.
getOutputLineCount
();
}
function
safeGetOutputPositionOfInputOffset
(
mapper
:
ILineMapping
,
inputOffset
:
number
):
OutputPosition
{
if
(
!
mapper
)
{
return
new
OutputPosition
(
0
,
inputOffset
);
}
return
mapper
.
getOutputPositionOfInputOffset
(
inputOffset
);
}
function
safeGetInputOffsetOfOutputPosition
(
mapper
:
ILineMapping
,
outputLineIndex
:
number
,
outputOffset
:
number
):
number
{
if
(
!
mapper
)
{
return
outputOffset
;
}
return
mapper
.
getInputOffsetOfOutputPosition
(
outputLineIndex
,
outputOffset
);
}
function
assertMappingIdentity
(
mapper
:
ILineMapping
,
offset
:
number
,
expectedLineIndex
:
number
)
{
let
result
=
safeGetOutputPositionOfInputOffset
(
mapper
,
offset
);
assert
.
ok
(
result
.
outputLineIndex
!==
-
1
);
assert
.
ok
(
result
.
outputOffset
!==
-
1
);
assert
.
equal
(
result
.
outputLineIndex
,
expectedLineIndex
);
let
actualOffset
=
safeGetInputOffsetOfOutputPosition
(
mapper
,
result
.
outputLineIndex
,
result
.
outputOffset
);
assert
.
equal
(
actualOffset
,
offset
);
}
function
assertLineMapping
(
factory
:
ILineMapperFactory
,
tabSize
:
number
,
breakAfter
:
number
,
annotatedText
:
string
)
{
function
assertLineMapping
(
factory
:
ILineMapperFactory
,
tabSize
:
number
,
breakAfter
:
number
,
annotatedText
:
string
,
wrappingIndent
=
WrappingIndent
.
None
)
{
let
rawText
=
''
;
let
currentLineIndex
=
0
;
...
...
@@ -55,12 +23,25 @@ function assertLineMapping(factory:ILineMapperFactory, tabSize:number, breakAfte
}
}
var
mapper
=
factory
.
createLineMapping
(
rawText
,
tabSize
,
breakAfter
,
2
,
WrappingIndent
.
None
);
assert
.
equal
(
safeGetOutputLineCount
(
mapper
),
(
lineIndices
.
length
>
0
?
lineIndices
[
lineIndices
.
length
-
1
]
+
1
:
1
));
for
(
let
i
=
0
,
len
=
rawText
.
length
;
i
<
len
;
i
++
)
{
assertMappingIdentity
(
mapper
,
i
,
lineIndices
[
i
]);
let
mapper
=
factory
.
createLineMapping
(
rawText
,
tabSize
,
breakAfter
,
2
,
wrappingIndent
);
let
actualAnnotatedText
=
''
;
if
(
mapper
)
{
let
previousLineIndex
=
0
;
for
(
let
i
=
0
,
len
=
rawText
.
length
;
i
<
len
;
i
++
)
{
let
r
=
mapper
.
getOutputPositionOfInputOffset
(
i
);
if
(
previousLineIndex
!==
r
.
outputLineIndex
)
{
previousLineIndex
=
r
.
outputLineIndex
;
actualAnnotatedText
+=
'
|
'
;
}
actualAnnotatedText
+=
rawText
.
charAt
(
i
);
}
}
else
{
// No wrapping
actualAnnotatedText
=
rawText
;
}
assert
.
equal
(
actualAnnotatedText
,
annotatedText
);
}
suite
(
'
Editor ViewModel - CharacterHardWrappingLineMapper
'
,
()
=>
{
...
...
@@ -105,8 +86,9 @@ suite('Editor ViewModel - CharacterHardWrappingLineMapper', () => {
assertLineMapping
(
factory
,
4
,
5
,
'
aa.(|()|.aaa
'
);
assertLineMapping
(
factory
,
4
,
5
,
'
aa.|(.)|.aaa
'
);
});
test
(
'
CharacterHardWrappingLineMapper - CJK and Kinsoku Shori
'
,
()
=>
{
var
factory
=
new
CharacterHardWrappingLineMapperFactory
(
'
(
'
,
'
)
'
,
'
.
'
);
let
factory
=
new
CharacterHardWrappingLineMapperFactory
(
'
(
'
,
'
)
'
,
'
.
'
);
assertLineMapping
(
factory
,
4
,
5
,
'
aa
\
u5b89|
\
u5b89
'
);
assertLineMapping
(
factory
,
4
,
5
,
'
\
u3042
\
u5b89|
\
u5b89
'
);
assertLineMapping
(
factory
,
4
,
5
,
'
\
u3042
\
u3042|
\
u5b89
\
u5b89
'
);
...
...
@@ -114,4 +96,9 @@ suite('Editor ViewModel - CharacterHardWrappingLineMapper', () => {
assertLineMapping
(
factory
,
4
,
5
,
'
aa
\
u3042|
\
u5b89
\
u3042)|
\
u5b89
'
);
assertLineMapping
(
factory
,
4
,
5
,
'
aa |(
\
u5b89aa|
\
u5b89
'
);
});
test
(
'
CharacterHardWrappingLineMapper - WrappingIndent.Same
'
,
()
=>
{
let
factory
=
new
CharacterHardWrappingLineMapperFactory
(
''
,
'
'
,
''
);
assertLineMapping
(
factory
,
4
,
38
,
'
*123456789012345678901234567890123456|7890
'
,
WrappingIndent
.
Same
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录