Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
bf6776b9
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,发现更多精彩内容 >>
提交
bf6776b9
编写于
11月 12, 2020
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #87730.
上级
293af207
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
10 deletion
+48
-10
src/vs/editor/contrib/comment/comment.ts
src/vs/editor/contrib/comment/comment.ts
+25
-3
src/vs/editor/contrib/comment/lineCommentCommand.ts
src/vs/editor/contrib/comment/lineCommentCommand.ts
+21
-5
src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts
...vs/editor/contrib/comment/test/lineCommentCommand.test.ts
+2
-2
未找到文件。
src/vs/editor/contrib/comment/comment.ts
浏览文件 @
bf6776b9
...
...
@@ -7,6 +7,7 @@ import * as nls from 'vs/nls';
import
{
KeyChord
,
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
EditorAction
,
IActionOptions
,
ServicesAccessor
,
registerEditorAction
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ICommand
}
from
'
vs/editor/common/editorCommon
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
import
{
BlockCommentCommand
}
from
'
vs/editor/contrib/comment/blockCommentCommand
'
;
...
...
@@ -31,17 +32,38 @@ abstract class CommentLineAction extends EditorAction {
const
model
=
editor
.
getModel
();
const
commands
:
ICommand
[]
=
[];
const
selections
=
editor
.
getSelections
();
const
modelOptions
=
model
.
getOptions
();
const
commentsOptions
=
editor
.
getOption
(
EditorOption
.
comments
);
const
selections
=
editor
.
getSelections
().
map
((
selection
,
index
)
=>
({
selection
,
index
,
ignoreFirstLine
:
false
}));
selections
.
sort
((
a
,
b
)
=>
Range
.
compareRangesUsingStarts
(
a
.
selection
,
b
.
selection
));
// Remove selections that would result in copying the same line
let
prev
=
selections
[
0
];
for
(
let
i
=
1
;
i
<
selections
.
length
;
i
++
)
{
const
curr
=
selections
[
i
];
if
(
prev
.
selection
.
endLineNumber
===
curr
.
selection
.
startLineNumber
)
{
// these two selections would copy the same line
if
(
prev
.
index
<
curr
.
index
)
{
// prev wins
curr
.
ignoreFirstLine
=
true
;
}
else
{
// curr wins
prev
.
ignoreFirstLine
=
true
;
prev
=
curr
;
}
}
}
for
(
const
selection
of
selections
)
{
commands
.
push
(
new
LineCommentCommand
(
selection
,
selection
.
selection
,
modelOptions
.
tabSize
,
this
.
_type
,
commentsOptions
.
insertSpace
,
commentsOptions
.
ignoreEmptyLines
commentsOptions
.
ignoreEmptyLines
,
selection
.
ignoreFirstLine
));
}
...
...
src/vs/editor/contrib/comment/lineCommentCommand.ts
浏览文件 @
bf6776b9
...
...
@@ -57,13 +57,15 @@ export class LineCommentCommand implements ICommand {
private
_selectionId
:
string
|
null
;
private
_deltaColumn
:
number
;
private
_moveEndPositionDown
:
boolean
;
private
_ignoreFirstLine
:
boolean
;
constructor
(
selection
:
Selection
,
tabSize
:
number
,
type
:
Type
,
insertSpace
:
boolean
,
ignoreEmptyLines
:
boolean
ignoreEmptyLines
:
boolean
,
ignoreFirstLine
?:
boolean
)
{
this
.
_selection
=
selection
;
this
.
_tabSize
=
tabSize
;
...
...
@@ -73,6 +75,7 @@ export class LineCommentCommand implements ICommand {
this
.
_deltaColumn
=
0
;
this
.
_moveEndPositionDown
=
false
;
this
.
_ignoreEmptyLines
=
ignoreEmptyLines
;
this
.
_ignoreFirstLine
=
ignoreFirstLine
||
false
;
}
/**
...
...
@@ -108,7 +111,7 @@ export class LineCommentCommand implements ICommand {
* Analyze lines and decide which lines are relevant and what the toggle should do.
* Also, build up several offsets and lengths useful in the generation of editor operations.
*/
public
static
_analyzeLines
(
type
:
Type
,
insertSpace
:
boolean
,
model
:
ISimpleModel
,
lines
:
ILinePreflightData
[],
startLineNumber
:
number
,
ignoreEmptyLines
:
boolean
):
IPreflightData
{
public
static
_analyzeLines
(
type
:
Type
,
insertSpace
:
boolean
,
model
:
ISimpleModel
,
lines
:
ILinePreflightData
[],
startLineNumber
:
number
,
ignoreEmptyLines
:
boolean
,
ignoreFirstLine
:
boolean
):
IPreflightData
{
let
onlyWhitespaceLines
=
true
;
let
shouldRemoveComments
:
boolean
;
...
...
@@ -124,6 +127,12 @@ export class LineCommentCommand implements ICommand {
const
lineData
=
lines
[
i
];
const
lineNumber
=
startLineNumber
+
i
;
if
(
lineNumber
===
startLineNumber
&&
ignoreFirstLine
)
{
// first line ignored
lineData
.
ignore
=
true
;
continue
;
}
const
lineContent
=
model
.
getLineContent
(
lineNumber
);
const
lineContentStartOffset
=
strings
.
firstNonWhitespaceIndex
(
lineContent
);
...
...
@@ -178,7 +187,7 @@ export class LineCommentCommand implements ICommand {
/**
* Analyze all lines and decide exactly what to do => not supported | insert line comments | remove line comments
*/
public
static
_gatherPreflightData
(
type
:
Type
,
insertSpace
:
boolean
,
model
:
ITextModel
,
startLineNumber
:
number
,
endLineNumber
:
number
,
ignoreEmptyLines
:
boolean
):
IPreflightData
{
public
static
_gatherPreflightData
(
type
:
Type
,
insertSpace
:
boolean
,
model
:
ITextModel
,
startLineNumber
:
number
,
endLineNumber
:
number
,
ignoreEmptyLines
:
boolean
,
ignoreFirstLine
:
boolean
):
IPreflightData
{
const
lines
=
LineCommentCommand
.
_gatherPreflightCommentStrings
(
model
,
startLineNumber
,
endLineNumber
);
if
(
lines
===
null
)
{
return
{
...
...
@@ -186,7 +195,7 @@ export class LineCommentCommand implements ICommand {
};
}
return
LineCommentCommand
.
_analyzeLines
(
type
,
insertSpace
,
model
,
lines
,
startLineNumber
,
ignoreEmptyLines
);
return
LineCommentCommand
.
_analyzeLines
(
type
,
insertSpace
,
model
,
lines
,
startLineNumber
,
ignoreEmptyLines
,
ignoreFirstLine
);
}
/**
...
...
@@ -323,6 +332,12 @@ export class LineCommentCommand implements ICommand {
let
s
=
this
.
_selection
;
this
.
_moveEndPositionDown
=
false
;
if
(
s
.
startLineNumber
===
s
.
endLineNumber
&&
this
.
_ignoreFirstLine
)
{
builder
.
addEditOperation
(
new
Range
(
s
.
startLineNumber
,
model
.
getLineMaxColumn
(
s
.
startLineNumber
),
s
.
startLineNumber
+
1
,
1
),
s
.
startLineNumber
===
model
.
getLineCount
()
?
''
:
'
\n
'
);
this
.
_selectionId
=
builder
.
trackSelection
(
s
);
return
;
}
if
(
s
.
startLineNumber
<
s
.
endLineNumber
&&
s
.
endColumn
===
1
)
{
this
.
_moveEndPositionDown
=
true
;
s
=
s
.
setEndPosition
(
s
.
endLineNumber
-
1
,
model
.
getLineMaxColumn
(
s
.
endLineNumber
-
1
));
...
...
@@ -334,7 +349,8 @@ export class LineCommentCommand implements ICommand {
model
,
s
.
startLineNumber
,
s
.
endLineNumber
,
this
.
_ignoreEmptyLines
this
.
_ignoreEmptyLines
,
this
.
_ignoreFirstLine
);
if
(
data
.
supported
)
{
...
...
src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts
浏览文件 @
bf6776b9
...
...
@@ -91,7 +91,7 @@ suite('Editor Contrib - Line Comment Command', () => {
'
'
,
'
c
'
,
'
\t\t
d
'
]),
createBasicLinePreflightData
([
'
//
'
,
'
rem
'
,
'
!@#
'
,
'
!@#
'
]),
1
,
true
);
]),
createBasicLinePreflightData
([
'
//
'
,
'
rem
'
,
'
!@#
'
,
'
!@#
'
]),
1
,
true
,
false
);
if
(
!
r
.
supported
)
{
throw
new
Error
(
`unexpected`
);
}
...
...
@@ -122,7 +122,7 @@ suite('Editor Contrib - Line Comment Command', () => {
'
rem
'
,
'
!@# c
'
,
'
\t\t
!@#d
'
]),
createBasicLinePreflightData
([
'
//
'
,
'
rem
'
,
'
!@#
'
,
'
!@#
'
]),
1
,
true
);
]),
createBasicLinePreflightData
([
'
//
'
,
'
rem
'
,
'
!@#
'
,
'
!@#
'
]),
1
,
true
,
false
);
if
(
!
r
.
supported
)
{
throw
new
Error
(
`unexpected`
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录