Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9f896956
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,发现更多精彩内容 >>
提交
9f896956
编写于
5月 22, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Have all cursor state changes go through the same _emitStateChangedIfNecessary method
上级
d02524ff
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
35 deletion
+51
-35
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+47
-35
src/vs/editor/common/controller/cursorCommon.ts
src/vs/editor/common/controller/cursorCommon.ts
+4
-0
未找到文件。
src/vs/editor/common/controller/cursor.ts
浏览文件 @
9f896956
...
...
@@ -53,6 +53,38 @@ export class CursorStateChangedEvent {
}
}
/**
* A snapshot of the cursor and the model state
*/
class
CursorModelState
{
public
readonly
modelVersionId
:
number
;
public
readonly
cursorState
:
CursorState
[];
constructor
(
model
:
editorCommon
.
IModel
,
cursor
:
Cursor
)
{
this
.
modelVersionId
=
model
.
getVersionId
();
this
.
cursorState
=
cursor
.
getAll
();
}
public
equals
(
other
:
CursorModelState
):
boolean
{
if
(
!
other
)
{
return
false
;
}
if
(
this
.
modelVersionId
!==
other
.
modelVersionId
)
{
return
false
;
}
if
(
this
.
cursorState
.
length
!==
other
.
cursorState
.
length
)
{
return
false
;
}
for
(
let
i
=
0
,
len
=
this
.
cursorState
.
length
;
i
<
len
;
i
++
)
{
if
(
!
this
.
cursorState
[
i
].
equals
(
other
.
cursorState
[
i
]))
{
return
false
;
}
}
return
true
;
}
}
export
class
Cursor
extends
viewEvents
.
ViewEventEmitter
implements
ICursors
{
private
readonly
_onDidChange
:
Emitter
<
CursorStateChangedEvent
>
=
this
.
_register
(
new
Emitter
<
CursorStateChangedEvent
>
());
...
...
@@ -154,40 +186,14 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return
this
.
_cursors
.
getAll
();
}
private
static
_somethingChanged
(
oldSelections
:
Selection
[],
oldViewSelections
:
Selection
[],
newSelections
:
Selection
[],
newViewSelections
:
Selection
[]):
boolean
{
if
(
oldSelections
.
length
!==
newSelections
.
length
)
{
return
true
;
}
for
(
let
i
=
0
,
len
=
oldSelections
.
length
;
i
<
len
;
i
++
)
{
if
(
!
oldSelections
[
i
].
equalsSelection
(
newSelections
[
i
]))
{
return
true
;
}
}
for
(
let
i
=
0
,
len
=
oldViewSelections
.
length
;
i
<
len
;
i
++
)
{
if
(
!
oldViewSelections
[
i
].
equalsSelection
(
newViewSelections
[
i
]))
{
return
true
;
}
}
return
false
;
}
public
setStates
(
source
:
string
,
reason
:
CursorChangeReason
,
states
:
CursorState
[]):
void
{
const
oldSelections
=
this
.
_cursors
.
getSelections
();
const
oldViewSelections
=
this
.
_cursors
.
getViewSelections
();
const
oldState
=
new
CursorModelState
(
this
.
_model
,
this
);
this
.
_cursors
.
setStates
(
states
);
this
.
_cursors
.
normalize
();
this
.
_columnSelectData
=
null
;
const
newSelections
=
this
.
_cursors
.
getSelections
();
const
newViewSelections
=
this
.
_cursors
.
getViewSelections
();
if
(
Cursor
.
_somethingChanged
(
oldSelections
,
oldViewSelections
,
newSelections
,
newViewSelections
))
{
this
.
_emitStateChanged
(
source
,
reason
);
}
this
.
_emitStateChangedIfNecessary
(
source
,
reason
,
oldState
);
}
public
setColumnSelectData
(
columnSelectData
:
IColumnSelectData
):
void
{
...
...
@@ -279,7 +285,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this
.
_cursors
.
dispose
();
this
.
_cursors
=
new
CursorCollection
(
this
.
context
);
this
.
_emitStateChanged
(
'
model
'
,
CursorChangeReason
.
ContentFlush
);
this
.
_emitStateChanged
IfNecessary
(
'
model
'
,
CursorChangeReason
.
ContentFlush
,
null
);
}
else
{
const
selectionsFromMarkers
=
this
.
_cursors
.
readSelectionFromMarkers
();
this
.
setStates
(
'
modelChange
'
,
CursorChangeReason
.
RecoverFromMarkers
,
CursorState
.
fromModelSelections
(
selectionsFromMarkers
));
...
...
@@ -356,6 +362,16 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
// -----------------------------------------------------------------------------------------------------------
// ----- emitting events
private
_emitStateChangedIfNecessary
(
source
:
string
,
reason
:
CursorChangeReason
,
oldState
:
CursorModelState
):
boolean
{
const
newState
=
new
CursorModelState
(
this
.
_model
,
this
);
if
(
newState
.
equals
(
oldState
))
{
return
false
;
}
this
.
_emitStateChanged
(
source
,
reason
);
return
true
;
}
private
_emitStateChanged
(
source
:
string
,
reason
:
CursorChangeReason
):
void
{
source
=
source
||
'
keyboard
'
;
...
...
@@ -436,8 +452,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return
;
}
const
oldSelections
=
this
.
_cursors
.
getSelections
();
const
oldViewSelections
=
this
.
_cursors
.
getViewSelections
();
const
oldState
=
new
CursorModelState
(
this
.
_model
,
this
);
let
cursorChangeReason
=
CursorChangeReason
.
NotSet
;
// ensure valid state on all cursors
...
...
@@ -488,10 +503,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this
.
_isHandling
=
false
;
const
newSelections
=
this
.
_cursors
.
getSelections
();
const
newViewSelections
=
this
.
_cursors
.
getViewSelections
();
if
(
Cursor
.
_somethingChanged
(
oldSelections
,
oldViewSelections
,
newSelections
,
newViewSelections
))
{
this
.
_emitStateChanged
(
source
,
cursorChangeReason
);
if
(
this
.
_emitStateChangedIfNecessary
(
source
,
cursorChangeReason
,
oldState
))
{
this
.
_revealRange
(
RevealTarget
.
Primary
,
viewEvents
.
VerticalRevealType
.
Simple
,
true
);
}
}
...
...
src/vs/editor/common/controller/cursorCommon.ts
浏览文件 @
9f896956
...
...
@@ -411,6 +411,10 @@ export class CursorState {
this
.
modelState
=
modelState
;
this
.
viewState
=
viewState
;
}
public
equals
(
other
:
CursorState
):
boolean
{
return
(
this
.
viewState
.
equals
(
other
.
viewState
)
&&
this
.
modelState
.
equals
(
other
.
viewState
));
}
}
export
class
EditOperationResult
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录