Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
edcae85f
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,发现更多精彩内容 >>
提交
edcae85f
编写于
8月 26, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #26012
上级
5974d06e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
49 addition
and
6 deletion
+49
-6
src/vs/editor/contrib/suggest/suggestController.ts
src/vs/editor/contrib/suggest/suggestController.ts
+46
-4
src/vs/editor/contrib/suggest/suggestModel.ts
src/vs/editor/contrib/suggest/suggestModel.ts
+3
-2
未找到文件。
src/vs/editor/contrib/suggest/suggestController.ts
浏览文件 @
edcae85f
...
...
@@ -7,7 +7,7 @@ import { alert } from 'vs/base/browser/ui/aria/aria';
import
{
isNonEmptyArray
}
from
'
vs/base/common/arrays
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
dispose
,
IDisposable
,
DisposableStore
,
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
dispose
,
IDisposable
,
DisposableStore
,
toDisposable
,
MutableDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
EditorAction
,
EditorCommand
,
registerEditorAction
,
registerEditorCommand
,
registerEditorContribution
,
ServicesAccessor
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
...
...
@@ -33,9 +33,49 @@ import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerServ
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
'
;
const
_sticky
=
false
;
// for development purposes only
class
LineSuffix
{
private
readonly
_marker
:
string
[]
|
undefined
;
constructor
(
private
readonly
_model
:
ITextModel
,
private
readonly
_position
:
IPosition
)
{
// spy on what's happening right of the cursor. two cases:
// 1. end of line -> check that it's still end of line
// 2. mid of line -> add a marker and compute the delta
const
maxColumn
=
_model
.
getLineMaxColumn
(
_position
.
lineNumber
);
if
(
maxColumn
!==
_position
.
column
)
{
const
offset
=
_model
.
getOffsetAt
(
_position
);
const
end
=
_model
.
getPositionAt
(
offset
+
1
);
this
.
_marker
=
_model
.
deltaDecorations
([],
[{
range
:
Range
.
fromPositions
(
_position
,
end
),
options
:
{
stickiness
:
TrackedRangeStickiness
.
NeverGrowsWhenTypingAtEdges
}
}]);
}
}
dispose
():
void
{
if
(
this
.
_marker
)
{
this
.
_model
.
deltaDecorations
(
this
.
_marker
,
[]);
}
}
delta
(
position
:
IPosition
):
number
{
if
(
this
.
_position
.
lineNumber
!==
position
.
lineNumber
)
{
return
0
;
}
else
if
(
this
.
_marker
)
{
const
range
=
this
.
_model
.
getDecorationRange
(
this
.
_marker
[
0
]);
const
end
=
this
.
_model
.
getOffsetAt
(
range
!
.
getStartPosition
());
return
end
-
this
.
_model
.
getOffsetAt
(
position
);
}
else
{
return
this
.
_model
.
getLineMaxColumn
(
position
.
lineNumber
)
-
position
.
column
;
}
}
}
export
class
SuggestController
implements
IEditorContribution
{
private
static
readonly
ID
:
string
=
'
editor.contrib.suggestController
'
;
...
...
@@ -47,9 +87,9 @@ export class SuggestController implements IEditorContribution {
private
readonly
_model
:
SuggestModel
;
private
readonly
_widget
:
IdleValue
<
SuggestWidget
>
;
private
readonly
_alternatives
:
IdleValue
<
SuggestAlternatives
>
;
private
readonly
_lineSuffix
=
new
MutableDisposable
<
LineSuffix
>
();
private
readonly
_toDispose
=
new
DisposableStore
();
constructor
(
private
_editor
:
ICodeEditor
,
@
IEditorWorkerService
editorWorker
:
IEditorWorkerService
,
...
...
@@ -115,6 +155,7 @@ export class SuggestController implements IEditorContribution {
this
.
_toDispose
.
add
(
this
.
_model
.
onDidTrigger
(
e
=>
{
this
.
_widget
.
getValue
().
showTriggered
(
e
.
auto
,
e
.
shy
?
250
:
50
);
this
.
_lineSuffix
.
value
=
new
LineSuffix
(
this
.
_editor
.
getModel
()
!
,
e
.
position
);
}));
this
.
_toDispose
.
add
(
this
.
_model
.
onDidSuggest
(
e
=>
{
if
(
!
e
.
shy
)
{
...
...
@@ -123,7 +164,7 @@ export class SuggestController implements IEditorContribution {
}
}));
this
.
_toDispose
.
add
(
this
.
_model
.
onDidCancel
(
e
=>
{
if
(
this
.
_widget
&&
!
e
.
retrigger
)
{
if
(
!
e
.
retrigger
)
{
this
.
_widget
.
getValue
().
hideWidget
();
}
}));
...
...
@@ -154,6 +195,7 @@ export class SuggestController implements IEditorContribution {
this
.
_toDispose
.
dispose
();
this
.
_widget
.
dispose
();
this
.
_model
.
dispose
();
this
.
_lineSuffix
.
dispose
();
}
protected
_insertSuggestion
(
event
:
ISelectedSuggestion
|
undefined
,
keepAlternativeSuggestions
:
boolean
,
undoStops
:
boolean
):
void
{
...
...
@@ -192,7 +234,7 @@ export class SuggestController implements IEditorContribution {
}
const
overwriteBefore
=
position
.
column
-
suggestion
.
range
.
startColumn
;
const
overwriteAfter
=
suggestion
.
range
.
endColumn
-
position
.
column
;
const
overwriteAfter
=
(
suggestion
.
range
.
endColumn
-
position
.
column
)
+
this
.
_lineSuffix
.
value
!
.
delta
(
this
.
_editor
.
getPosition
())
;
SnippetController2
.
get
(
this
.
_editor
).
insert
(
insertText
,
{
overwriteBefore
:
overwriteBefore
+
columnDelta
,
...
...
src/vs/editor/contrib/suggest/suggestModel.ts
浏览文件 @
edcae85f
...
...
@@ -10,7 +10,7 @@ import { Emitter, Event } from 'vs/base/common/event';
import
{
IDisposable
,
dispose
,
DisposableStore
,
isDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
CursorChangeReason
,
ICursorSelectionChangedEvent
}
from
'
vs/editor/common/controller/cursorEvents
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Position
,
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
ITextModel
,
IWordAtPosition
}
from
'
vs/editor/common/model
'
;
import
{
CompletionItemProvider
,
StandardTokenType
,
CompletionContext
,
CompletionProviderRegistry
,
CompletionTriggerKind
,
CompletionItemKind
,
completionKindFromString
}
from
'
vs/editor/common/modes
'
;
...
...
@@ -28,6 +28,7 @@ export interface ICancelEvent {
export
interface
ITriggerEvent
{
readonly
auto
:
boolean
;
readonly
shy
:
boolean
;
readonly
position
:
IPosition
;
}
export
interface
ISuggestEvent
{
...
...
@@ -365,7 +366,7 @@ export class SuggestModel implements IDisposable {
// Cancel previous requests, change state & update UI
this
.
cancel
(
retrigger
);
this
.
_state
=
auto
?
State
.
Auto
:
State
.
Manual
;
this
.
_onDidTrigger
.
fire
({
auto
,
shy
:
context
.
shy
});
this
.
_onDidTrigger
.
fire
({
auto
,
shy
:
context
.
shy
,
position
:
this
.
_editor
.
getPosition
()
});
// Capture context when request was sent
this
.
_context
=
ctx
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录