Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2c208a99
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,发现更多精彩内容 >>
未验证
提交
2c208a99
编写于
11月 28, 2019
作者:
A
Alexandru Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce and adapt CompleteEnterAction
上级
0789507d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
49 deletion
+64
-49
src/vs/editor/common/commands/shiftCommand.ts
src/vs/editor/common/commands/shiftCommand.ts
+1
-1
src/vs/editor/common/controller/cursorTypeOperations.ts
src/vs/editor/common/controller/cursorTypeOperations.ts
+11
-18
src/vs/editor/common/modes/languageConfiguration.ts
src/vs/editor/common/modes/languageConfiguration.ts
+22
-0
src/vs/editor/common/modes/languageConfigurationRegistry.ts
src/vs/editor/common/modes/languageConfigurationRegistry.ts
+23
-22
src/vs/editor/contrib/linesOperations/moveLinesCommand.ts
src/vs/editor/contrib/linesOperations/moveLinesCommand.ts
+7
-8
未找到文件。
src/vs/editor/common/commands/shiftCommand.ts
浏览文件 @
2c208a99
...
...
@@ -139,7 +139,7 @@ export class ShiftCommand implements ICommand {
// The current line is "miss-aligned", so let's see if this is expected...
// This can only happen when it has trailing commas in the indent
if
(
model
.
isCheapToTokenize
(
lineNumber
-
1
))
{
let
enterAction
=
LanguageConfigurationRegistry
.
get
RawEnterActionAtPosition
(
this
.
_opts
.
autoIndent
,
model
,
lineNumber
-
1
,
model
.
getLineMaxColumn
(
lineNumber
-
1
));
let
enterAction
=
LanguageConfigurationRegistry
.
get
EnterAction
(
this
.
_opts
.
autoIndent
,
model
,
new
Range
(
lineNumber
-
1
,
model
.
getLineMaxColumn
(
lineNumber
-
1
),
lineNumber
-
1
,
model
.
getLineMaxColumn
(
lineNumber
-
1
)
));
if
(
enterAction
)
{
extraSpaces
=
previousLineExtraSpaces
;
if
(
enterAction
.
appendText
)
{
...
...
src/vs/editor/common/controller/cursorTypeOperations.ts
浏览文件 @
2c208a99
...
...
@@ -174,11 +174,7 @@ export class TypeOperations {
const
maxColumn
=
model
.
getLineMaxColumn
(
lastLineNumber
);
const
expectedEnterAction
=
LanguageConfigurationRegistry
.
getEnterAction
(
config
.
autoIndent
,
model
,
new
Range
(
lastLineNumber
,
maxColumn
,
lastLineNumber
,
maxColumn
));
if
(
expectedEnterAction
)
{
indentation
=
expectedEnterAction
.
indentation
;
action
=
expectedEnterAction
.
enterAction
;
if
(
action
)
{
indentation
+=
action
.
appendText
;
}
indentation
=
expectedEnterAction
.
indentation
+
expectedEnterAction
.
appendText
;
}
}
...
...
@@ -304,21 +300,18 @@ export class TypeOperations {
const
r
=
LanguageConfigurationRegistry
.
getEnterAction
(
config
.
autoIndent
,
model
,
range
);
if
(
r
)
{
const
enterAction
=
r
.
enterAction
;
const
indentation
=
r
.
indentation
;
if
(
enterAction
.
indentAction
===
IndentAction
.
None
)
{
if
(
r
.
indentAction
===
IndentAction
.
None
)
{
// Nothing special
return
TypeOperations
.
_typeCommand
(
range
,
'
\n
'
+
config
.
normalizeIndentation
(
indentation
+
enterAction
.
appendText
),
keepPosition
);
return
TypeOperations
.
_typeCommand
(
range
,
'
\n
'
+
config
.
normalizeIndentation
(
r
.
indentation
+
r
.
appendText
),
keepPosition
);
}
else
if
(
enterAction
.
indentAction
===
IndentAction
.
Indent
)
{
}
else
if
(
r
.
indentAction
===
IndentAction
.
Indent
)
{
// Indent once
return
TypeOperations
.
_typeCommand
(
range
,
'
\n
'
+
config
.
normalizeIndentation
(
indentation
+
enterAction
.
appendText
),
keepPosition
);
return
TypeOperations
.
_typeCommand
(
range
,
'
\n
'
+
config
.
normalizeIndentation
(
r
.
indentation
+
r
.
appendText
),
keepPosition
);
}
else
if
(
enterAction
.
indentAction
===
IndentAction
.
IndentOutdent
)
{
}
else
if
(
r
.
indentAction
===
IndentAction
.
IndentOutdent
)
{
// Ultra special
const
normalIndent
=
config
.
normalizeIndentation
(
indentation
);
const
increasedIndent
=
config
.
normalizeIndentation
(
indentation
+
enterAction
.
appendText
);
const
normalIndent
=
config
.
normalizeIndentation
(
r
.
indentation
);
const
increasedIndent
=
config
.
normalizeIndentation
(
r
.
indentation
+
r
.
appendText
);
const
typeText
=
'
\n
'
+
increasedIndent
+
'
\n
'
+
normalIndent
;
...
...
@@ -327,9 +320,9 @@ export class TypeOperations {
}
else
{
return
new
ReplaceCommandWithOffsetCursorState
(
range
,
typeText
,
-
1
,
increasedIndent
.
length
-
normalIndent
.
length
,
true
);
}
}
else
if
(
enterAction
.
indentAction
===
IndentAction
.
Outdent
)
{
const
actualIndentation
=
TypeOperations
.
unshiftIndent
(
config
,
indentation
);
return
TypeOperations
.
_typeCommand
(
range
,
'
\n
'
+
config
.
normalizeIndentation
(
actualIndentation
+
enterAction
.
appendText
),
keepPosition
);
}
else
if
(
r
.
indentAction
===
IndentAction
.
Outdent
)
{
const
actualIndentation
=
TypeOperations
.
unshiftIndent
(
config
,
r
.
indentation
);
return
TypeOperations
.
_typeCommand
(
range
,
'
\n
'
+
config
.
normalizeIndentation
(
actualIndentation
+
r
.
appendText
),
keepPosition
);
}
}
...
...
src/vs/editor/common/modes/languageConfiguration.ts
浏览文件 @
2c208a99
...
...
@@ -228,6 +228,28 @@ export interface EnterAction {
removeText
?:
number
;
}
/**
* @internal
*/
export
interface
CompleteEnterAction
{
/**
* Describe what to do with the indentation.
*/
indentAction
:
IndentAction
;
/**
* Describes text to be appended after the new line and after the indentation.
*/
appendText
:
string
;
/**
* Describes the number of characters to remove from the new line's indentation.
*/
removeText
:
number
;
/**
* The line's indentation minus removeText
*/
indentation
:
string
;
}
/**
* @internal
*/
...
...
src/vs/editor/common/modes/languageConfigurationRegistry.ts
浏览文件 @
2c208a99
...
...
@@ -12,7 +12,7 @@ import { Range } from 'vs/editor/common/core/range';
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
DEFAULT_WORD_REGEXP
,
ensureValidWordDefinition
}
from
'
vs/editor/common/model/wordHelper
'
;
import
{
LanguageId
,
LanguageIdentifier
}
from
'
vs/editor/common/modes
'
;
import
{
EnterAction
,
FoldingRules
,
IAutoClosingPair
,
IndentAction
,
IndentationRule
,
LanguageConfiguration
,
StandardAutoClosingPairConditional
}
from
'
vs/editor/common/modes/languageConfiguration
'
;
import
{
EnterAction
,
FoldingRules
,
IAutoClosingPair
,
IndentAction
,
IndentationRule
,
LanguageConfiguration
,
StandardAutoClosingPairConditional
,
CompleteEnterAction
}
from
'
vs/editor/common/modes/languageConfiguration
'
;
import
{
createScopedLineTokens
,
ScopedLineTokens
}
from
'
vs/editor/common/modes/supports
'
;
import
{
CharacterPairSupport
}
from
'
vs/editor/common/modes/supports/characterPair
'
;
import
{
BracketElectricCharacterSupport
,
IElectricAction
}
from
'
vs/editor/common/modes/supports/electricCharacter
'
;
...
...
@@ -697,12 +697,7 @@ export class LanguageConfigurationRegistryImpl {
return
value
.
onEnter
||
null
;
}
public
getRawEnterActionAtPosition
(
autoIndent
:
EditorAutoIndentStrategy
,
model
:
ITextModel
,
lineNumber
:
number
,
column
:
number
):
EnterAction
|
null
{
const
r
=
this
.
getEnterAction
(
autoIndent
,
model
,
new
Range
(
lineNumber
,
column
,
lineNumber
,
column
));
return
r
?
r
.
enterAction
:
null
;
}
public
getEnterAction
(
autoIndent
:
EditorAutoIndentStrategy
,
model
:
ITextModel
,
range
:
Range
):
{
enterAction
:
EnterAction
;
indentation
:
string
;
}
|
null
{
public
getEnterAction
(
autoIndent
:
EditorAutoIndentStrategy
,
model
:
ITextModel
,
range
:
Range
):
CompleteEnterAction
|
null
{
const
scopedLineTokens
=
this
.
getScopedLineTokens
(
model
,
range
.
startLineNumber
,
range
.
startColumn
);
const
onEnterSupport
=
this
.
_getOnEnterSupport
(
scopedLineTokens
.
languageId
);
if
(
!
onEnterSupport
)
{
...
...
@@ -740,28 +735,34 @@ export class LanguageConfigurationRegistryImpl {
if
(
!
enterResult
)
{
return
null
;
}
else
{
// Here we add `\t` to appendText first because enterAction is leveraging appendText and removeText to change indentation.
if
(
!
enterResult
.
appendText
)
{
if
(
(
enterResult
.
indentAction
===
IndentAction
.
Indent
)
||
(
enterResult
.
indentAction
===
IndentAction
.
IndentOutdent
)
)
{
enterResult
.
appendText
=
'
\t
'
;
}
else
{
enterResult
.
appendText
=
''
;
}
}
const
indentAction
=
enterResult
.
indentAction
;
let
appendText
=
enterResult
.
appendText
;
const
removeText
=
enterResult
.
removeText
||
0
;
// Here we add `\t` to appendText first because enterAction is leveraging appendText and removeText to change indentation.
if
(
!
appendText
)
{
if
(
(
indentAction
===
IndentAction
.
Indent
)
||
(
indentAction
===
IndentAction
.
IndentOutdent
)
)
{
appendText
=
'
\t
'
;
}
else
{
appendText
=
''
;
}
}
let
indentation
=
this
.
getIndentationAtPosition
(
model
,
range
.
startLineNumber
,
range
.
startColumn
);
if
(
enterResult
.
removeText
)
{
indentation
=
indentation
.
substring
(
0
,
indentation
.
length
-
enterResult
.
removeText
);
if
(
removeText
)
{
indentation
=
indentation
.
substring
(
0
,
indentation
.
length
-
removeText
);
}
return
{
enterAction
:
enterResult
,
indentation
:
indentation
,
indentAction
:
indentAction
,
appendText
:
appendText
,
removeText
:
removeText
,
indentation
:
indentation
};
}
...
...
src/vs/editor/contrib/linesOperations/moveLinesCommand.ts
浏览文件 @
2c208a99
...
...
@@ -256,16 +256,15 @@ export class MoveLinesCommand implements ICommand {
if
(
enter
)
{
let
enterPrefix
=
enter
.
indentation
;
let
enterAction
=
enter
.
enterAction
;
if
(
enter
Action
.
indentAction
===
IndentAction
.
None
)
{
enterPrefix
=
enter
.
indentation
+
enter
Action
.
appendText
;
}
else
if
(
enter
Action
.
indentAction
===
IndentAction
.
Indent
)
{
enterPrefix
=
enter
.
indentation
+
enter
Action
.
appendText
;
}
else
if
(
enter
Action
.
indentAction
===
IndentAction
.
IndentOutdent
)
{
if
(
enter
.
indentAction
===
IndentAction
.
None
)
{
enterPrefix
=
enter
.
indentation
+
enter
.
appendText
;
}
else
if
(
enter
.
indentAction
===
IndentAction
.
Indent
)
{
enterPrefix
=
enter
.
indentation
+
enter
.
appendText
;
}
else
if
(
enter
.
indentAction
===
IndentAction
.
IndentOutdent
)
{
enterPrefix
=
enter
.
indentation
;
}
else
if
(
enter
Action
.
indentAction
===
IndentAction
.
Outdent
)
{
enterPrefix
=
indentConverter
.
unshiftIndent
(
enter
.
indentation
)
+
enter
Action
.
appendText
;
}
else
if
(
enter
.
indentAction
===
IndentAction
.
Outdent
)
{
enterPrefix
=
indentConverter
.
unshiftIndent
(
enter
.
indentation
)
+
enter
.
appendText
;
}
let
movingLineText
=
model
.
getLineContent
(
line
);
if
(
this
.
trimLeft
(
movingLineText
).
indexOf
(
this
.
trimLeft
(
enterPrefix
))
>=
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录