Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
3c509087
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3c509087
编写于
2月 12, 2016
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[folding] store folding state as view state
上级
40635574
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
123 addition
and
62 deletion
+123
-62
src/vs/editor/browser/widget/codeEditorWidget.ts
src/vs/editor/browser/widget/codeEditorWidget.ts
+18
-1
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+9
-0
src/vs/editor/contrib/folding/browser/folding.ts
src/vs/editor/contrib/folding/browser/folding.ts
+94
-60
src/vs/editor/contrib/folding/common/foldingRange.ts
src/vs/editor/contrib/folding/common/foldingRange.ts
+2
-1
未找到文件。
src/vs/editor/browser/widget/codeEditorWidget.ts
浏览文件 @
3c509087
...
...
@@ -181,11 +181,20 @@ export class CodeEditorWidget extends CommonCodeEditor implements EditorBrowser.
if
(
!
this
.
cursor
||
!
this
.
hasView
)
{
return
null
;
}
let
contributionsState
:
{[
key
:
string
]:
any
}
=
{};
for
(
let
id
in
this
.
contributions
)
{
let
contribution
=
this
.
contributions
[
id
];
if
(
typeof
contribution
.
saveViewState
===
'
function
'
)
{
contributionsState
[
id
]
=
contribution
.
saveViewState
();
}
}
var
cursorState
=
this
.
cursor
.
saveState
();
var
viewState
=
this
.
_view
.
saveState
();
return
{
cursorState
:
cursorState
,
viewState
:
viewState
viewState
:
viewState
,
contributionsState
:
contributionsState
};
}
...
...
@@ -204,6 +213,14 @@ export class CodeEditorWidget extends CommonCodeEditor implements EditorBrowser.
this
.
cursor
.
restoreState
([
<
EditorCommon
.
ICursorState
>
cursorState
]);
}
this
.
_view
.
restoreState
(
codeEditorState
.
viewState
);
let
contributionsState
=
s
.
contributionsState
||
{};
for
(
let
id
in
this
.
contributions
)
{
let
contribution
=
this
.
contributions
[
id
];
if
(
typeof
contribution
.
restoreViewState
===
'
function
'
)
{
contribution
.
restoreViewState
(
contributionsState
[
id
]);
}
}
}
}
...
...
src/vs/editor/common/editorCommon.ts
浏览文件 @
3c509087
...
...
@@ -2310,6 +2310,7 @@ export interface IViewState {
export
interface
ICodeEditorViewState
extends
IEditorViewState
{
cursorState
:
ICursorState
[];
viewState
:
IViewState
;
contributionsState
:
{[
id
:
string
]:
any
};
}
/**
...
...
@@ -3001,6 +3002,14 @@ export interface IEditorContribution {
* Dispose this contribution.
*/
dispose
():
void
;
/**
* Store view state.
*/
saveViewState
?():
any
;
/**
* Restore view state.
*/
restoreViewState
?(
state
:
any
):
void
;
}
export
type
MarkedString
=
string
|
{
language
:
string
;
value
:
string
};
...
...
src/vs/editor/contrib/folding/browser/folding.ts
浏览文件 @
3c509087
...
...
@@ -33,8 +33,7 @@ class CollapsibleRegion {
private
_lastRange
:
IFoldingRange
;
public
constructor
(
range
:
IFoldingRange
,
model
:
EditorCommon
.
IModel
,
changeAccessor
:
EditorCommon
.
IModelDecorationsChangeAccessor
,
isCollapsed
:
boolean
)
{
this
.
_isCollapsed
=
isCollapsed
;
public
constructor
(
range
:
IFoldingRange
,
model
:
EditorCommon
.
IModel
,
changeAccessor
:
EditorCommon
.
IModelDecorationsChangeAccessor
)
{
this
.
decorationIds
=
[];
this
.
update
(
range
,
model
,
changeAccessor
);
}
...
...
@@ -80,6 +79,7 @@ class CollapsibleRegion {
public
update
(
newRange
:
IFoldingRange
,
model
:
EditorCommon
.
IModel
,
changeAccessor
:
EditorCommon
.
IModelDecorationsChangeAccessor
):
void
{
this
.
_lastRange
=
newRange
;
this
.
_isCollapsed
=
!!
newRange
.
isCollapsed
;
let
newDecorations
:
EditorCommon
.
IModelDeltaDecoration
[]
=
[];
...
...
@@ -166,80 +166,114 @@ export class FoldingController implements EditorCommon.IEditorContribution {
this
.
globalToDispose
=
disposeAll
(
this
.
globalToDispose
);
}
private
cleanState
():
void
{
this
.
localToDispose
=
disposeAll
(
this
.
localToDispose
);
/**
* Store view state.
*/
public
saveViewState
():
any
{
let
model
=
this
.
editor
.
getModel
();
if
(
!
model
)
{
return
{};
}
var
collapsedRegions
:
IFoldingRange
[]
=
[];
this
.
decorations
.
forEach
(
d
=>
{
if
(
d
.
isCollapsed
)
{
var
range
=
d
.
getDecorationRange
(
model
);
if
(
range
)
{
collapsedRegions
.
push
({
startLineNumber
:
range
.
startLineNumber
,
endLineNumber
:
range
.
endLineNumber
,
isCollapsed
:
true
});
}
};
});
return
collapsedRegions
;
}
private
onModelChanged
():
void
{
this
.
cleanState
();
if
(
!
this
.
editor
.
getConfiguration
().
folding
)
{
/**
* Restore view state.
*/
public
restoreViewState
(
state
:
any
):
void
{
if
(
!
Array
.
isArray
(
state
))
{
return
;
}
this
.
applyRegions
(
<
IFoldingRange
[]
>
state
);
}
private
cleanState
():
void
{
this
.
localToDispose
=
disposeAll
(
this
.
localToDispose
);
}
private
applyRegions
(
regions
:
IFoldingRange
[])
{
let
model
=
this
.
editor
.
getModel
();
if
(
!
model
)
{
return
;
}
this
.
updateScheduler
=
new
RunOnceScheduler
(()
=>
{
let
myToken
=
(
++
this
.
computeToken
);
regions
=
regions
.
sort
((
r1
,
r2
)
=>
r1
.
startLineNumber
-
r2
.
startLineNumber
);
log
(
'
imput ranges
'
+
regions
.
map
(
rangeToString
).
join
(
'
,
'
)
);
this
.
computeCollapsibleRegions
().
then
(
regions
=>
{
if
(
myToken
!==
this
.
computeToken
)
{
// A new request was made in the meantime or the model was changed
return
;
}
regions
=
regions
.
sort
((
r1
,
r2
)
=>
r1
.
startLineNumber
-
r2
.
startLineNumber
);
log
(
'
compute ranges
'
+
regions
.
map
(
rangeToString
).
join
(
'
,
'
));
this
.
editor
.
changeDecorations
(
changeAccessor
=>
{
this
.
editor
.
changeDecorations
(
changeAccessor
=>
{
let
newDecorations
:
CollapsibleRegion
[]
=
[];
let
newDecorations
:
CollapsibleRegion
[]
=
[];
let
k
=
0
,
i
=
0
;
while
(
i
<
this
.
decorations
.
length
&&
k
<
regions
.
length
)
{
let
dec
=
this
.
decorations
[
i
];
let
decRange
=
dec
.
getDecorationRange
(
model
);
if
(
!
decRange
)
{
let
k
=
0
,
i
=
0
;
while
(
i
<
this
.
decorations
.
length
&&
k
<
regions
.
length
)
{
let
dec
=
this
.
decorations
[
i
];
let
decRange
=
dec
.
getDecorationRange
(
model
);
if
(
!
decRange
)
{
log
(
'
range no longer valid, was
'
+
dec
.
toString
());
dec
.
dispose
(
changeAccessor
);
i
++
;
}
else
{
while
(
k
<
regions
.
length
&&
decRange
.
startLineNumber
>
regions
[
k
].
startLineNumber
)
{
log
(
'
new range
'
+
rangeToString
(
regions
[
k
]));
newDecorations
.
push
(
new
CollapsibleRegion
(
regions
[
k
],
model
,
changeAccessor
));
k
++
;
}
if
(
k
<
regions
.
length
)
{
let
currRange
=
regions
[
k
];
if
(
decRange
.
startLineNumber
<
currRange
.
startLineNumber
)
{
log
(
'
range no longer valid, was
'
+
dec
.
toString
());
dec
.
dispose
(
changeAccessor
);
i
++
;
}
else
{
while
(
k
<
regions
.
length
&&
decRange
.
startLineNumber
>
regions
[
k
].
startLineNumber
)
{
log
(
'
new range
'
+
rangeToString
(
regions
[
k
]));
newDecorations
.
push
(
new
CollapsibleRegion
(
regions
[
k
],
model
,
changeAccessor
,
false
));
k
++
;
}
if
(
k
<
regions
.
length
)
{
let
currRange
=
regions
[
k
];
if
(
decRange
.
startLineNumber
<
currRange
.
startLineNumber
)
{
log
(
'
range no longer valid, was
'
+
dec
.
toString
());
dec
.
dispose
(
changeAccessor
);
i
++
;
}
else
if
(
decRange
.
startLineNumber
===
currRange
.
startLineNumber
)
{
dec
.
update
(
currRange
,
model
,
changeAccessor
);
newDecorations
.
push
(
dec
);
i
++
;
k
++
;
}
}
}
else
if
(
decRange
.
startLineNumber
===
currRange
.
startLineNumber
)
{
currRange
.
isCollapsed
=
dec
.
isCollapsed
;
// preserve collapse state
dec
.
update
(
currRange
,
model
,
changeAccessor
);
newDecorations
.
push
(
dec
);
i
++
;
k
++
;
}
}
while
(
i
<
this
.
decorations
.
length
)
{
log
(
'
range no longer valid, was
'
+
this
.
decorations
[
i
].
toString
());
this
.
decorations
[
i
].
dispose
(
changeAccessor
);
i
++
;
}
while
(
k
<
regions
.
length
)
{
log
(
'
new range
'
+
rangeToString
(
regions
[
k
]));
newDecorations
.
push
(
new
CollapsibleRegion
(
regions
[
k
],
model
,
changeAccessor
,
false
));
k
++
;
}
this
.
decorations
=
newDecorations
;
});
}
}
while
(
i
<
this
.
decorations
.
length
)
{
log
(
'
range no longer valid, was
'
+
this
.
decorations
[
i
].
toString
());
this
.
decorations
[
i
].
dispose
(
changeAccessor
);
i
++
;
}
while
(
k
<
regions
.
length
)
{
log
(
'
new range
'
+
rangeToString
(
regions
[
k
]));
newDecorations
.
push
(
new
CollapsibleRegion
(
regions
[
k
],
model
,
changeAccessor
));
k
++
;
}
this
.
decorations
=
newDecorations
;
});
this
.
updateHiddenAreas
();
}
private
onModelChanged
():
void
{
this
.
cleanState
();
this
.
updateHiddenAreas
();
let
model
=
this
.
editor
.
getModel
();
if
(
!
this
.
editor
.
getConfiguration
().
folding
||
!
model
)
{
return
;
}
this
.
updateScheduler
=
new
RunOnceScheduler
(()
=>
{
let
myToken
=
(
++
this
.
computeToken
);
this
.
computeCollapsibleRegions
().
then
(
regions
=>
{
if
(
myToken
!==
this
.
computeToken
)
{
return
;
// A new request was made in the meantime or the model was changed
}
this
.
applyRegions
(
regions
);
});
},
200
);
...
...
@@ -249,6 +283,7 @@ export class FoldingController implements EditorCommon.IEditorContribution {
++
this
.
computeToken
;
this
.
editor
.
changeDecorations
(
changeAccessor
=>
{
this
.
decorations
.
forEach
(
dec
=>
dec
.
dispose
(
changeAccessor
));
this
.
decorations
=
[];
});
}});
this
.
localToDispose
.
push
(
this
.
editor
.
addListener2
(
EditorCommon
.
EventType
.
MouseDown
,
(
e
)
=>
this
.
_onEditorMouseDown
(
e
)));
...
...
@@ -263,7 +298,6 @@ export class FoldingController implements EditorCommon.IEditorContribution {
return
TPromise
.
as
([]);
}
let
ranges
=
foldStrategy
.
computeRanges
(
model
,
tabSize
);
return
TPromise
.
as
(
ranges
);
}
...
...
@@ -320,7 +354,7 @@ export class FoldingController implements EditorCommon.IEditorContribution {
private
updateHiddenAreas
():
void
{
let
model
=
this
.
editor
.
getModel
();
let
hiddenAreas
:
EditorCommon
.
IRange
[]
=
[];
let
hiddenAreas
:
EditorCommon
.
IRange
[]
=
[];
this
.
decorations
.
filter
(
dec
=>
dec
.
isCollapsed
).
forEach
(
dec
=>
{
let
decRange
=
dec
.
getDecorationRange
(
model
);
hiddenAreas
.
push
({
...
...
@@ -377,7 +411,7 @@ export class FoldingController implements EditorCommon.IEditorContribution {
}
abstract
class
FoldingAction
extends
EditorAction
{
constructor
(
descriptor
:
EditorCommon
.
IEditorActionDescriptorData
,
editor
:
EditorCommon
.
ICommonCodeEditor
,
@
INullService
ns
)
{
constructor
(
descriptor
:
EditorCommon
.
IEditorActionDescriptorData
,
editor
:
EditorCommon
.
ICommonCodeEditor
,
@
INullService
ns
)
{
super
(
descriptor
,
editor
);
}
...
...
src/vs/editor/contrib/folding/common/foldingRange.ts
浏览文件 @
3c509087
...
...
@@ -8,8 +8,9 @@
export
interface
IFoldingRange
{
startLineNumber
:
number
;
endLineNumber
:
number
;
isCollapsed
?:
boolean
;
}
export
function
toString
(
range
:
IFoldingRange
):
string
{
return
range
?
range
.
startLineNumber
+
'
/
'
+
range
.
endLineNumber
:
'
null
'
;
return
(
range
?
range
.
startLineNumber
+
'
/
'
+
range
.
endLineNumber
:
'
null
'
)
+
range
.
isCollapsed
?
'
(collapsed)
'
:
'
'
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录