Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0c50806e
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,发现更多精彩内容 >>
提交
0c50806e
编写于
10月 19, 2020
作者:
R
Raymond Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor Emmet abbrevationAction files
上级
2c53d687
变更
2
展开全部
显示空白变更内容
内联
并排
Showing
2 changed file
with
75 addition
and
75 deletion
+75
-75
extensions/emmet/src/abbreviationActions.ts
extensions/emmet/src/abbreviationActions.ts
+21
-21
extensions/emmet/src/test/abbreviationAction.test.ts
extensions/emmet/src/test/abbreviationAction.test.ts
+54
-54
未找到文件。
extensions/emmet/src/abbreviationActions.ts
浏览文件 @
0c50806e
...
...
@@ -66,7 +66,7 @@ function doWrapping(individualLines: boolean, args: any) {
const
helper
=
getEmmetHelper
();
// Fetch general information for the succesive expansions. i.e. the ranges to replace and its contents
le
t
rangesToReplace
:
PreviewRangesWithContent
[]
=
editor
.
selections
.
sort
((
a
:
vscode
.
Selection
,
b
:
vscode
.
Selection
)
=>
{
return
a
.
start
.
compareTo
(
b
.
start
);
}).
map
(
selection
=>
{
cons
t
rangesToReplace
:
PreviewRangesWithContent
[]
=
editor
.
selections
.
sort
((
a
:
vscode
.
Selection
,
b
:
vscode
.
Selection
)
=>
{
return
a
.
start
.
compareTo
(
b
.
start
);
}).
map
(
selection
=>
{
let
rangeToReplace
:
vscode
.
Range
=
selection
.
isReversed
?
new
vscode
.
Range
(
selection
.
active
,
selection
.
anchor
)
:
selection
;
if
(
!
rangeToReplace
.
isSingleLine
&&
rangeToReplace
.
end
.
character
===
0
)
{
const
previousLine
=
rangeToReplace
.
end
.
line
-
1
;
...
...
@@ -88,7 +88,7 @@ function doWrapping(individualLines: boolean, args: any) {
rangeToReplace
=
new
vscode
.
Range
(
rangeToReplace
.
start
.
line
,
rangeToReplace
.
start
.
character
+
extraWhitespaceSelected
,
rangeToReplace
.
end
.
line
,
rangeToReplace
.
end
.
character
);
let
textToWrapInPreview
:
string
[];
le
t
textToReplace
=
editor
.
document
.
getText
(
rangeToReplace
);
cons
t
textToReplace
=
editor
.
document
.
getText
(
rangeToReplace
);
if
(
individualLines
)
{
textToWrapInPreview
=
textToReplace
.
split
(
'
\n
'
).
map
(
x
=>
x
.
trim
());
}
else
{
...
...
@@ -144,7 +144,7 @@ function doWrapping(individualLines: boolean, args: any) {
const
oldPreviewLines
=
oldPreviewRange
.
end
.
line
-
oldPreviewRange
.
start
.
line
+
1
;
const
newLinesInserted
=
expandedTextLines
.
length
-
oldPreviewLines
;
le
t
newPreviewLineStart
=
oldPreviewRange
.
start
.
line
+
totalLinesInserted
;
cons
t
newPreviewLineStart
=
oldPreviewRange
.
start
.
line
+
totalLinesInserted
;
let
newPreviewStart
=
oldPreviewRange
.
start
.
character
;
const
newPreviewLineEnd
=
oldPreviewRange
.
end
.
line
+
totalLinesInserted
+
newLinesInserted
;
let
newPreviewEnd
=
expandedTextLines
[
expandedTextLines
.
length
-
1
].
length
;
...
...
@@ -177,19 +177,19 @@ function doWrapping(individualLines: boolean, args: any) {
return
inPreview
?
revertPreview
().
then
(()
=>
{
return
false
;
})
:
Promise
.
resolve
(
inPreview
);
}
le
t
extractedResults
=
helper
.
extractAbbreviationFromText
(
inputAbbreviation
);
cons
t
extractedResults
=
helper
.
extractAbbreviationFromText
(
inputAbbreviation
);
if
(
!
extractedResults
)
{
return
Promise
.
resolve
(
inPreview
);
}
else
if
(
extractedResults
.
abbreviation
!==
inputAbbreviation
)
{
// Not clear what should we do in this case. Warn the user? How?
}
le
t
{
abbreviation
,
filter
}
=
extractedResults
;
cons
t
{
abbreviation
,
filter
}
=
extractedResults
;
if
(
definitive
)
{
const
revertPromise
=
inPreview
?
revertPreview
()
:
Promise
.
resolve
();
return
revertPromise
.
then
(()
=>
{
const
expandAbbrList
:
ExpandAbbreviationInput
[]
=
rangesToReplace
.
map
(
rangesAndContent
=>
{
le
t
rangeToReplace
=
rangesAndContent
.
originalRange
;
cons
t
rangeToReplace
=
rangesAndContent
.
originalRange
;
let
textToWrap
:
string
[];
if
(
individualLines
)
{
textToWrap
=
rangesAndContent
.
textToWrapInPreview
;
...
...
@@ -270,17 +270,17 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
return
fallbackTab
();
}
le
t
abbreviationList
:
ExpandAbbreviationInput
[]
=
[];
cons
t
abbreviationList
:
ExpandAbbreviationInput
[]
=
[];
let
firstAbbreviation
:
string
;
let
allAbbreviationsSame
:
boolean
=
true
;
const
helper
=
getEmmetHelper
();
le
t
getAbbreviation
=
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
,
position
:
vscode
.
Position
,
syntax
:
string
):
[
vscode
.
Range
|
null
,
string
,
string
]
=>
{
cons
t
getAbbreviation
=
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
,
position
:
vscode
.
Position
,
syntax
:
string
):
[
vscode
.
Range
|
null
,
string
,
string
]
=>
{
position
=
document
.
validatePosition
(
position
);
let
rangeToReplace
:
vscode
.
Range
=
selection
;
let
abbr
=
document
.
getText
(
rangeToReplace
);
if
(
!
rangeToReplace
.
isEmpty
)
{
le
t
extractedResults
=
helper
.
extractAbbreviationFromText
(
abbr
);
cons
t
extractedResults
=
helper
.
extractAbbreviationFromText
(
abbr
);
if
(
extractedResults
)
{
return
[
rangeToReplace
,
extractedResults
.
abbreviation
,
extractedResults
.
filter
];
}
...
...
@@ -293,23 +293,23 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
// Expand cases like <div to <div></div> explicitly
// else we will end up with <<div></div>
if
(
syntax
===
'
html
'
)
{
le
t
matches
=
textTillPosition
.
match
(
/<
(\w
+
)
$/
);
cons
t
matches
=
textTillPosition
.
match
(
/<
(\w
+
)
$/
);
if
(
matches
)
{
abbr
=
matches
[
1
];
rangeToReplace
=
new
vscode
.
Range
(
position
.
translate
(
0
,
-
(
abbr
.
length
+
1
)),
position
);
return
[
rangeToReplace
,
abbr
,
''
];
}
}
le
t
extractedResults
=
helper
.
extractAbbreviation
(
toLSTextDocument
(
editor
.
document
),
position
,
false
);
cons
t
extractedResults
=
helper
.
extractAbbreviation
(
toLSTextDocument
(
editor
.
document
),
position
,
false
);
if
(
!
extractedResults
)
{
return
[
null
,
''
,
''
];
}
le
t
{
abbreviationRange
,
abbreviation
,
filter
}
=
extractedResults
;
cons
t
{
abbreviationRange
,
abbreviation
,
filter
}
=
extractedResults
;
return
[
new
vscode
.
Range
(
abbreviationRange
.
start
.
line
,
abbreviationRange
.
start
.
character
,
abbreviationRange
.
end
.
line
,
abbreviationRange
.
end
.
character
),
abbreviation
,
filter
];
};
le
t
selectionsInReverseOrder
=
editor
.
selections
.
slice
(
0
);
cons
t
selectionsInReverseOrder
=
editor
.
selections
.
slice
(
0
);
selectionsInReverseOrder
.
sort
((
a
,
b
)
=>
{
const
posA
=
a
.
isReversed
?
a
.
anchor
:
a
.
active
;
const
posB
=
b
.
isReversed
?
b
.
anchor
:
b
.
active
;
...
...
@@ -322,7 +322,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
return
rootNode
;
}
le
t
usePartialParsing
=
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
)[
'
optimizeStylesheetParsing
'
]
===
true
;
cons
t
usePartialParsing
=
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
)[
'
optimizeStylesheetParsing
'
]
===
true
;
if
(
editor
.
selections
.
length
===
1
&&
isStyleSheet
(
editor
.
document
.
languageId
)
&&
usePartialParsing
&&
editor
.
document
.
lineCount
>
1000
)
{
rootNode
=
parsePartialStylesheet
(
editor
.
document
,
editor
.
selection
.
isReversed
?
editor
.
selection
.
anchor
:
editor
.
selection
.
active
);
}
else
{
...
...
@@ -333,8 +333,8 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
}
selectionsInReverseOrder
.
forEach
(
selection
=>
{
le
t
position
=
selection
.
isReversed
?
selection
.
anchor
:
selection
.
active
;
le
t
[
rangeToReplace
,
abbreviation
,
filter
]
=
getAbbreviation
(
editor
.
document
,
selection
,
position
,
syntax
);
cons
t
position
=
selection
.
isReversed
?
selection
.
anchor
:
selection
.
active
;
cons
t
[
rangeToReplace
,
abbreviation
,
filter
]
=
getAbbreviation
(
editor
.
document
,
selection
,
position
,
syntax
);
if
(
!
rangeToReplace
)
{
return
;
}
...
...
@@ -578,7 +578,7 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex
// Snippet to replace at multiple cursors are not the same
// `editor.insertSnippet` will have to be called for each instance separately
// We will not be able to maintain multiple cursors after snippet insertion
le
t
insertPromises
:
Thenable
<
boolean
>
[]
=
[];
cons
t
insertPromises
:
Thenable
<
boolean
>
[]
=
[];
if
(
!
insertSameSnippet
)
{
expandAbbrList
.
sort
((
a
:
ExpandAbbreviationInput
,
b
:
ExpandAbbreviationInput
)
=>
{
return
b
.
rangeToReplace
.
start
.
compareTo
(
a
.
rangeToReplace
.
start
);
}).
forEach
((
expandAbbrInput
:
ExpandAbbreviationInput
)
=>
{
let
expandedText
=
expandAbbr
(
expandAbbrInput
);
...
...
@@ -596,8 +596,8 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex
// We can pass all ranges to `editor.insertSnippet` in a single call so that
// all cursors are maintained after snippet insertion
const
anyExpandAbbrInput
=
expandAbbrList
[
0
];
le
t
expandedText
=
expandAbbr
(
anyExpandAbbrInput
);
le
t
allRanges
=
expandAbbrList
.
map
(
value
=>
{
cons
t
expandedText
=
expandAbbr
(
anyExpandAbbrInput
);
cons
t
allRanges
=
expandAbbrList
.
map
(
value
=>
{
return
new
vscode
.
Range
(
value
.
rangeToReplace
.
start
.
line
,
value
.
rangeToReplace
.
start
.
character
,
value
.
rangeToReplace
.
end
.
line
,
value
.
rangeToReplace
.
end
.
character
);
});
if
(
expandedText
)
{
...
...
@@ -614,7 +614,7 @@ function walk(root: any, fn: ((node: any) => boolean)): boolean {
let
ctx
=
root
;
while
(
ctx
)
{
le
t
next
=
ctx
.
next
;
cons
t
next
=
ctx
.
next
;
if
(
fn
(
ctx
)
===
false
||
walk
(
ctx
.
firstChild
,
fn
)
===
false
)
{
return
false
;
}
...
...
@@ -653,7 +653,7 @@ function expandAbbr(input: ExpandAbbreviationInput): string | undefined {
// Expand the abbreviation
if
(
input
.
textToWrap
)
{
le
t
parsedAbbr
=
helper
.
parseAbbreviation
(
input
.
abbreviation
,
expandOptions
);
cons
t
parsedAbbr
=
helper
.
parseAbbreviation
(
input
.
abbreviation
,
expandOptions
);
if
(
input
.
rangeToReplace
.
isSingleLine
&&
input
.
textToWrap
.
length
===
1
)
{
// Fetch rightmost element in the parsed abbreviation (i.e the element that will contain the wrapped text).
...
...
extensions/emmet/src/test/abbreviationAction.test.ts
浏览文件 @
0c50806e
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录