Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6d439732
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,发现更多精彩内容 >>
未验证
提交
6d439732
编写于
11月 18, 2020
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce diff
上级
2a499549
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
62 deletion
+87
-62
src/vs/editor/common/controller/cursorWordOperations.ts
src/vs/editor/common/controller/cursorWordOperations.ts
+70
-44
src/vs/editor/contrib/wordOperations/wordOperations.ts
src/vs/editor/contrib/wordOperations/wordOperations.ts
+17
-18
未找到文件。
src/vs/editor/common/controller/cursorWordOperations.ts
浏览文件 @
6d439732
...
@@ -374,24 +374,43 @@ export class WordOperations {
...
@@ -374,24 +374,43 @@ export class WordOperations {
return
null
;
return
null
;
}
}
protected
static
_determineDeleteRange
(
wordSeparators
:
WordCharacterClassifier
,
model
:
ICursorSimpleModel
,
wordNavigationType
:
WordNavigationType
,
position
:
Position
,
isEntire
:
boolean
):
Range
{
public
static
deleteWordLeft
(
ctx
:
DeleteWordContext
,
wordNavigationType
:
WordNavigationType
):
Range
|
null
{
const
wordSeparators
=
ctx
.
wordSeparators
;
const
model
=
ctx
.
model
;
const
selection
=
ctx
.
selection
;
const
whitespaceHeuristics
=
ctx
.
whitespaceHeuristics
;
if
(
!
selection
.
isEmpty
())
{
return
selection
;
}
if
(
DeleteOperations
.
isAutoClosingPairDelete
(
ctx
.
autoClosingBrackets
,
ctx
.
autoClosingQuotes
,
ctx
.
autoClosingPairs
.
autoClosingPairsOpenByEnd
,
ctx
.
model
,
[
ctx
.
selection
]))
{
const
position
=
ctx
.
selection
.
getPosition
();
return
new
Range
(
position
.
lineNumber
,
position
.
column
-
1
,
position
.
lineNumber
,
position
.
column
+
1
);
}
const
position
=
new
Position
(
selection
.
positionLineNumber
,
selection
.
positionColumn
);
let
lineNumber
=
position
.
lineNumber
;
let
lineNumber
=
position
.
lineNumber
;
let
column
=
position
.
column
;
let
column
=
position
.
column
;
let
columnEnd
=
position
.
column
;
let
lineContent
=
model
.
getLineContent
(
position
.
lineNumber
);
if
(
lineNumber
===
1
&&
column
===
1
)
{
// Ignore deleting at beginning of file
return
null
;
}
if
(
whitespaceHeuristics
)
{
let
r
=
this
.
_deleteWordLeftWhitespace
(
model
,
position
);
if
(
r
)
{
return
r
;
}
}
let
prevWordOnLine
=
WordOperations
.
_findPreviousWordOnLine
(
wordSeparators
,
model
,
position
);
let
prevWordOnLine
=
WordOperations
.
_findPreviousWordOnLine
(
wordSeparators
,
model
,
position
);
if
(
wordNavigationType
===
WordNavigationType
.
WordStart
)
{
if
(
wordNavigationType
===
WordNavigationType
.
WordStart
)
{
if
(
prevWordOnLine
)
{
if
(
prevWordOnLine
)
{
column
=
prevWordOnLine
.
start
+
1
;
column
=
prevWordOnLine
.
start
+
1
;
if
(
isEntire
)
{
columnEnd
=
prevWordOnLine
.
end
+
1
;
const
chCode
=
lineContent
.
charCodeAt
(
columnEnd
-
1
);
if
(
chCode
===
CharCode
.
Space
||
chCode
===
CharCode
.
Tab
)
{
columnEnd
++
;
}
}
}
else
{
}
else
{
if
(
column
>
1
)
{
if
(
column
>
1
)
{
column
=
1
;
column
=
1
;
...
@@ -416,11 +435,10 @@ export class WordOperations {
...
@@ -416,11 +435,10 @@ export class WordOperations {
}
}
}
}
return
new
Range
(
lineNumber
,
column
,
position
.
lineNumber
,
columnEnd
);
return
new
Range
(
lineNumber
,
column
,
position
.
lineNumber
,
position
.
column
);
}
}
public
static
deleteWordEntire
(
ctx
:
DeleteWordContext
,
wordNavigationType
:
WordNavigationType
):
Range
|
null
{
public
static
deleteWordLeft
(
ctx
:
DeleteWordContext
,
wordNavigationType
:
WordNavigationType
):
Range
|
null
{
const
wordSeparators
=
ctx
.
wordSeparators
;
const
wordSeparators
=
ctx
.
wordSeparators
;
const
model
=
ctx
.
model
;
const
model
=
ctx
.
model
;
const
selection
=
ctx
.
selection
;
const
selection
=
ctx
.
selection
;
...
@@ -446,17 +464,16 @@ export class WordOperations {
...
@@ -446,17 +464,16 @@ export class WordOperations {
}
}
if
(
whitespaceHeuristics
)
{
if
(
whitespaceHeuristics
)
{
let
r
=
this
.
_deleteWord
Left
Whitespace
(
model
,
position
);
let
r
=
this
.
_deleteWord
Entire
Whitespace
(
model
,
position
);
if
(
r
)
{
if
(
r
)
{
return
r
;
return
r
;
}
}
}
}
return
this
.
_determineDeleteRange
(
wordSeparators
,
model
,
wordNavigationType
,
position
,
fals
e
);
return
this
.
_determineDeleteRange
(
wordSeparators
,
model
,
wordNavigationType
,
position
,
tru
e
);
}
}
private
static
_deleteWordEntireWhitespace
(
model
:
ICursorSimpleModel
,
position
:
Position
):
Range
|
null
{
protected
static
_deleteWordEntireWhitespace
(
model
:
ICursorSimpleModel
,
position
:
Position
):
Range
|
null
{
const
lineContent
=
model
.
getLineContent
(
position
.
lineNumber
);
const
lineContent
=
model
.
getLineContent
(
position
.
lineNumber
);
const
startIndex1
=
position
.
column
-
1
;
// deleteRight
const
startIndex1
=
position
.
column
-
1
;
// deleteRight
const
startIndex2
=
position
.
column
-
2
;
// deleteLeft
const
startIndex2
=
position
.
column
-
2
;
// deleteLeft
...
@@ -468,40 +485,49 @@ export class WordOperations {
...
@@ -468,40 +485,49 @@ export class WordOperations {
return
null
;
return
null
;
}
}
private
static
_determineDeleteRange
(
wordSeparators
:
WordCharacterClassifier
,
model
:
ICursorSimpleModel
,
wordNavigationType
:
WordNavigationType
,
position
:
Position
,
isEntire
:
boolean
):
Range
{
public
static
deleteWordEntire
(
ctx
:
DeleteWordContext
,
wordNavigationType
:
WordNavigationType
):
Range
|
null
{
const
wordSeparators
=
ctx
.
wordSeparators
;
const
model
=
ctx
.
model
;
const
selection
=
ctx
.
selection
;
const
whitespaceHeuristics
=
ctx
.
whitespaceHeuristics
;
if
(
!
selection
.
isEmpty
())
{
return
selection
;
}
if
(
DeleteOperations
.
isAutoClosingPairDelete
(
ctx
.
autoClosingBrackets
,
ctx
.
autoClosingQuotes
,
ctx
.
autoClosingPairs
.
autoClosingPairsOpen
,
ctx
.
model
,
[
ctx
.
selection
]))
{
const
position
=
ctx
.
selection
.
getPosition
();
return
new
Range
(
position
.
lineNumber
,
position
.
column
-
1
,
position
.
lineNumber
,
position
.
column
+
1
);
}
const
position
=
new
Position
(
selection
.
positionLineNumber
,
selection
.
positionColumn
);
let
lineNumber
=
position
.
lineNumber
;
let
lineNumber
=
position
.
lineNumber
;
let
column
=
position
.
column
;
let
column
=
position
.
column
;
let
columnEnd
=
position
.
column
;
let
lineContent
=
model
.
getLineContent
(
position
.
lineNumber
);
if
(
lineNumber
===
1
&&
column
===
1
)
{
let
prevWordOnLine
=
WordOperations
.
_findPreviousWordOnLine
(
wordSeparators
,
model
,
position
);
// Ignore deleting at beginning of file
return
null
;
}
if
(
whitespaceHeuristics
)
{
if
(
wordNavigationType
===
WordNavigationType
.
WordStart
)
{
let
r
=
this
.
_deleteWordEntireWhitespace
(
model
,
position
);
if
(
prevWordOnLine
)
{
if
(
r
)
{
column
=
prevWordOnLine
.
start
+
1
;
return
r
;
if
(
isEntire
)
{
columnEnd
=
prevWordOnLine
.
end
+
1
;
const
chCode
=
lineContent
.
charCodeAt
(
columnEnd
-
1
);
if
(
chCode
===
CharCode
.
Space
||
chCode
===
CharCode
.
Tab
)
{
columnEnd
++
;
}
}
}
else
{
if
(
column
>
1
)
{
column
=
1
;
}
else
{
lineNumber
--
;
column
=
model
.
getLineMaxColumn
(
lineNumber
);
}
}
}
else
{
if
(
prevWordOnLine
&&
column
<=
prevWordOnLine
.
end
+
1
)
{
prevWordOnLine
=
WordOperations
.
_findPreviousWordOnLine
(
wordSeparators
,
model
,
new
Position
(
lineNumber
,
prevWordOnLine
.
start
+
1
));
}
if
(
prevWordOnLine
)
{
column
=
prevWordOnLine
.
end
+
1
;
}
else
{
if
(
column
>
1
)
{
column
=
1
;
}
else
{
lineNumber
--
;
column
=
model
.
getLineMaxColumn
(
lineNumber
);
}
}
}
}
}
return
this
.
_determineDeleteRange
(
wordSeparators
,
model
,
wordNavigationType
,
position
,
true
);
return
new
Range
(
lineNumber
,
column
,
position
.
lineNumber
,
columnEnd
);
}
}
public
static
_deleteWordPartLeft
(
model
:
ICursorSimpleModel
,
selection
:
Selection
):
Range
{
public
static
_deleteWordPartLeft
(
model
:
ICursorSimpleModel
,
selection
:
Selection
):
Range
{
...
...
src/vs/editor/contrib/wordOperations/wordOperations.ts
浏览文件 @
6d439732
...
@@ -402,23 +402,6 @@ export class DeleteWordRightCommand extends DeleteWordCommand {
...
@@ -402,23 +402,6 @@ export class DeleteWordRightCommand extends DeleteWordCommand {
}
}
}
}
export
class
DeleteWordRight
extends
DeleteWordRightCommand
{
constructor
()
{
super
({
whitespaceHeuristics
:
true
,
wordNavigationType
:
WordNavigationType
.
WordEnd
,
id
:
'
deleteWordRight
'
,
precondition
:
EditorContextKeys
.
writable
,
kbOpts
:
{
kbExpr
:
EditorContextKeys
.
textInputFocus
,
primary
:
KeyMod
.
CtrlCmd
|
KeyCode
.
Delete
,
mac
:
{
primary
:
KeyMod
.
Alt
|
KeyCode
.
Delete
},
weight
:
KeybindingWeight
.
EditorContrib
}
});
}
}
export
class
DeleteWordStartLeft
extends
DeleteWordLeftCommand
{
export
class
DeleteWordStartLeft
extends
DeleteWordLeftCommand
{
constructor
()
{
constructor
()
{
super
({
super
({
...
@@ -480,6 +463,23 @@ export class DeleteWordEndRight extends DeleteWordRightCommand {
...
@@ -480,6 +463,23 @@ export class DeleteWordEndRight extends DeleteWordRightCommand {
}
}
}
}
export
class
DeleteWordRight
extends
DeleteWordRightCommand
{
constructor
()
{
super
({
whitespaceHeuristics
:
true
,
wordNavigationType
:
WordNavigationType
.
WordEnd
,
id
:
'
deleteWordRight
'
,
precondition
:
EditorContextKeys
.
writable
,
kbOpts
:
{
kbExpr
:
EditorContextKeys
.
textInputFocus
,
primary
:
KeyMod
.
CtrlCmd
|
KeyCode
.
Delete
,
mac
:
{
primary
:
KeyMod
.
Alt
|
KeyCode
.
Delete
},
weight
:
KeybindingWeight
.
EditorContrib
}
});
}
}
export
class
DeleteWordEntireCommand
extends
DeleteWordCommand
{
export
class
DeleteWordEntireCommand
extends
DeleteWordCommand
{
protected
_delete
(
ctx
:
DeleteWordContext
,
wordNavigationType
:
WordNavigationType
):
Range
{
protected
_delete
(
ctx
:
DeleteWordContext
,
wordNavigationType
:
WordNavigationType
):
Range
{
let
r
=
WordOperations
.
deleteWordEntire
(
ctx
,
wordNavigationType
);
let
r
=
WordOperations
.
deleteWordEntire
(
ctx
,
wordNavigationType
);
...
@@ -509,7 +509,6 @@ export class DeleteWordEntire extends DeleteWordEntireCommand {
...
@@ -509,7 +509,6 @@ export class DeleteWordEntire extends DeleteWordEntireCommand {
}
}
}
}
registerEditorCommand
(
new
CursorWordStartLeft
());
registerEditorCommand
(
new
CursorWordStartLeft
());
registerEditorCommand
(
new
CursorWordEndLeft
());
registerEditorCommand
(
new
CursorWordEndLeft
());
registerEditorCommand
(
new
CursorWordLeft
());
registerEditorCommand
(
new
CursorWordLeft
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录