Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
776419c4
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,发现更多精彩内容 >>
提交
776419c4
编写于
10月 19, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[folding] fix restoring collapse state (for #36555)
上级
464f1a75
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
74 addition
and
28 deletion
+74
-28
src/vs/editor/contrib/folding/browser/folding.ts
src/vs/editor/contrib/folding/browser/folding.ts
+12
-24
src/vs/editor/contrib/folding/common/foldingModel.ts
src/vs/editor/contrib/folding/common/foldingModel.ts
+40
-0
src/vs/editor/contrib/folding/common/hiddenRangeModel.ts
src/vs/editor/contrib/folding/common/hiddenRangeModel.ts
+22
-4
未找到文件。
src/vs/editor/contrib/folding/browser/folding.ts
浏览文件 @
776419c4
...
@@ -17,7 +17,7 @@ import { ICommonCodeEditor, ScrollType } from 'vs/editor/common/editorCommon';
...
@@ -17,7 +17,7 @@ import { ICommonCodeEditor, ScrollType } from 'vs/editor/common/editorCommon';
import
{
editorAction
,
ServicesAccessor
,
EditorAction
,
CommonEditorRegistry
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
editorAction
,
ServicesAccessor
,
EditorAction
,
CommonEditorRegistry
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
ICodeEditor
,
IEditorMouseEvent
,
MouseTargetType
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
ICodeEditor
,
IEditorMouseEvent
,
MouseTargetType
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
editorContribution
}
from
'
vs/editor/browser/editorBrowserExtensions
'
;
import
{
editorContribution
}
from
'
vs/editor/browser/editorBrowserExtensions
'
;
import
{
FoldingModel
,
FoldingRegion
,
setCollapseStateAtLevel
,
setCollapseStateRecursivly
,
fold
,
unfold
}
from
'
vs/editor/contrib/folding/common/foldingModel
'
;
import
{
FoldingModel
,
setCollapseStateAtLevel
,
setCollapseStateRecursivly
,
fold
,
unfold
,
CollapseState
}
from
'
vs/editor/contrib/folding/common/foldingModel
'
;
import
{
computeRanges
,
limitByIndent
}
from
'
vs/editor/contrib/folding/common/indentFoldStrategy
'
;
import
{
computeRanges
,
limitByIndent
}
from
'
vs/editor/contrib/folding/common/indentFoldStrategy
'
;
import
{
FoldingDecorationProvider
}
from
'
./foldingDecorations
'
;
import
{
FoldingDecorationProvider
}
from
'
./foldingDecorations
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
...
@@ -99,27 +99,18 @@ export class FoldingController {
...
@@ -99,27 +99,18 @@ export class FoldingController {
/**
/**
* Store view state.
* Store view state.
*/
*/
public
saveViewState
():
any
{
public
saveViewState
():
{
collapsedRegions
?:
CollapseState
,
lineCount
?:
number
}
{
let
model
=
this
.
editor
.
getModel
();
let
model
=
this
.
editor
.
getModel
();
if
(
!
model
)
{
if
(
!
model
)
{
return
{};
return
{};
}
}
let
collapsedIndexes
:
number
[]
=
[];
return
{
collapsedRegions
:
this
.
foldingModel
.
getCollapseState
(),
lineCount
:
model
.
getLineCount
()
};
for
(
let
region
of
this
.
foldingModel
.
regions
)
{
if
(
region
.
isCollapsed
&&
region
.
editorDecorationId
)
{
var
range
=
model
.
getDecorationRange
(
region
.
editorDecorationId
);
if
(
range
)
{
collapsedIndexes
.
push
(
range
.
startLineNumber
);
}
}
}
return
{
collapsedIndexes
,
lineCount
:
model
.
getLineCount
()
};
}
}
/**
/**
* Restore view state.
* Restore view state.
*/
*/
public
restoreViewState
(
state
:
any
):
void
{
public
restoreViewState
(
state
:
{
collapsedRegions
?:
CollapseState
,
lineCount
?:
number
}
):
void
{
let
model
=
this
.
editor
.
getModel
();
let
model
=
this
.
editor
.
getModel
();
if
(
!
model
)
{
if
(
!
model
)
{
return
;
return
;
...
@@ -127,19 +118,16 @@ export class FoldingController {
...
@@ -127,19 +118,16 @@ export class FoldingController {
if
(
!
this
.
_isEnabled
)
{
if
(
!
this
.
_isEnabled
)
{
return
;
return
;
}
}
if
(
!
state
||
!
Array
.
isArray
(
state
.
collapsedIndexes
)
||
state
.
collapsedIndexes
.
length
===
0
||
state
.
lineCount
!==
model
.
getLineCount
())
{
if
(
!
state
||
!
state
.
collapsedRegions
||
state
.
lineCount
!==
model
.
getLineCount
())
{
return
;
return
;
}
}
this
.
getFoldingModel
().
then
(
foldingModel
=>
{
let
toToogle
:
FoldingRegion
[]
=
[];
// set the hidden ranges right way, before waiting for the folding model.
for
(
let
index
of
state
.
collapsedIndexes
)
{
if
(
this
.
hiddenRangeModel
.
applyCollapseState
(
state
.
collapsedRegions
))
{
let
region
=
foldingModel
.
getRegionAtLine
(
index
);
this
.
getFoldingModel
().
then
(
foldingModel
=>
{
if
(
region
&&
!
region
.
isCollapsed
)
{
foldingModel
.
applyCollapseState
(
state
.
collapsedRegions
);
toToogle
.
push
(
region
);
});
}
}
}
foldingModel
.
toggleCollapseState
(
toToogle
);
});
}
}
private
onModelChanged
():
void
{
private
onModelChanged
():
void
{
...
...
src/vs/editor/contrib/folding/common/foldingModel.ts
浏览文件 @
776419c4
...
@@ -32,6 +32,8 @@ export interface FoldingModelChangeEvent {
...
@@ -32,6 +32,8 @@ export interface FoldingModelChangeEvent {
collapseStateChanged
?:
FoldingRegion
[];
collapseStateChanged
?:
FoldingRegion
[];
}
}
export
type
CollapseState
=
ILineRange
[];
export
class
FoldingModel
{
export
class
FoldingModel
{
private
_textModel
:
IModel
;
private
_textModel
:
IModel
;
private
_decorationProvider
:
IDecorationProvider
;
private
_decorationProvider
:
IDecorationProvider
;
...
@@ -134,6 +136,44 @@ export class FoldingModel {
...
@@ -134,6 +136,44 @@ export class FoldingModel {
this
.
_updateEventEmitter
.
fire
({
model
:
this
});
this
.
_updateEventEmitter
.
fire
({
model
:
this
});
}
}
/**
* Collapse state, for persistence only
*/
public
getCollapseState
():
CollapseState
{
let
collapsedRanges
:
ILineRange
[]
=
[];
for
(
let
region
of
this
.
_regions
)
{
if
(
region
.
isCollapsed
&&
region
.
editorDecorationId
)
{
let
range
=
this
.
_textModel
.
getDecorationRange
(
region
.
editorDecorationId
);
if
(
range
)
{
let
startLineNumber
=
range
.
startLineNumber
;
let
endLineNumber
=
range
.
endLineNumber
+
region
.
range
.
endLineNumber
+
region
.
range
.
startLineNumber
;
collapsedRanges
.
push
({
startLineNumber
,
endLineNumber
});
}
}
}
if
(
collapsedRanges
.
length
>
0
)
{
return
collapsedRanges
;
}
return
null
;
}
/**
* Apply persisted state, for persistence only
*/
public
applyCollapseState
(
state
:
CollapseState
)
{
if
(
!
Array
.
isArray
(
state
))
{
return
;
}
let
toToogle
:
FoldingRegion
[]
=
[];
for
(
let
range
of
state
)
{
let
region
=
this
.
getRegionAtLine
(
range
.
startLineNumber
);
if
(
region
&&
!
region
.
isCollapsed
)
{
toToogle
.
push
(
region
);
}
}
this
.
toggleCollapseState
(
toToogle
);
}
public
dispose
()
{
public
dispose
()
{
let
editorDecorationIds
=
[];
let
editorDecorationIds
=
[];
for
(
let
region
of
this
.
_regions
)
{
for
(
let
region
of
this
.
_regions
)
{
...
...
src/vs/editor/contrib/folding/common/hiddenRangeModel.ts
浏览文件 @
776419c4
...
@@ -5,12 +5,11 @@
...
@@ -5,12 +5,11 @@
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
FoldingRegion
,
FoldingModel
,
IFoldingRange
}
from
'
vs/editor/contrib/folding/common/foldingModel
'
;
import
{
FoldingRegion
,
FoldingModel
,
IFoldingRange
,
CollapseState
}
from
'
vs/editor/contrib/folding/common/foldingModel
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
findFirst
}
from
'
vs/base/common/arrays
'
;
import
{
findFirst
}
from
'
vs/base/common/arrays
'
;
export
class
HiddenRangeModel
{
export
class
HiddenRangeModel
{
private
_foldingModel
:
FoldingModel
;
private
_foldingModel
:
FoldingModel
;
private
_hiddenRanges
:
IRange
[]
=
[];
private
_hiddenRanges
:
IRange
[]
=
[];
...
@@ -53,9 +52,28 @@ export class HiddenRangeModel {
...
@@ -53,9 +52,28 @@ export class HiddenRangeModel {
}
}
};
};
if
(
updateHiddenAreas
||
i
<
this
.
_hiddenRanges
.
length
)
{
if
(
updateHiddenAreas
||
i
<
this
.
_hiddenRanges
.
length
)
{
this
.
_hiddenRanges
=
newHiddenAreas
;
this
.
applyHiddenRanges
(
newHiddenAreas
);
this
.
_updateEventEmitter
.
fire
(
newHiddenAreas
);
}
}
public
applyCollapseState
(
state
:
CollapseState
):
boolean
{
if
(
!
Array
.
isArray
(
state
)
||
state
.
length
===
0
)
{
return
false
;
}
}
let
hiddenRanges
=
[];
for
(
let
r
of
state
)
{
if
(
!
r
.
startLineNumber
||
!
r
.
endLineNumber
)
{
return
false
;
}
hiddenRanges
.
push
(
new
Range
(
r
.
startLineNumber
,
1
,
r
.
endLineNumber
,
1
));
}
this
.
applyHiddenRanges
(
hiddenRanges
);
return
true
;
}
private
applyHiddenRanges
(
newHiddenAreas
:
IRange
[])
{
this
.
_hiddenRanges
=
newHiddenAreas
;
this
.
_updateEventEmitter
.
fire
(
newHiddenAreas
);
}
}
public
hasRanges
()
{
public
hasRanges
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录