Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f4055d95
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,发现更多精彩内容 >>
提交
f4055d95
编写于
6月 22, 2017
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactoring
上级
7be031a6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
70 deletion
+52
-70
extensions/emmet/src/abbreviationActions.ts
extensions/emmet/src/abbreviationActions.ts
+52
-70
未找到文件。
extensions/emmet/src/abbreviationActions.ts
浏览文件 @
f4055d95
...
...
@@ -12,6 +12,12 @@ import { getSyntax, getNode, getInnerRange } from './util';
import
{
getExpandOptions
,
extractAbbreviation
,
isStyleSheet
}
from
'
vscode-emmet-helper
'
;
import
{
DocumentStreamReader
}
from
'
./bufferStream
'
;
interface
ExpandAbbreviationInput
{
abbreviation
:
string
;
rangeToReplace
:
vscode
.
Range
;
textToWrap
?:
string
;
}
export
function
wrapWithAbbreviation
()
{
let
editor
=
vscode
.
window
.
activeTextEditor
;
if
(
!
editor
)
{
...
...
@@ -21,10 +27,10 @@ export function wrapWithAbbreviation() {
const
newLine
=
editor
.
document
.
eol
===
vscode
.
EndOfLine
.
LF
?
'
\n
'
:
'
\r\n
'
;
let
syntax
=
getSyntax
(
editor
.
document
);
vscode
.
window
.
showInputBox
({
prompt
:
'
Enter Abbreviation
'
}).
then
(
abbr
=>
{
if
(
!
abbr
||
!
abbr
.
trim
())
{
return
;
}
vscode
.
window
.
showInputBox
({
prompt
:
'
Enter Abbreviation
'
}).
then
(
abbr
eviation
=>
{
if
(
!
abbr
eviation
||
!
abbreviation
.
trim
())
{
return
;
}
let
textToReplaceList
:
[
string
,
vscode
.
Range
]
[]
=
[];
let
expandAbbrList
:
ExpandAbbreviationInput
[]
=
[];
let
firstTextToReplace
:
string
;
let
allTextToReplaceSame
:
boolean
=
true
;
...
...
@@ -33,45 +39,18 @@ export function wrapWithAbbreviation() {
if
(
rangeToReplace
.
isEmpty
)
{
rangeToReplace
=
new
vscode
.
Range
(
rangeToReplace
.
start
.
line
,
0
,
rangeToReplace
.
start
.
line
,
editor
.
document
.
lineAt
(
rangeToReplace
.
start
.
line
).
text
.
length
);
}
let
textTo
Replace
=
editor
.
document
.
getText
(
rangeToReplace
)
;
let
textTo
Wrap
=
newLine
+
editor
.
document
.
getText
(
rangeToReplace
)
+
newLine
;
if
(
!
firstTextToReplace
)
{
firstTextToReplace
=
textTo
Replace
;
}
else
if
(
allTextToReplaceSame
&&
firstTextToReplace
!==
textTo
Replace
)
{
firstTextToReplace
=
textTo
Wrap
;
}
else
if
(
allTextToReplaceSame
&&
firstTextToReplace
!==
textTo
Wrap
)
{
allTextToReplaceSame
=
false
;
}
textToReplaceList
.
push
([
textToReplace
,
rangeToReplace
]);
});
if
(
textToReplaceList
.
length
===
0
)
{
return
;
}
// Text 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
if
(
!
allTextToReplaceSame
)
{
textToReplaceList
.
forEach
(([
textToReplace
,
rangeToReplace
])
=>
{
let
expandedText
=
expand
(
abbr
,
getExpandOptions
(
syntax
,
newLine
+
textToReplace
+
newLine
));
if
(
expandedText
)
{
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
rangeToReplace
);
}
});
return
;
}
// Text to replace at all cursors are the same
// We can pass all ranges to `editor.insertSnippet` in a single call so that
// all cursors are maintained after snippet insertion
let
expandedText
=
expand
(
abbr
,
getExpandOptions
(
syntax
,
newLine
+
textToReplaceList
[
0
][
0
]
+
newLine
));
let
allRanges
=
textToReplaceList
.
map
(
value
=>
{
return
value
[
1
];
expandAbbrList
.
push
({
abbreviation
,
rangeToReplace
,
textToWrap
});
});
if
(
expandedText
)
{
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
allRanges
);
}
expandAbbr
(
editor
,
expandAbbrList
,
syntax
,
allTextToReplaceSame
);
});
}
...
...
@@ -89,16 +68,16 @@ export function expandAbbreviation(args) {
let
parseContent
=
isStyleSheet
(
syntax
)
?
parseStylesheet
:
parse
;
let
rootNode
:
Node
=
parseContent
(
new
DocumentStreamReader
(
editor
.
document
));
let
abbreviationList
:
[
string
,
vscode
.
Range
]
[]
=
[];
let
abbreviationList
:
ExpandAbbreviationInput
[]
=
[];
let
firstAbbreviation
:
string
;
let
allAbbreviationsSame
:
boolean
=
true
;
editor
.
selections
.
forEach
(
selection
=>
{
let
abbreviationRang
e
:
vscode
.
Range
=
selection
;
let
rangeToReplac
e
:
vscode
.
Range
=
selection
;
let
position
=
selection
.
isReversed
?
selection
.
anchor
:
selection
.
active
;
let
abbreviation
=
editor
.
document
.
getText
(
abbreviationRang
e
);
if
(
abbreviationRang
e
.
isEmpty
)
{
[
abbreviationRang
e
,
abbreviation
]
=
extractAbbreviation
(
editor
.
document
,
position
);
let
abbreviation
=
editor
.
document
.
getText
(
rangeToReplac
e
);
if
(
rangeToReplac
e
.
isEmpty
)
{
[
rangeToReplac
e
,
abbreviation
]
=
extractAbbreviation
(
editor
.
document
,
position
);
}
let
currentNode
=
getNode
(
rootNode
,
position
);
...
...
@@ -112,38 +91,10 @@ export function expandAbbreviation(args) {
allAbbreviationsSame
=
false
;
}
abbreviationList
.
push
(
[
abbreviation
,
abbreviationRange
]
);
abbreviationList
.
push
(
{
abbreviation
,
rangeToReplace
}
);
});
if
(
abbreviationList
.
length
===
0
)
{
return
;
}
// Abbreviations at multiple cursors are not the same
// `editor.insertSnippet` will have to be called for each abbreviation separately
// We will not be able to maintain multiple cursors after snippet insertion
if
(
!
allAbbreviationsSame
)
{
abbreviationList
.
forEach
(([
abbreviation
,
abbreviationRange
])
=>
{
let
expandedText
=
expand
(
abbreviation
,
getExpandOptions
(
syntax
));
if
(
expandedText
)
{
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
abbreviationRange
);
}
});
return
;
}
// Abbreviations at all cursors are the same
// We can pass all ranges to `editor.insertSnippet` in a single call so that
// all cursors are maintained after snippet insertion
let
expandedText
=
expand
(
abbreviationList
[
0
][
0
],
getExpandOptions
(
syntax
));
let
allRanges
=
abbreviationList
.
map
(
value
=>
{
return
value
[
1
];
});
if
(
expandedText
)
{
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
allRanges
);
}
expandAbbr
(
editor
,
abbreviationList
,
syntax
,
allAbbreviationsSame
);
}
...
...
@@ -169,4 +120,35 @@ export function isValidLocationForEmmetAbbreviation(currentNode: Node, syntax: s
}
return
false
;
}
function
expandAbbr
(
editor
:
vscode
.
TextEditor
,
expandAbbrList
:
ExpandAbbreviationInput
[],
syntax
:
string
,
insertSameSnippet
:
boolean
)
{
if
(
!
expandAbbrList
||
expandAbbrList
.
length
===
0
)
{
return
;
}
// 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
if
(
!
insertSameSnippet
)
{
expandAbbrList
.
forEach
((
expandAbbrInput
:
ExpandAbbreviationInput
)
=>
{
let
expandedText
=
expand
(
expandAbbrInput
.
abbreviation
,
getExpandOptions
(
syntax
,
expandAbbrInput
.
textToWrap
));
if
(
expandedText
)
{
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
expandAbbrInput
.
rangeToReplace
);
}
});
return
;
}
// Snippet to replace at all cursors are the same
// 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
];
let
expandedText
=
expand
(
anyExpandAbbrInput
.
abbreviation
,
getExpandOptions
(
syntax
,
anyExpandAbbrInput
.
textToWrap
));
let
allRanges
=
expandAbbrList
.
map
(
value
=>
{
return
value
.
rangeToReplace
;
});
if
(
expandedText
)
{
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
allRanges
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录