Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
25cb0d70
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,发现更多精彩内容 >>
提交
25cb0d70
编写于
12月 17, 2020
作者:
R
Raymond Zhao
提交者:
GitHub
12月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update removeTag command
- Handles mixed spacing indents - Affects #104173
上级
d03c1866
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
15 addition
and
59 deletion
+15
-59
extensions/emmet/src/removeTag.ts
extensions/emmet/src/removeTag.ts
+15
-59
未找到文件。
extensions/emmet/src/removeTag.ts
浏览文件 @
25cb0d70
...
...
@@ -11,11 +11,9 @@ export function removeTag() {
return
;
}
const
editor
=
vscode
.
window
.
activeTextEditor
;
const
tabSize
:
number
=
+
editor
.
options
.
tabSize
!
;
let
finalRangesToRemove
=
editor
.
selections
.
reverse
()
.
reduce
<
vscode
.
Range
[]
>
((
prev
,
selection
)
=>
prev
.
concat
(
getRangesToRemove
(
editor
.
document
,
selection
,
tabSize
)),
[]);
prev
.
concat
(
getRangesToRemove
(
editor
.
document
,
selection
)),
[]);
return
editor
.
edit
(
editBuilder
=>
{
finalRangesToRemove
.
forEach
(
range
=>
{
...
...
@@ -28,9 +26,8 @@ export function removeTag() {
* Calculates the ranges to remove, along with what to replace those ranges with.
* It finds the node to remove based on the selection's start position
* and then removes that node, reindenting the content in between.
* Assumption: The document indents consist of only tabs or only spaces.
*/
function
getRangesToRemove
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
,
tabSize
:
number
):
vscode
.
Range
[]
{
function
getRangesToRemove
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
):
vscode
.
Range
[]
{
const
lsDocument
=
toLSTextDocument
(
document
);
const
nodeToUpdate
=
getHtmlNodeLS
(
lsDocument
,
selection
.
start
,
true
);
if
(
!
nodeToUpdate
)
{
...
...
@@ -45,7 +42,7 @@ function getRangesToRemove(document: vscode.TextDocument, selection: vscode.Sele
let
rangesToRemove
=
[
openTagRange
];
if
(
closeTagRange
)
{
const
indentAmountToRemove
=
calculateIndentAmountToRemove
(
document
,
openTagRange
,
closeTagRange
,
tabSize
);
const
indentAmountToRemove
=
calculateIndentAmountToRemove
(
document
,
openTagRange
,
closeTagRange
);
for
(
let
i
=
openTagRange
.
start
.
line
+
1
;
i
<
closeTagRange
.
start
.
line
;
i
++
)
{
rangesToRemove
.
push
(
new
vscode
.
Range
(
i
,
0
,
i
,
indentAmountToRemove
));
}
...
...
@@ -54,71 +51,30 @@ function getRangesToRemove(document: vscode.TextDocument, selection: vscode.Sele
return
rangesToRemove
;
}
type
IndentInfo
=
{
indentAmount
:
number
,
tabsOnly
:
boolean
};
/**
* Calculates the amount of indent to remove for getRangesToRemove.
*/
function
calculateIndentAmountToRemove
(
document
:
vscode
.
TextDocument
,
openRange
:
vscode
.
Range
,
closeRange
:
vscode
.
Range
,
tabSize
:
number
):
number
{
function
calculateIndentAmountToRemove
(
document
:
vscode
.
TextDocument
,
openRange
:
vscode
.
Range
,
closeRange
:
vscode
.
Range
):
number
{
const
startLine
=
openRange
.
start
.
line
;
const
endLine
=
closeRange
.
start
.
line
;
const
startLineIndent
=
calculateLineIndentInSpaces
(
document
.
lineAt
(
startLine
).
text
,
tabSize
)
;
const
endLineIndent
=
calculateLineIndentInSpaces
(
document
.
lineAt
(
endLine
).
text
,
tabSize
)
;
const
startLineIndent
=
document
.
lineAt
(
startLine
).
firstNonWhitespaceCharacterIndex
;
const
endLineIndent
=
document
.
lineAt
(
endLine
).
firstNonWhitespaceCharacterIndex
;
let
contentIndent
:
IndentInfo
|
undefined
;
for
(
let
i
=
startLine
+
1
;
i
<=
endLine
-
1
;
i
++
)
{
const
lineContent
=
document
.
lineAt
(
i
).
text
;
const
indent
=
calculateLineIndentInSpaces
(
lineContent
,
tabSize
);
contentIndent
=
!
contentIndent
?
indent
:
{
indentAmount
:
Math
.
min
(
contentIndent
.
indentAmount
,
indent
.
indentAmount
),
tabsOnly
:
contentIndent
.
tabsOnly
&&
indent
.
tabsOnly
};
let
contentIndent
:
number
|
undefined
;
for
(
let
i
=
startLine
+
1
;
i
<
endLine
;
i
++
)
{
const
lineIndent
=
document
.
lineAt
(
i
).
firstNonWhitespaceCharacterIndex
;
contentIndent
=
!
contentIndent
?
lineIndent
:
Math
.
min
(
contentIndent
,
lineIndent
);
}
let
indentAmountSpaces
=
0
;
let
tabsOnly
=
startLineIndent
.
tabsOnly
&&
endLineIndent
.
tabsOnly
;
let
indentAmount
=
0
;
if
(
contentIndent
)
{
if
(
contentIndent
.
indentAmount
<
startLineIndent
.
indentAmount
||
contentIndent
.
indentAmount
<
endLineIndent
.
indentAmount
)
{
indentAmountSpaces
=
0
;
if
(
contentIndent
<
startLineIndent
||
contentIndent
<
endLineIndent
)
{
indentAmount
=
0
;
}
else
{
indentAmountSpaces
=
Math
.
min
(
contentIndent
.
indentAmount
-
startLineIndent
.
indentAmount
,
contentIndent
.
indentAmount
-
endLineIndent
.
indentAmount
);
indentAmount
=
Math
.
min
(
contentIndent
-
startLineIndent
,
contentIndent
-
endLineIndent
);
}
tabsOnly
=
tabsOnly
&&
contentIndent
.
tabsOnly
;
}
return
tabsOnly
?
Math
.
trunc
(
indentAmountSpaces
/
tabSize
)
:
indentAmountSpaces
;
}
function
calculateLineIndentInSpaces
(
line
:
string
,
tabSize
:
number
):
IndentInfo
{
const
whiteSpaceMatch
=
line
.
match
(
/^
\s
+/
);
const
whiteSpaceContent
=
whiteSpaceMatch
?
whiteSpaceMatch
[
0
]
:
''
;
if
(
!
whiteSpaceContent
)
{
return
{
indentAmount
:
0
,
tabsOnly
:
true
};
}
let
numSpaces
=
0
;
let
numTabs
=
0
;
let
tabsOnly
=
true
;
for
(
const
c
of
whiteSpaceContent
)
{
if
(
c
===
'
\t
'
)
{
numTabs
++
;
}
else
{
numSpaces
++
;
tabsOnly
=
false
;
}
}
return
{
indentAmount
:
numTabs
*
tabSize
+
numSpaces
,
tabsOnly
};
return
indentAmount
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录