Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a8d91758
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,发现更多精彩内容 >>
未验证
提交
a8d91758
编写于
4月 23, 2020
作者:
C
Christos Pappas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use the cancellation token to trigger rename cancellation
上级
a9306b4f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
20 deletion
+21
-20
src/vs/editor/browser/core/editorState.ts
src/vs/editor/browser/core/editorState.ts
+15
-4
src/vs/editor/contrib/rename/rename.ts
src/vs/editor/contrib/rename/rename.ts
+2
-6
src/vs/editor/contrib/rename/renameInputField.ts
src/vs/editor/contrib/rename/renameInputField.ts
+4
-10
未找到文件。
src/vs/editor/browser/core/editorState.ts
浏览文件 @
a8d91758
...
...
@@ -6,7 +6,7 @@
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
ICodeEditor
,
IActiveCodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
CancellationTokenSource
,
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
IDisposable
,
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
...
...
@@ -87,19 +87,30 @@ export class EditorState {
/**
* A cancellation token source that cancels when the editor changes as expressed
* by the provided flags
* @param range If provided, changes in position and selection within this range will not trigger cancellation
*/
export
class
EditorStateCancellationTokenSource
extends
EditorKeybindingCancellationTokenSource
implements
IDisposable
{
private
readonly
_listener
=
new
DisposableStore
();
constructor
(
readonly
editor
:
IActiveCodeEditor
,
flags
:
CodeEditorStateFlag
,
parent
?:
CancellationToken
)
{
set
range
(
range
:
IRange
|
undefined
)
{
this
.
_range
=
range
;
}
constructor
(
readonly
editor
:
IActiveCodeEditor
,
flags
:
CodeEditorStateFlag
,
parent
?:
CancellationToken
,
private
_range
?:
IRange
)
{
super
(
editor
,
parent
);
if
(
flags
&
CodeEditorStateFlag
.
Position
)
{
this
.
_listener
.
add
(
editor
.
onDidChangeCursorPosition
(
_
=>
this
.
cancel
()));
this
.
_listener
.
add
(
editor
.
onDidChangeCursorPosition
(
e
=>
{
if
(
!
this
.
_range
||
!
Range
.
containsPosition
(
this
.
_range
,
e
.
position
))
{
this
.
cancel
();
}
}));
}
if
(
flags
&
CodeEditorStateFlag
.
Selection
)
{
this
.
_listener
.
add
(
editor
.
onDidChangeCursorSelection
(
_
=>
this
.
cancel
()));
this
.
_listener
.
add
(
editor
.
onDidChangeCursorSelection
(
e
=>
{
if
(
!
this
.
_range
||
!
Range
.
containsRange
(
this
.
_range
,
e
.
selection
))
{
this
.
cancel
();
}
}));
}
if
(
flags
&
CodeEditorStateFlag
.
Scroll
)
{
this
.
_listener
.
add
(
editor
.
onDidScrollChange
(
_
=>
this
.
cancel
()));
...
...
src/vs/editor/contrib/rename/rename.ts
浏览文件 @
a8d91758
...
...
@@ -173,6 +173,7 @@ class RenameController implements IEditorContribution {
let
selection
=
this
.
editor
.
getSelection
();
let
selectionStart
=
0
;
let
selectionEnd
=
loc
.
text
.
length
;
(
this
.
_cts
as
EditorStateCancellationTokenSource
).
range
=
loc
.
range
;
if
(
!
Range
.
isEmpty
(
selection
)
&&
!
Range
.
spansMultipleLines
(
selection
)
&&
Range
.
containsRange
(
loc
.
range
,
selection
))
{
selectionStart
=
Math
.
max
(
0
,
selection
.
startColumn
-
loc
.
range
.
startColumn
);
...
...
@@ -180,10 +181,7 @@ class RenameController implements IEditorContribution {
}
const
supportPreview
=
this
.
_bulkEditService
.
hasPreviewHandler
()
&&
this
.
_configService
.
getValue
<
boolean
>
(
this
.
editor
.
getModel
().
uri
,
'
editor.rename.enablePreview
'
);
// Special cancellation handling here (allows the user to move the cursor but only within loc.range):
this
.
_cts
.
dispose
(
false
);
const
inputFieldResult
=
await
this
.
_renameInputField
.
getValue
().
getInput
(
loc
.
range
,
loc
.
text
,
selectionStart
,
selectionEnd
,
supportPreview
);
const
inputFieldResult
=
await
this
.
_renameInputField
.
getValue
().
getInput
(
loc
.
range
,
loc
.
text
,
selectionStart
,
selectionEnd
,
supportPreview
,
this
.
_cts
.
token
);
// no result, only hint to focus the editor or not
if
(
typeof
inputFieldResult
===
'
boolean
'
)
{
...
...
@@ -193,8 +191,6 @@ class RenameController implements IEditorContribution {
return
undefined
;
}
this
.
_cts
=
new
EditorStateCancellationTokenSource
(
this
.
editor
,
CodeEditorStateFlag
.
Position
|
CodeEditorStateFlag
.
Value
);
this
.
editor
.
focus
();
const
renameOperation
=
raceCancellation
(
skeleton
.
provideRenameEdits
(
inputFieldResult
.
newName
,
0
,
[],
this
.
_cts
.
token
),
this
.
_cts
.
token
).
then
(
async
renameResult
=>
{
...
...
src/vs/editor/contrib/rename/renameInputField.ts
浏览文件 @
a8d91758
...
...
@@ -7,7 +7,7 @@ import 'vs/css!./renameInputField';
import
{
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
ContentWidgetPositionPreference
,
ICodeEditor
,
IContentWidget
,
IContentWidgetPosition
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
IRange
,
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
ScrollType
}
from
'
vs/editor/common/editorCommon
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
IContextKey
,
IContextKeyService
,
RawContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
...
...
@@ -16,6 +16,7 @@ import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeServic
import
{
EditorOption
}
from
'
vs/editor/common/config/editorOptions
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
toggleClass
}
from
'
vs/base/browser/dom
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
export
const
CONTEXT_RENAME_INPUT_VISIBLE
=
new
RawContextKey
<
boolean
>
(
'
renameInputVisible
'
,
false
);
...
...
@@ -149,7 +150,7 @@ export class RenameInputField implements IContentWidget {
}
}
getInput
(
where
:
IRange
,
value
:
string
,
selectionStart
:
number
,
selectionEnd
:
number
,
supportPreview
:
boolean
):
Promise
<
RenameInputFieldResult
|
boolean
>
{
getInput
(
where
:
IRange
,
value
:
string
,
selectionStart
:
number
,
selectionEnd
:
number
,
supportPreview
:
boolean
,
token
:
CancellationToken
):
Promise
<
RenameInputFieldResult
|
boolean
>
{
toggleClass
(
this
.
_domNode
!
,
'
preview
'
,
supportPreview
);
...
...
@@ -185,14 +186,7 @@ export class RenameInputField implements IContentWidget {
});
};
let
onCursorChanged
=
()
=>
{
const
editorPosition
=
this
.
_editor
.
getPosition
();
if
(
!
editorPosition
||
!
Range
.
containsPosition
(
where
,
editorPosition
))
{
this
.
cancelInput
(
true
);
}
};
disposeOnDone
.
add
(
this
.
_editor
.
onDidChangeCursorSelection
(
onCursorChanged
));
token
.
onCancellationRequested
(()
=>
this
.
cancelInput
(
true
));
disposeOnDone
.
add
(
this
.
_editor
.
onDidBlurEditorWidget
(()
=>
this
.
cancelInput
(
false
)));
this
.
_show
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录