Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
499086dc
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,发现更多精彩内容 >>
提交
499086dc
编写于
9月 07, 2017
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve editor history navigation: merge locations (fixes #29027)
上级
f7c2c14e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
49 addition
and
31 deletion
+49
-31
src/vs/workbench/services/history/browser/history.ts
src/vs/workbench/services/history/browser/history.ts
+49
-31
未找到文件。
src/vs/workbench/services/history/browser/history.ts
浏览文件 @
499086dc
...
...
@@ -34,22 +34,28 @@ import { ResourceGlobMatcher } from 'vs/workbench/common/resources';
/**
* Stores the selection & view state of an editor and allows to compare it to other selection states.
*/
export
class
EditorState
{
export
class
Text
EditorState
{
private
static
EDITOR_SELECTION_THRESHOLD
=
10
;
// number of lines to move in editor to justify for new state
private
textEditorSelection
:
ITextEditorSelection
;
constructor
(
private
_editorInput
:
IEditorInput
,
private
_selection
:
Selection
)
{
this
.
textEditorSelection
=
Selection
.
isISelection
(
_selection
)
?
{
startLineNumber
:
_selection
.
startLineNumber
,
startColumn
:
_selection
.
startColumn
}
:
void
0
;
}
public
get
editorInput
():
IEditorInput
{
return
this
.
_editorInput
;
}
public
get
selection
():
Selection
{
return
this
.
_s
election
;
public
get
selection
():
ITextEditor
Selection
{
return
this
.
textEditorS
election
;
}
public
justifiesNewPushState
(
other
:
EditorState
,
event
?:
ICursorPositionChangedEvent
):
boolean
{
public
justifiesNewPushState
(
other
:
Text
EditorState
,
event
?:
ICursorPositionChangedEvent
):
boolean
{
if
(
!
this
.
_editorInput
.
matches
(
other
.
_editorInput
))
{
return
true
;
// push different editor inputs
}
...
...
@@ -65,7 +71,7 @@ export class EditorState {
const
myLineNumber
=
Math
.
min
(
this
.
_selection
.
selectionStartLineNumber
,
this
.
_selection
.
positionLineNumber
);
const
otherLineNumber
=
Math
.
min
(
other
.
_selection
.
selectionStartLineNumber
,
other
.
_selection
.
positionLineNumber
);
if
(
Math
.
abs
(
myLineNumber
-
otherLineNumber
)
<
EditorState
.
EDITOR_SELECTION_THRESHOLD
)
{
if
(
Math
.
abs
(
myLineNumber
-
otherLineNumber
)
<
Text
EditorState
.
EDITOR_SELECTION_THRESHOLD
)
{
return
false
;
// ignore selection changes in the range of EditorState.EDITOR_SELECTION_THRESHOLD lines
}
...
...
@@ -151,7 +157,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private
index
:
number
;
private
lastIndex
:
number
;
private
navigatingInStack
:
boolean
;
private
current
FileEditorState
:
EditorState
;
private
current
TextEditorState
:
Text
EditorState
;
private
history
:
(
IEditorInput
|
IResourceInput
)[];
private
recentlyClosedFiles
:
IRecentlyClosedFile
[];
...
...
@@ -436,13 +442,13 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
// treat editor changes that happen as part of stack navigation specially
// we do not want to add a new stack entry as a matter of navigating the
// stack but we need to keep our current
File
EditorState up to date with
// stack but we need to keep our current
Text
EditorState up to date with
// the navigtion that occurs.
if
(
this
.
navigatingInStack
)
{
if
(
control
&&
editor
.
input
)
{
this
.
current
FileEditorState
=
new
EditorState
(
editor
.
input
,
control
.
getSelection
());
this
.
current
TextEditorState
=
new
Text
EditorState
(
editor
.
input
,
control
.
getSelection
());
}
else
{
this
.
current
FileEditorState
=
null
;
// we navigated to a non file
editor
this
.
current
TextEditorState
=
null
;
// we navigated to a non text
editor
}
return
;
...
...
@@ -454,7 +460,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
return
;
}
this
.
current
FileEditorState
=
null
;
// at this time we have no active file
editor view state
this
.
current
TextEditorState
=
null
;
// at this time we have no active text
editor view state
if
(
editor
&&
editor
.
input
)
{
this
.
handleNonTextEditorEvent
(
editor
);
...
...
@@ -462,19 +468,20 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
private
handleTextEditorEvent
(
editor
:
IBaseEditor
,
editorControl
:
IEditor
,
event
?:
ICursorPositionChangedEvent
):
void
{
const
stateCandidate
=
new
EditorState
(
editor
.
input
,
editorControl
.
getSelection
());
if
(
!
this
.
currentFileEditorState
||
this
.
currentFileEditorState
.
justifiesNewPushState
(
stateCandidate
,
event
))
{
this
.
currentFileEditorState
=
stateCandidate
;
let
selection
:
ITextEditorSelection
;
const
stateCandidate
=
new
TextEditorState
(
editor
.
input
,
editorControl
.
getSelection
());
const
editorSelection
=
editorControl
.
getSelection
();
if
(
editorSelection
)
{
selection
=
{
startLineNumber
:
editorSelection
.
startLineNumber
,
startColumn
:
editorSelection
.
startColumn
}
;
// Add to stack if we dont have a current state or this new state justifies a push
if
(
!
this
.
currentTextEditorState
||
this
.
currentTextEditorState
.
justifiesNewPushState
(
stateCandidate
,
event
)
)
{
this
.
add
(
editor
.
input
,
stateCandidate
.
selection
)
;
}
this
.
add
(
editor
.
input
,
selection
,
true
/* from event */
);
// Otherwise we replace the current stack entry with this one
else
{
this
.
replace
(
editor
.
input
,
stateCandidate
.
selection
);
}
// Update our current text editor state
this
.
currentTextEditorState
=
stateCandidate
;
}
private
handleNonTextEditorEvent
(
editor
:
IBaseEditor
):
void
{
...
...
@@ -483,34 +490,45 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
return
;
// do not push same editor input again
}
this
.
add
(
editor
.
input
,
void
0
,
true
/* from event */
);
this
.
add
(
editor
.
input
);
}
public
add
(
input
:
IEditorInput
,
selection
?:
ITextEditorSelection
,
fromEvent
?:
boolean
):
void
{
public
add
(
input
:
IEditorInput
,
selection
?:
ITextEditorSelection
):
void
{
if
(
!
this
.
navigatingInStack
)
{
this
.
add
ToStack
(
input
,
selection
,
fromEvent
);
this
.
add
OrReplaceInStack
(
input
,
selection
);
}
}
private
addToStack
(
input
:
IEditorInput
,
selection
?:
ITextEditorSelection
,
fromEvent
?:
boolean
):
void
{
private
replace
(
input
:
IEditorInput
,
selection
?:
ITextEditorSelection
):
void
{
if
(
!
this
.
navigatingInStack
)
{
this
.
addOrReplaceInStack
(
input
,
selection
,
true
/* force replace */
);
}
}
private
addOrReplaceInStack
(
input
:
IEditorInput
,
selection
?:
ITextEditorSelection
,
forceReplace
?:
boolean
):
void
{
// Overwrite an entry in the stack if we have a matching input that comes
// with editor options to indicate that this entry is more specific. Also
// prevent entries that have the exact same options. Finally, Overwrite
// entries if it came from an event and we detect that the change came in
// very fast which indicates that it was not coming in from a user change
// but rather rapid programmatic changes. We just take the last of the changes
// to not cause too many entries on the stack.
// entries if we detect that the change came in very fast which indicates
// that it was not coming in from a user change but rather rapid programmatic
// changes. We just take the last of the changes to not cause too many entries
// on the stack.
// We can also be instructed to force replace the last entry.
let
replace
=
false
;
if
(
this
.
stack
[
this
.
index
])
{
if
(
forceReplace
)
{
replace
=
true
;
}
else
{
const
currentEntry
=
this
.
stack
[
this
.
index
];
if
(
this
.
matches
(
input
,
currentEntry
.
input
)
&&
(
this
.
sameSelection
(
currentEntry
.
selection
,
selection
)
||
(
fromEvent
&&
Date
.
now
()
-
currentEntry
.
timestamp
<
HistoryService
.
MERGE_EVENT_CHANGES_THRESHOLD
)))
{
if
(
this
.
matches
(
input
,
currentEntry
.
input
)
&&
(
this
.
sameSelection
(
currentEntry
.
selection
,
selection
)
||
(
Date
.
now
()
-
currentEntry
.
timestamp
<
HistoryService
.
MERGE_EVENT_CHANGES_THRESHOLD
)))
{
replace
=
true
;
}
}
}
const
stackInput
=
this
.
preferResourceInput
(
input
);
const
entry
=
{
input
:
stackInput
,
selection
,
timestamp
:
fromEvent
?
Date
.
now
()
:
void
0
};
const
entry
=
{
input
:
stackInput
,
selection
,
timestamp
:
Date
.
now
()
};
// If we are not at the end of history, we remove anything after
if
(
this
.
stack
.
length
>
this
.
index
+
1
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录