Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
609a53b4
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,发现更多精彩内容 >>
提交
609a53b4
编写于
11月 15, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Using 'new' event in diff navigator, #38417
上级
ebfe7213
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
54 deletion
+47
-54
src/vs/editor/browser/widget/diffNavigator.ts
src/vs/editor/browser/widget/diffNavigator.ts
+45
-49
src/vs/editor/standalone/browser/standaloneEditor.ts
src/vs/editor/standalone/browser/standaloneEditor.ts
+0
-2
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+0
-1
src/vs/workbench/browser/parts/editor/textDiffEditor.ts
src/vs/workbench/browser/parts/editor/textDiffEditor.ts
+2
-2
未找到文件。
src/vs/editor/browser/widget/diffNavigator.ts
浏览文件 @
609a53b4
...
...
@@ -5,13 +5,14 @@
'
use strict
'
;
import
*
as
assert
from
'
vs/base/common/assert
'
;
import
{
EventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
*
as
objects
from
'
vs/base/common/objects
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ILineChange
,
ScrollType
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
ICursorPositionChangedEvent
}
from
'
vs/editor/common/controller/cursorEvents
'
;
import
{
IDiffEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
interface
IDiffRange
{
rhs
:
boolean
;
...
...
@@ -33,73 +34,69 @@ var defaultOptions: Options = {
/**
* Create a new diff navigator for the provided diff editor.
*/
export
class
DiffNavigator
extends
EventEmitter
{
export
class
DiffNavigator
{
public
static
Events
=
{
UPDATED
:
'
navigation.updated
'
};
private
readonly
_editor
:
IDiffEditor
;
private
readonly
_options
:
Options
;
private
readonly
_disposables
:
IDisposable
[];
private
readonly
_onDidUpdate
=
new
Emitter
<
this
>
();
private
editor
:
IDiffEditor
;
private
options
:
Options
;
private
disposed
:
boolean
;
private
toUnbind
:
IDisposable
[];
readonly
onDidUpdate
:
Event
<
this
>
=
this
.
_onDidUpdate
.
event
;
private
disposed
:
boolean
;
private
revealFirst
:
boolean
;
private
nextIdx
:
number
;
private
ranges
:
IDiffRange
[];
private
ignoreSelectionChange
:
boolean
;
public
revealFirst
:
boolean
;
constructor
(
editor
:
IDiffEditor
,
options
:
Options
=
{})
{
super
([
DiffNavigator
.
Events
.
UPDATED
]);
this
.
editor
=
editor
;
this
.
options
=
objects
.
mixin
(
options
,
defaultOptions
,
false
);
this
.
_editor
=
editor
;
this
.
_options
=
objects
.
mixin
(
options
,
defaultOptions
,
false
);
this
.
disposed
=
false
;
this
.
toUnbind
=
[];
this
.
_disposables
=
[];
this
.
nextIdx
=
-
1
;
this
.
ranges
=
[];
this
.
ignoreSelectionChange
=
false
;
this
.
revealFirst
=
this
.
options
.
alwaysRevealFirst
;
this
.
revealFirst
=
this
.
_
options
.
alwaysRevealFirst
;
// hook up to diff editor for diff, disposal, and caret move
this
.
toUnbind
.
push
(
this
.
editor
.
onDidDispose
(()
=>
this
.
dispose
()));
this
.
toUnbind
.
push
(
this
.
editor
.
onDidUpdateDiff
(()
=>
this
.
onDiffUpdated
()));
this
.
_disposables
.
push
(
this
.
_
editor
.
onDidDispose
(()
=>
this
.
dispose
()));
this
.
_disposables
.
push
(
this
.
_editor
.
onDidUpdateDiff
(()
=>
this
.
_
onDiffUpdated
()));
if
(
this
.
options
.
followsCaret
)
{
this
.
toUnbind
.
push
(
this
.
editor
.
getModifiedEditor
().
onDidChangeCursorPosition
((
e
:
ICursorPositionChangedEvent
)
=>
{
if
(
this
.
_
options
.
followsCaret
)
{
this
.
_disposables
.
push
(
this
.
_
editor
.
getModifiedEditor
().
onDidChangeCursorPosition
((
e
:
ICursorPositionChangedEvent
)
=>
{
if
(
this
.
ignoreSelectionChange
)
{
return
;
}
this
.
nextIdx
=
-
1
;
}));
}
if
(
this
.
options
.
alwaysRevealFirst
)
{
this
.
toUnbind
.
push
(
this
.
editor
.
getModifiedEditor
().
onDidChangeModel
((
e
)
=>
{
if
(
this
.
_
options
.
alwaysRevealFirst
)
{
this
.
_disposables
.
push
(
this
.
_
editor
.
getModifiedEditor
().
onDidChangeModel
((
e
)
=>
{
this
.
revealFirst
=
true
;
}));
}
// init things
this
.
init
();
this
.
_
init
();
}
private
init
():
void
{
var
changes
=
this
.
editor
.
getLineChanges
();
private
_
init
():
void
{
var
changes
=
this
.
_
editor
.
getLineChanges
();
if
(
!
changes
)
{
return
;
}
}
private
onDiffUpdated
():
void
{
this
.
init
();
private
_
onDiffUpdated
():
void
{
this
.
_
init
();
this
.
compute
(
this
.
editor
.
getLineChanges
());
this
.
_compute
(
this
.
_
editor
.
getLineChanges
());
if
(
this
.
revealFirst
)
{
// Only reveal first on first non-null changes
if
(
this
.
editor
.
getLineChanges
()
!==
null
)
{
if
(
this
.
_
editor
.
getLineChanges
()
!==
null
)
{
this
.
revealFirst
=
false
;
this
.
nextIdx
=
-
1
;
this
.
next
();
...
...
@@ -107,7 +104,7 @@ export class DiffNavigator extends EventEmitter {
}
}
private
compute
(
lineChanges
:
ILineChange
[]):
void
{
private
_
compute
(
lineChanges
:
ILineChange
[]):
void
{
// new ranges
this
.
ranges
=
[];
...
...
@@ -116,7 +113,7 @@ export class DiffNavigator extends EventEmitter {
// create ranges from changes
lineChanges
.
forEach
((
lineChange
)
=>
{
if
(
!
this
.
options
.
ignoreCharChanges
&&
lineChange
.
charChanges
)
{
if
(
!
this
.
_
options
.
ignoreCharChanges
&&
lineChange
.
charChanges
)
{
lineChange
.
charChanges
.
forEach
((
charChange
)
=>
{
this
.
ranges
.
push
({
...
...
@@ -148,13 +145,12 @@ export class DiffNavigator extends EventEmitter {
return
0
;
}
});
this
.
emit
(
DiffNavigator
.
Events
.
UPDATED
,
{});
this
.
_onDidUpdate
.
fire
(
this
);
}
private
initIdx
(
fwd
:
boolean
):
void
{
private
_
initIdx
(
fwd
:
boolean
):
void
{
var
found
=
false
;
var
position
=
this
.
editor
.
getPosition
();
var
position
=
this
.
_
editor
.
getPosition
();
for
(
var
i
=
0
,
len
=
this
.
ranges
.
length
;
i
<
len
&&
!
found
;
i
++
)
{
var
range
=
this
.
ranges
[
i
].
range
;
if
(
position
.
isBeforeOrEqual
(
range
.
getStartPosition
()))
{
...
...
@@ -171,7 +167,7 @@ export class DiffNavigator extends EventEmitter {
}
}
private
move
(
fwd
:
boolean
):
void
{
private
_
move
(
fwd
:
boolean
):
void
{
assert
.
ok
(
!
this
.
disposed
,
'
Illegal State - diff navigator has been disposed
'
);
if
(
!
this
.
canNavigate
())
{
...
...
@@ -179,7 +175,7 @@ export class DiffNavigator extends EventEmitter {
}
if
(
this
.
nextIdx
===
-
1
)
{
this
.
initIdx
(
fwd
);
this
.
_
initIdx
(
fwd
);
}
else
if
(
fwd
)
{
this
.
nextIdx
+=
1
;
...
...
@@ -197,30 +193,30 @@ export class DiffNavigator extends EventEmitter {
this
.
ignoreSelectionChange
=
true
;
try
{
var
pos
=
info
.
range
.
getStartPosition
();
this
.
editor
.
setPosition
(
pos
);
this
.
editor
.
revealPositionInCenter
(
pos
,
ScrollType
.
Smooth
);
this
.
_
editor
.
setPosition
(
pos
);
this
.
_
editor
.
revealPositionInCenter
(
pos
,
ScrollType
.
Smooth
);
}
finally
{
this
.
ignoreSelectionChange
=
false
;
}
}
public
canNavigate
():
boolean
{
canNavigate
():
boolean
{
return
this
.
ranges
&&
this
.
ranges
.
length
>
0
;
}
public
next
():
void
{
this
.
move
(
true
);
next
():
void
{
this
.
_
move
(
true
);
}
p
ublic
p
revious
():
void
{
this
.
move
(
false
);
previous
():
void
{
this
.
_
move
(
false
);
}
public
dispose
():
void
{
this
.
toUnbind
=
dispose
(
this
.
toUnbind
);
dispose
():
void
{
dispose
(
this
.
_disposables
);
this
.
_disposables
.
length
=
0
;
this
.
_onDidUpdate
.
dispose
();
this
.
ranges
=
null
;
this
.
disposed
=
true
;
super
.
dispose
();
}
}
src/vs/editor/standalone/browser/standaloneEditor.ts
浏览文件 @
609a53b4
...
...
@@ -135,8 +135,6 @@ export function createDiffEditor(domElement: HTMLElement, options?: IDiffEditorC
}
export
interface
IDiffNavigator
{
revealFirst
:
boolean
;
canNavigate
():
boolean
;
next
():
void
;
previous
():
void
;
...
...
src/vs/monaco.d.ts
浏览文件 @
609a53b4
...
...
@@ -787,7 +787,6 @@ declare module monaco.editor {
export
function
createDiffEditor
(
domElement
:
HTMLElement
,
options
?:
IDiffEditorConstructionOptions
,
override
?:
IEditorOverrideServices
):
IStandaloneDiffEditor
;
export
interface
IDiffNavigator
{
revealFirst
:
boolean
;
canNavigate
():
boolean
;
next
():
void
;
previous
():
void
;
...
...
src/vs/workbench/browser/parts/editor/textDiffEditor.ts
浏览文件 @
609a53b4
...
...
@@ -159,7 +159,7 @@ export class TextDiffEditor extends BaseTextEditor {
this
.
diffNavigator
=
new
DiffNavigator
(
diffEditor
,
{
alwaysRevealFirst
});
this
.
diffNavigator
.
addListener
(
DiffNavigator
.
Events
.
UPDATED
,
()
=>
{
this
.
diffNavigator
.
onDidUpdate
(
()
=>
{
this
.
nextDiffAction
.
updateEnablement
();
this
.
previousDiffAction
.
updateEnablement
();
});
...
...
@@ -369,4 +369,4 @@ class ToggleEditorModeAction extends Action {
return
control
&&
!
control
.
renderSideBySide
;
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录