Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3eb4e2be
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,体验更适合开发者的 AI 搜索 >>
提交
3eb4e2be
编写于
1月 04, 2017
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
get expected indentation from above lines
上级
6267d9f5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
66 addition
and
72 deletion
+66
-72
src/vs/editor/common/controller/cursorTypeOperations.ts
src/vs/editor/common/controller/cursorTypeOperations.ts
+24
-29
src/vs/editor/common/modes/languageConfiguration.ts
src/vs/editor/common/modes/languageConfiguration.ts
+4
-0
src/vs/editor/common/modes/languageConfigurationRegistry.ts
src/vs/editor/common/modes/languageConfigurationRegistry.ts
+23
-28
src/vs/editor/common/modes/supports/onEnter.ts
src/vs/editor/common/modes/supports/onEnter.ts
+9
-14
src/vs/editor/test/common/controller/cursor.test.ts
src/vs/editor/test/common/controller/cursor.test.ts
+2
-1
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+4
-0
未找到文件。
src/vs/editor/common/controller/cursorTypeOperations.ts
浏览文件 @
3eb4e2be
...
...
@@ -103,16 +103,16 @@ export class TypeOperations {
}
private
static
_goodIndentForLine
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
lineNumber
:
number
):
string
{
let
inheritIndentAction
=
LanguageConfigurationRegistry
.
getInheritedIndentActionForCurrentLine
(
model
,
lineNumber
);
let
expectedIndentAction
=
LanguageConfigurationRegistry
.
getExpectedIndentActionAtPosition
(
model
,
lineNumber
);
if
(
inheritIndentAction
&&
inherit
IndentAction
.
action
)
{
let
indentation
=
inherit
IndentAction
.
indentation
;
if
(
expectedIndentAction
&&
expected
IndentAction
.
action
)
{
let
indentation
=
expected
IndentAction
.
indentation
;
if
(
inherit
IndentAction
.
action
===
IndentAction
.
Indent
)
{
if
(
expected
IndentAction
.
action
===
IndentAction
.
Indent
)
{
indentation
=
TypeOperations
.
shiftIndent
(
config
,
indentation
);
}
if
(
inherit
IndentAction
.
action
===
IndentAction
.
Outdent
)
{
if
(
expected
IndentAction
.
action
===
IndentAction
.
Outdent
)
{
indentation
=
TypeOperations
.
unshiftIndent
(
config
,
indentation
);
}
...
...
@@ -213,37 +213,32 @@ export class TypeOperations {
}
let
enterAction
=
LanguageConfigurationRegistry
.
getEnterActionAtPosition
(
model
,
range
.
startLineNumber
,
range
.
startColumn
);
let
beforeText
=
''
;
let
inheritedIntentationAction
=
LanguageConfigurationRegistry
.
getInheritedIndentActionForCurrentLine
(
model
,
range
.
startLineNumber
);
let
currentLineIndentationRule
=
LanguageConfigurationRegistry
.
getIndentationRuleForCurrentLine
(
model
,
range
.
startLineNumber
,
range
.
startColumn
);
let
expectedIndentAction
=
LanguageConfigurationRegistry
.
getExpectedIndentActionAtPosition
(
model
,
range
.
startLineNumber
);
let
expectedIndentationBeforeEnter
=
indentation
;
if
(
inheritedIntentationAction
||
currentLineIndentationRule
)
{
// The indentation of current line may be adjusted
let
expectedIndentation
=
indentation
;
if
(
expectedIndentAction
&&
expectedIndentAction
.
action
)
{
expectedIndentationBeforeEnter
=
expectedIndentAction
.
indentation
;
if
(
inheritedIntentationAction
&&
inheritedIntentationAction
.
action
)
{
if
(
inheritedIntentationAction
.
action
===
IndentAction
.
Indent
)
{
expectedIndentation
=
TypeOperations
.
shiftIndent
(
config
,
inheritedIntentationAction
.
indentation
);
}
if
(
inheritedIntentationAction
.
action
===
IndentAction
.
Outdent
)
{
expectedIndentation
=
TypeOperations
.
unshiftIndent
(
config
,
inheritedIntentationAction
.
indentation
);
}
if
(
expectedIndentAction
.
action
===
IndentAction
.
Indent
)
{
expectedIndentationBeforeEnter
=
TypeOperations
.
shiftIndent
(
config
,
expectedIndentationBeforeEnter
);
}
if
(
currentLineIndentationRule
&&
currentLineIndentationRule
===
IndentAction
.
Outdent
)
{
expectedIndentation
=
TypeOperations
.
unshiftIndent
(
config
,
expectedIndentation
);
if
(
expectedIndentAction
.
action
===
IndentAction
.
Outdent
)
{
expectedIndentation
BeforeEnter
=
TypeOperations
.
unshiftIndent
(
config
,
expectedIndentationBeforeEnter
);
}
}
expectedIndentation
=
config
.
normalizeIndentation
(
expectedIndentation
);
if
(
enterAction
.
outdentCurrentLine
)
{
expectedIndentationBeforeEnter
=
TypeOperations
.
unshiftIndent
(
config
,
expectedIndentationBeforeEnter
);
}
if
(
expectedIndentation
!==
indentation
)
{
// adjust indentation of current line.
beforeText
=
expectedIndentation
+
lineText
.
substring
(
indentation
.
length
,
range
.
startColumn
-
1
);
indentation
=
expectedIndentation
;
range
=
new
Range
(
range
.
startLineNumber
,
1
,
range
.
endLineNumber
,
range
.
endColumn
);
}
expectedIndentationBeforeEnter
=
config
.
normalizeIndentation
(
expectedIndentationBeforeEnter
);
let
beforeText
=
''
;
if
(
expectedIndentationBeforeEnter
!==
indentation
)
{
beforeText
=
expectedIndentationBeforeEnter
+
lineText
.
substring
(
indentation
.
length
,
range
.
startColumn
-
1
);
indentation
=
expectedIndentationBeforeEnter
;
range
=
new
Range
(
range
.
startLineNumber
,
1
,
range
.
endLineNumber
,
range
.
endColumn
);
}
// compute indentation of following lines
...
...
src/vs/editor/common/modes/languageConfiguration.ts
浏览文件 @
3eb4e2be
...
...
@@ -174,6 +174,10 @@ export interface EnterAction {
* Describe what to do with the indentation.
*/
indentAction
:
IndentAction
;
/**
* Describe whether to outdent current line.
*/
outdentCurrentLine
?:
boolean
;
/**
* Describes text to be appended after the new line and after the indentation.
*/
...
...
src/vs/editor/common/modes/languageConfigurationRegistry.ts
浏览文件 @
3eb4e2be
...
...
@@ -279,16 +279,28 @@ export class LanguageConfigurationRegistryImpl {
return
result
;
}
public
getInheritedIndentActionForCurrentLine
(
model
:
ITokenizedModel
,
lineNumber
:
number
):
{
indentation
:
string
,
action
:
IndentAction
}
{
public
getEnterActionAtPosition
(
model
:
ITokenizedModel
,
lineNumber
:
number
,
column
:
number
):
EnterAction
{
let
enterAction
=
this
.
getRawEnterActionAtPosition
(
model
,
lineNumber
,
column
);
if
(
!
enterAction
)
{
enterAction
=
{
indentAction
:
IndentAction
.
None
,
appendText
:
''
,
};
}
else
{
if
(
!
enterAction
.
appendText
)
{
enterAction
.
appendText
=
''
;
}
}
return
enterAction
;
}
public
getExpectedIndentActionAtPosition
(
model
:
ITokenizedModel
,
lineNumber
:
number
)
{
/**
* In order to get correct indentation for current line
* we need to loop backwards all the lines from current line until
* 1. a line is not empty
* 2. and the line doesn't match `unIndentedLinePattern` pattern
* we need to loop backwards all the lines from current line until a line contains non whitespace characters.
*/
// TODO: how about a line filled with only spaces?
let
lastLineNumber
=
lineNumber
-
1
;
for
(
lastLineNumber
=
lineNumber
-
1
;
lastLineNumber
>=
1
;
lastLineNumber
--
)
{
...
...
@@ -313,18 +325,17 @@ export class LanguageConfigurationRegistryImpl {
}
let
lineText
=
model
.
getLineContent
(
lastLineNumber
);
let
lineTextAbove
:
string
;
let
oneLineAboveText
:
string
;
if
(
lastLineNumber
>
1
)
{
lineTextAbove
=
model
.
getLineContent
(
lastLineNumber
-
1
);
oneLineAboveText
=
model
.
getLineContent
(
lastLineNumber
-
1
);
}
let
indentation
=
strings
.
getLeadingWhitespace
(
lineText
);
let
inheritedIntentationRule
=
onEnterSupport
.
getInheritedIndentationRules
(
lineText
,
lineTextAbove
);
let
expectedIntentAction
=
onEnterSupport
.
getExpectedIndentActionAtPosition
(
lineText
,
oneLineAboveText
);
return
{
indentation
:
indentation
,
action
:
inheritedIntentationRule
action
:
expectedIntentAction
};
}
...
...
@@ -342,22 +353,6 @@ export class LanguageConfigurationRegistryImpl {
return
indentAction
;
}
public
getEnterActionAtPosition
(
model
:
ITokenizedModel
,
lineNumber
:
number
,
column
:
number
):
EnterAction
{
let
enterAction
=
this
.
getRawEnterActionAtPosition
(
model
,
lineNumber
,
column
);
if
(
!
enterAction
)
{
enterAction
=
{
indentAction
:
IndentAction
.
None
,
appendText
:
''
,
};
}
else
{
if
(
!
enterAction
.
appendText
)
{
enterAction
.
appendText
=
''
;
}
}
return
enterAction
;
}
// end onEnter
public
getBracketsSupport
(
languageId
:
LanguageId
):
RichEditBrackets
{
...
...
src/vs/editor/common/modes/supports/onEnter.ts
浏览文件 @
3eb4e2be
...
...
@@ -75,7 +75,6 @@ export class OnEnterSupport {
// (3): Indentation Support
if
(
this
.
_indentationRules
)
{
let
enterAction
:
EnterAction
=
null
;
if
(
this
.
_indentationRules
.
increaseIndentPattern
&&
this
.
_indentationRules
.
increaseIndentPattern
.
test
(
beforeEnterText
))
{
enterAction
=
{
indentAction
:
IndentAction
.
Indent
};
}
...
...
@@ -90,6 +89,13 @@ export class OnEnterSupport {
if
(
this
.
_indentationRules
.
indentNextLinePattern
&&
this
.
_indentationRules
.
indentNextLinePattern
.
test
(
oneLineAboveText
))
{
enterAction
=
{
indentAction
:
IndentAction
.
Outdent
};
}
if
(
this
.
_indentationRules
.
decreaseIndentPattern
&&
this
.
_indentationRules
.
decreaseIndentPattern
.
test
(
beforeEnterText
))
{
if
(
enterAction
===
null
)
{
enterAction
=
{
indentAction
:
IndentAction
.
None
,
outdentCurrentLine
:
true
};
}
else
{
enterAction
=
{
indentAction
:
enterAction
.
indentAction
,
outdentCurrentLine
:
true
};
}
}
}
if
(
enterAction
!==
null
)
{
...
...
@@ -110,10 +116,10 @@ export class OnEnterSupport {
return
null
;
}
public
get
InheritedIndentationRules
(
text
:
string
,
textOneLineAbove
?:
string
):
IndentAction
{
public
get
ExpectedIndentActionAtPosition
(
text
:
string
,
oneLineAboveText
?:
string
):
IndentAction
{
let
offset
=
0
;
if
(
this
.
_indentationRules
)
{
if
(
textOneLineAbove
&&
this
.
_indentationRules
.
indentNextLinePattern
&&
this
.
_indentationRules
.
indentNextLinePattern
.
test
(
textOneLineAbove
))
{
if
(
oneLineAboveText
&&
this
.
_indentationRules
.
indentNextLinePattern
&&
this
.
_indentationRules
.
indentNextLinePattern
.
test
(
oneLineAboveText
))
{
offset
-=
1
;
}
...
...
@@ -144,17 +150,6 @@ export class OnEnterSupport {
return
null
;
}
public
getIndentActionForContent
(
text
:
string
):
IndentAction
{
if
(
this
.
_indentationRules
&&
/^
\s
/
.
test
(
text
))
{
// No reason to run regular expressions if there is nothing to outdent from
if
(
this
.
_indentationRules
.
decreaseIndentPattern
&&
this
.
_indentationRules
.
decreaseIndentPattern
.
test
(
text
))
{
return
IndentAction
.
Outdent
;
}
}
return
null
;
}
private
static
_createOpenBracketRegExp
(
bracket
:
string
):
RegExp
{
var
str
=
strings
.
escapeRegExpCharacters
(
bracket
);
if
(
!
/
\B
/
.
test
(
str
.
charAt
(
0
)))
{
...
...
src/vs/editor/test/common/controller/cursor.test.ts
浏览文件 @
3eb4e2be
...
...
@@ -1142,7 +1142,8 @@ class OnEnterMode extends MockMode {
onEnterRules
:
[{
beforeText
:
/.*/
,
action
:
{
indentAction
:
indentAction
indentAction
:
indentAction
,
outdentCurrentLine
:
outdentCurrentLine
}
}]
}));
...
...
src/vs/monaco.d.ts
浏览文件 @
3eb4e2be
...
...
@@ -4298,6 +4298,10 @@ declare module monaco.languages {
* Describe what to do with the indentation.
*/
indentAction
:
IndentAction
;
/**
* Describe whether to outdent current line.
*/
outdentCurrentLine
?:
boolean
;
/**
* Describes text to be appended after the new line and after the indentation.
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录