Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
569da9e0
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,发现更多精彩内容 >>
提交
569da9e0
编写于
10月 27, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
don't use array, sorting, and array#delta but map and set, #35996
上级
ce6a0cf0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
80 addition
and
36 deletion
+80
-36
src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts
...nch/api/electron-browser/mainThreadDocumentsAndEditors.ts
+80
-36
未找到文件。
src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts
浏览文件 @
569da9e0
...
...
@@ -6,8 +6,6 @@
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModel
,
ICommonCodeEditor
,
isCommonCodeEditor
,
isCommonDiffEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
compare
}
from
'
vs/base/common/strings
'
;
import
{
delta
}
from
'
vs/base/common/arrays
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/common/services/codeEditorService
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
...
...
@@ -26,28 +24,72 @@ import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/un
import
{
IEditorGroupService
}
from
'
vs/workbench/services/group/common/groupService
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
namespace
cmp
{
export
function
compareModels
(
a
:
IModel
,
b
:
IModel
):
number
{
return
compare
(
a
.
uri
.
toString
(),
b
.
uri
.
toString
());
namespace
mapset
{
export
function
newSet
<
E
>
(
from
:
Set
<
E
>
):
Set
<
E
>
{
let
ret
=
new
Set
<
E
>
();
from
.
forEach
(
ret
.
add
,
ret
);
return
ret
;
}
export
function
compareEditors
(
a
:
EditorAndModel
,
b
:
EditorAndModel
):
number
{
let
ret
=
compare
(
a
.
editor
.
getId
(),
b
.
editor
.
getId
());
if
(
ret
===
0
)
{
ret
=
compare
(
a
.
document
.
uri
.
toString
(),
b
.
document
.
uri
.
toString
());
}
export
function
setValues
<
T
>
(
set
:
Set
<
T
>
):
T
[]
{
// return Array.from(set);
let
ret
:
T
[]
=
[];
set
.
forEach
(
v
=>
ret
.
push
(
v
));
return
ret
;
}
export
function
mapValues
<
T
>
(
map
:
Map
<
any
,
T
>
):
T
[]
{
// return Array.from(map.values());
let
ret
:
T
[]
=
[];
map
.
forEach
(
v
=>
ret
.
push
(
v
));
return
ret
;
}
}
class
EditorAndModel
{
namespace
delta
{
export
function
ofSets
<
T
>
(
before
:
Set
<
T
>
,
after
:
Set
<
T
>
):
{
removed
:
T
[],
added
:
T
[]
}
{
const
removed
:
T
[]
=
[];
const
added
:
T
[]
=
[];
before
.
forEach
(
element
=>
{
if
(
!
after
.
has
(
element
))
{
removed
.
push
(
element
);
}
});
after
.
forEach
(
element
=>
{
if
(
!
before
.
has
(
element
))
{
added
.
push
(
element
);
}
});
return
{
removed
,
added
};
};
export
function
ofMaps
<
K
,
V
>
(
before
:
Map
<
K
,
V
>
,
after
:
Map
<
K
,
V
>
):
{
removed
:
V
[],
added
:
V
[]
}
{
const
removed
:
V
[]
=
[];
const
added
:
V
[]
=
[];
before
.
forEach
((
value
,
index
)
=>
{
if
(
!
after
.
has
(
index
))
{
removed
.
push
(
value
);
}
});
after
.
forEach
((
value
,
index
)
=>
{
if
(
!
before
.
has
(
index
))
{
added
.
push
(
value
);
}
});
return
{
removed
,
added
};
};
}
class
EditorSnapshot
{
readonly
id
:
string
;
constructor
(
readonly
editor
:
ICommonCodeEditor
,
readonly
document
:
IModel
,
)
{
this
.
id
=
`
${
editor
.
getId
()}
,
${
document
.
uri
.
toString
()
}
`
;
this
.
id
=
`
${
editor
.
getId
()}
,
${
editor
.
getModel
().
id
}
`
;
}
}
...
...
@@ -58,8 +100,8 @@ class DocumentAndEditorStateDelta {
constructor
(
readonly
removedDocuments
:
IModel
[],
readonly
addedDocuments
:
IModel
[],
readonly
removedEditors
:
Editor
AndModel
[],
readonly
addedEditors
:
Editor
AndModel
[],
readonly
removedEditors
:
Editor
Snapshot
[],
readonly
addedEditors
:
Editor
Snapshot
[],
readonly
oldActiveEditor
:
string
,
readonly
newActiveEditor
:
string
,
)
{
...
...
@@ -85,10 +127,14 @@ class DocumentAndEditorState {
static
compute
(
before
:
DocumentAndEditorState
,
after
:
DocumentAndEditorState
):
DocumentAndEditorStateDelta
{
if
(
!
before
)
{
return
new
DocumentAndEditorStateDelta
([],
after
.
documents
,
[],
after
.
editors
,
undefined
,
after
.
activeEditor
);
return
new
DocumentAndEditorStateDelta
(
[],
mapset
.
setValues
(
after
.
documents
),
[],
mapset
.
mapValues
(
after
.
editors
),
undefined
,
after
.
activeEditor
);
}
const
documentDelta
=
delta
(
before
.
documents
,
after
.
documents
,
cmp
.
compareModel
s
);
const
editorDelta
=
delta
(
before
.
editors
,
after
.
editors
,
cmp
.
compareE
ditors
);
const
documentDelta
=
delta
.
ofSets
(
before
.
documents
,
after
.
document
s
);
const
editorDelta
=
delta
.
ofMaps
(
before
.
editors
,
after
.
e
ditors
);
const
oldActiveEditor
=
before
.
activeEditor
!==
after
.
activeEditor
?
before
.
activeEditor
:
undefined
;
const
newActiveEditor
=
before
.
activeEditor
!==
after
.
activeEditor
?
after
.
activeEditor
:
undefined
;
...
...
@@ -100,12 +146,11 @@ class DocumentAndEditorState {
}
constructor
(
readonly
documents
:
IModel
[]
,
readonly
editors
:
EditorAndModel
[]
,
readonly
documents
:
Set
<
IModel
>
,
readonly
editors
:
Map
<
string
,
EditorSnapshot
>
,
readonly
activeEditor
:
string
,
)
{
this
.
documents
=
documents
.
sort
(
cmp
.
compareModels
);
this
.
editors
=
editors
.
sort
(
cmp
.
compareEditors
);
//
}
}
...
...
@@ -154,16 +199,16 @@ class MainThreadDocumentAndEditorStateComputer {
private
_updateState
():
void
{
// models: ignore too large models
const
models
=
this
.
_modelService
.
getModels
();
for
(
let
i
=
0
;
i
<
models
.
length
;
i
++
)
{
if
(
models
[
i
].
isTooLargeForHavingARichMode
())
{
models
.
splice
(
i
,
1
);
i
--
;
const
models
=
new
Set
<
IModel
>
();
for
(
const
model
of
this
.
_modelService
.
getModels
())
{
if
(
!
model
.
isTooLargeForHavingARichMode
())
{
models
.
add
(
model
);
}
}
// editor: only take those that have a not too large model
const
editors
:
EditorAndModel
[]
=
[]
;
const
editors
=
new
Map
<
string
,
EditorSnapshot
>
()
;
let
activeEditor
:
string
=
null
;
for
(
const
editor
of
this
.
_codeEditorService
.
listCodeEditors
())
{
...
...
@@ -172,8 +217,8 @@ class MainThreadDocumentAndEditorStateComputer {
&&
!
model
.
isDisposed
()
// model disposed
&&
Boolean
(
this
.
_modelService
.
getModel
(
model
.
uri
))
// model disposing, the flag didn't flip yet but the model service already removed it
)
{
const
apiEditor
=
new
Editor
AndModel
(
editor
,
model
);
editors
.
push
(
apiEditor
);
const
apiEditor
=
new
Editor
Snapshot
(
editor
);
editors
.
set
(
apiEditor
.
id
,
apiEditor
);
if
(
editor
.
isFocused
())
{
activeEditor
=
apiEditor
.
id
;
}
...
...
@@ -194,12 +239,11 @@ class MainThreadDocumentAndEditorStateComputer {
candidate
=
workbenchEditorControl
.
getModifiedEditor
();
}
if
(
candidate
)
{
for
(
const
{
editor
,
id
}
of
editors
)
{
if
(
candidate
===
editor
)
{
activeEditor
=
id
;
break
;
editors
.
forEach
(
snapshot
=>
{
if
(
candidate
===
snapshot
.
editor
)
{
activeEditor
=
snapshot
.
id
;
}
}
}
);
}
}
}
...
...
@@ -282,7 +326,7 @@ export class MainThreadDocumentsAndEditors {
// added editors
for
(
const
apiEditor
of
delta
.
addedEditors
)
{
const
mainThreadEditor
=
new
MainThreadTextEditor
(
apiEditor
.
id
,
apiEditor
.
document
,
const
mainThreadEditor
=
new
MainThreadTextEditor
(
apiEditor
.
id
,
apiEditor
.
editor
.
getModel
()
,
apiEditor
.
editor
,
{
onGainedFocus
()
{
},
onLostFocus
()
{
}
},
this
.
_modelService
);
this
.
_editors
[
apiEditor
.
id
]
=
mainThreadEditor
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录