Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3a626d89
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,发现更多精彩内容 >>
提交
3a626d89
编写于
10月 10, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
shift+tab/shift+enter overwrite suffix when accepting a completion, #10266
上级
13dc6f18
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
20 deletion
+50
-20
src/vs/editor/contrib/suggest/suggestController.ts
src/vs/editor/contrib/suggest/suggestController.ts
+44
-15
src/vs/editor/contrib/suggest/test/suggestModel.test.ts
src/vs/editor/contrib/suggest/test/suggestModel.test.ts
+1
-1
src/vs/platform/keybinding/common/keybindingsRegistry.ts
src/vs/platform/keybinding/common/keybindingsRegistry.ts
+3
-2
src/vs/workbench/contrib/debug/browser/repl.ts
src/vs/workbench/contrib/debug/browser/repl.ts
+2
-2
未找到文件。
src/vs/editor/contrib/suggest/suggestController.ts
浏览文件 @
3a626d89
...
...
@@ -22,7 +22,7 @@ import * as nls from 'vs/nls';
import
{
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ContextKeyExpr
,
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
KeybindingWeight
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
KeybindingWeight
,
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
Context
as
SuggestContext
,
CompletionItem
}
from
'
./suggest
'
;
import
{
SuggestAlternatives
}
from
'
./suggestAlternatives
'
;
import
{
State
,
SuggestModel
}
from
'
./suggestModel
'
;
...
...
@@ -34,7 +34,7 @@ import { IdleValue } from 'vs/base/common/async';
import
{
isObject
}
from
'
vs/base/common/types
'
;
import
{
CommitCharacterController
}
from
'
./suggestCommitCharacters
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
TrackedRangeStickiness
,
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
TrackedRangeStickiness
,
ITextModel
,
IWordAtPosition
}
from
'
vs/editor/common/model
'
;
import
{
EditorOption
}
from
'
vs/editor/common/config/editorOptions
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
...
...
@@ -115,10 +115,10 @@ export class SuggestController implements IEditorContribution {
const
widget
=
this
.
_instantiationService
.
createInstance
(
SuggestWidget
,
this
.
_editor
);
this
.
_toDispose
.
add
(
widget
);
this
.
_toDispose
.
add
(
widget
.
onDidSelect
(
item
=>
this
.
_insertSuggestion
(
item
,
false
,
true
,
true
),
this
));
this
.
_toDispose
.
add
(
widget
.
onDidSelect
(
item
=>
this
.
_insertSuggestion
(
item
,
false
,
true
,
true
,
false
),
this
));
// Wire up logic to accept a suggestion on certain characters
const
commitCharacterController
=
new
CommitCharacterController
(
this
.
_editor
,
widget
,
item
=>
this
.
_insertSuggestion
(
item
,
false
,
true
,
false
));
const
commitCharacterController
=
new
CommitCharacterController
(
this
.
_editor
,
widget
,
item
=>
this
.
_insertSuggestion
(
item
,
false
,
true
,
false
,
false
));
this
.
_toDispose
.
add
(
commitCharacterController
);
this
.
_toDispose
.
add
(
this
.
_model
.
onDidSuggest
(
e
=>
{
if
(
e
.
completionModel
.
items
.
length
===
0
)
{
...
...
@@ -223,7 +223,12 @@ export class SuggestController implements IEditorContribution {
this
.
_lineSuffix
.
dispose
();
}
protected
_insertSuggestion
(
event
:
ISelectedSuggestion
|
undefined
,
keepAlternativeSuggestions
:
boolean
,
undoStopBefore
:
boolean
,
undoStopAfter
:
boolean
):
void
{
protected
_insertSuggestion
(
event
:
ISelectedSuggestion
|
undefined
,
keepAlternativeSuggestions
:
boolean
,
undoStopBefore
:
boolean
,
undoStopAfter
:
boolean
,
overwriteSuffix
:
boolean
):
void
{
if
(
!
event
||
!
event
.
item
)
{
this
.
_alternatives
.
getValue
().
reset
();
this
.
_model
.
cancel
();
...
...
@@ -237,8 +242,8 @@ export class SuggestController implements IEditorContribution {
const
model
=
this
.
_editor
.
getModel
();
const
modelVersionNow
=
model
.
getAlternativeVersionId
();
const
{
completion
:
suggestion
,
position
}
=
event
.
item
;
const
editor
Column
=
this
.
_editor
.
getPosition
().
column
;
const
columnDelta
=
editor
C
olumn
-
position
.
column
;
const
editor
Position
=
this
.
_editor
.
getPosition
()
;
const
columnDelta
=
editor
Position
.
c
olumn
-
position
.
column
;
// pushing undo stops *before* additional text edits and
// *after* the main edit
...
...
@@ -251,7 +256,7 @@ export class SuggestController implements IEditorContribution {
}
// keep item in memory
this
.
_memoryService
.
memorize
(
model
,
this
.
_editor
.
getPosition
()
,
event
.
item
);
this
.
_memoryService
.
memorize
(
model
,
editorPosition
,
event
.
item
);
let
{
insertText
}
=
suggestion
;
if
(
!
(
suggestion
.
insertTextRules
!
&
CompletionItemInsertTextRule
.
InsertAsSnippet
))
{
...
...
@@ -260,7 +265,12 @@ export class SuggestController implements IEditorContribution {
const
overwriteBefore
=
position
.
column
-
suggestion
.
range
.
startColumn
;
const
overwriteAfter
=
suggestion
.
range
.
endColumn
-
position
.
column
;
const
suffixDelta
=
this
.
_lineSuffix
.
value
?
this
.
_lineSuffix
.
value
.
delta
(
this
.
_editor
.
getPosition
())
:
0
;
let
suffixDelta
=
this
.
_lineSuffix
.
value
?
this
.
_lineSuffix
.
value
.
delta
(
position
)
:
0
;
let
word
:
IWordAtPosition
|
null
;
if
(
overwriteAfter
===
0
&&
overwriteSuffix
&&
(
word
=
model
.
getWordAtPosition
(
position
)))
{
suffixDelta
+=
word
.
endColumn
-
position
.
column
;
}
SnippetController2
.
get
(
this
.
_editor
).
insert
(
insertText
,
{
overwriteBefore
:
overwriteBefore
+
columnDelta
,
...
...
@@ -300,7 +310,7 @@ export class SuggestController implements IEditorContribution {
if
(
modelVersionNow
!==
model
.
getAlternativeVersionId
())
{
model
.
undo
();
}
this
.
_insertSuggestion
(
next
,
false
,
false
,
false
);
this
.
_insertSuggestion
(
next
,
false
,
false
,
false
,
overwriteSuffix
);
break
;
}
});
...
...
@@ -382,7 +392,7 @@ export class SuggestController implements IEditorContribution {
return
;
}
this
.
_editor
.
pushUndoStop
();
this
.
_insertSuggestion
({
index
,
item
,
model
:
completionModel
},
true
,
false
,
false
);
this
.
_insertSuggestion
({
index
,
item
,
model
:
completionModel
},
true
,
false
,
false
,
false
);
},
undefined
,
listener
);
});
...
...
@@ -392,9 +402,9 @@ export class SuggestController implements IEditorContribution {
this
.
_editor
.
focus
();
}
acceptSelectedSuggestion
(
keepAlternativeSuggestions
?
:
boolean
):
void
{
acceptSelectedSuggestion
(
keepAlternativeSuggestions
:
boolean
,
overwriteSuffix
:
boolean
):
void
{
const
item
=
this
.
_widget
.
getValue
().
getFocusedItem
();
this
.
_insertSuggestion
(
item
,
!!
keepAlternativeSuggestions
,
true
,
true
);
this
.
_insertSuggestion
(
item
,
keepAlternativeSuggestions
,
true
,
true
,
overwriteSuffix
);
}
acceptNextSuggestion
()
{
...
...
@@ -489,18 +499,37 @@ const SuggestCommand = EditorCommand.bindToContribution<SuggestController>(Sugge
registerEditorCommand
(
new
SuggestCommand
({
id
:
'
acceptSelectedSuggestion
'
,
precondition
:
SuggestContext
.
Visible
,
handler
:
x
=>
x
.
acceptSelectedSuggestion
(
true
),
kbOpts
:
{
weight
:
weight
,
kbExpr
:
EditorContextKeys
.
textInputFocus
,
primary
:
KeyCode
.
Tab
},
handler
(
x
,
args
)
{
let
overwriteSuffix
:
boolean
;
if
(
typeof
args
!==
'
object
'
)
{
overwriteSuffix
=
false
;
}
else
if
(
typeof
args
.
overwriteSuffix
!==
'
boolean
'
)
{
overwriteSuffix
=
false
;
}
else
{
overwriteSuffix
=
args
.
overwriteSuffix
;
}
x
.
acceptSelectedSuggestion
(
true
,
overwriteSuffix
);
}
}));
KeybindingsRegistry
.
registerKeybindingRule
({
id
:
'
acceptSelectedSuggestion
'
,
when
:
ContextKeyExpr
.
and
(
SuggestContext
.
Visible
,
EditorContextKeys
.
textInputFocus
),
primary
:
KeyMod
.
Shift
|
KeyCode
.
Tab
,
secondary
:
[
KeyMod
.
Shift
|
KeyCode
.
Enter
],
args
:
{
overwriteSuffix
:
true
},
weight
});
registerEditorCommand
(
new
SuggestCommand
({
id
:
'
acceptSelectedSuggestionOnEnter
'
,
precondition
:
SuggestContext
.
Visible
,
handler
:
x
=>
x
.
acceptSelectedSuggestion
(
false
),
handler
:
x
=>
x
.
acceptSelectedSuggestion
(
false
,
false
),
kbOpts
:
{
weight
:
weight
,
kbExpr
:
ContextKeyExpr
.
and
(
EditorContextKeys
.
textInputFocus
,
SuggestContext
.
AcceptSuggestionsOnEnter
,
SuggestContext
.
MakesTextEdit
),
...
...
src/vs/editor/contrib/suggest/test/suggestModel.test.ts
浏览文件 @
3a626d89
...
...
@@ -676,7 +676,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
return
withOracle
(
async
(
sugget
,
editor
)
=>
{
class
TestCtrl
extends
SuggestController
{
_insertSuggestion
(
item
:
ISelectedSuggestion
)
{
super
.
_insertSuggestion
(
item
,
false
,
true
,
true
);
super
.
_insertSuggestion
(
item
,
false
,
true
,
true
,
false
);
}
}
const
ctrl
=
<
TestCtrl
>
editor
.
registerAndInstantiateContribution
(
TestCtrl
);
...
...
src/vs/platform/keybinding/common/keybindingsRegistry.ts
浏览文件 @
3a626d89
...
...
@@ -38,6 +38,7 @@ export interface IKeybindings {
export
interface
IKeybindingRule
extends
IKeybindings
{
id
:
string
;
weight
:
number
;
args
?:
any
;
when
:
ContextKeyExpr
|
null
|
undefined
;
}
...
...
@@ -132,7 +133,7 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry {
if
(
actualKb
&&
actualKb
.
primary
)
{
const
kk
=
createKeybinding
(
actualKb
.
primary
,
OS
);
if
(
kk
)
{
this
.
_registerDefaultKeybinding
(
kk
,
rule
.
id
,
undefined
,
rule
.
weight
,
0
,
rule
.
when
);
this
.
_registerDefaultKeybinding
(
kk
,
rule
.
id
,
rule
.
args
,
rule
.
weight
,
0
,
rule
.
when
);
}
}
...
...
@@ -141,7 +142,7 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry {
const
k
=
actualKb
.
secondary
[
i
];
const
kk
=
createKeybinding
(
k
,
OS
);
if
(
kk
)
{
this
.
_registerDefaultKeybinding
(
kk
,
rule
.
id
,
undefined
,
rule
.
weight
,
-
i
-
1
,
rule
.
when
);
this
.
_registerDefaultKeybinding
(
kk
,
rule
.
id
,
rule
.
args
,
rule
.
weight
,
-
i
-
1
,
rule
.
when
);
}
}
}
...
...
src/vs/workbench/contrib/debug/browser/repl.ts
浏览文件 @
3a626d89
...
...
@@ -919,7 +919,7 @@ class AcceptReplInputAction extends EditorAction {
}
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
|
Promise
<
void
>
{
SuggestController
.
get
(
editor
).
acceptSelectedSuggestion
();
SuggestController
.
get
(
editor
).
acceptSelectedSuggestion
(
false
,
false
);
accessor
.
get
(
IPrivateReplService
).
acceptReplInput
();
}
}
...
...
@@ -941,7 +941,7 @@ class FilterReplAction extends EditorAction {
}
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
|
Promise
<
void
>
{
SuggestController
.
get
(
editor
).
acceptSelectedSuggestion
();
SuggestController
.
get
(
editor
).
acceptSelectedSuggestion
(
false
,
false
);
accessor
.
get
(
IPrivateReplService
).
focusRepl
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录