Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9df54d6f
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,发现更多精彩内容 >>
提交
9df54d6f
编写于
12月 05, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid deferredEmit
上级
3ead6ed3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
335 addition
and
239 deletion
+335
-239
src/vs/base/common/eventEmitter.ts
src/vs/base/common/eventEmitter.ts
+14
-3
src/vs/base/parts/tree/browser/treeModel.ts
src/vs/base/parts/tree/browser/treeModel.ts
+12
-5
src/vs/editor/browser/editorBrowser.ts
src/vs/editor/browser/editorBrowser.ts
+0
-1
src/vs/editor/browser/view/viewController.ts
src/vs/editor/browser/view/viewController.ts
+13
-40
src/vs/editor/browser/view/viewImpl.ts
src/vs/editor/browser/view/viewImpl.ts
+27
-37
src/vs/editor/browser/view/viewOutgoingEvents.ts
src/vs/editor/browser/view/viewOutgoingEvents.ts
+106
-0
src/vs/editor/browser/widget/codeEditorWidget.ts
src/vs/editor/browser/widget/codeEditorWidget.ts
+12
-15
src/vs/editor/common/viewModel/viewModelImpl.ts
src/vs/editor/common/viewModel/viewModelImpl.ts
+151
-138
未找到文件。
src/vs/base/common/eventEmitter.ts
浏览文件 @
9df54d6f
...
...
@@ -220,14 +220,25 @@ export class EventEmitter implements IEventEmitter {
}
}
p
ublic
deferredEmit
(
callback
:
()
=>
any
):
any
{
p
rotected
_beginDeferredEmit
():
void
{
this
.
_deferredCnt
=
this
.
_deferredCnt
+
1
;
var
result
:
any
=
safeInvokeNoArg
(
callback
);
}
protected
_endDeferredEmit
():
void
{
this
.
_deferredCnt
=
this
.
_deferredCnt
-
1
;
if
(
this
.
_deferredCnt
===
0
)
{
this
.
_emitCollected
();
}
}
public
deferredEmit
<
T
>
(
callback
:
()
=>
T
):
T
{
this
.
_beginDeferredEmit
();
let
result
:
T
=
safeInvokeNoArg
<
T
>
(
callback
);
this
.
_endDeferredEmit
();
return
result
;
}
...
...
@@ -290,7 +301,7 @@ export class OrderGuaranteeEventEmitter extends EventEmitter {
}
}
function
safeInvokeNoArg
(
func
:
Function
):
any
{
function
safeInvokeNoArg
<
T
>
(
func
:
Function
):
T
{
try
{
return
func
();
}
catch
(
e
)
{
...
...
src/vs/base/parts/tree/browser/treeModel.ts
浏览文件 @
9df54d6f
...
...
@@ -848,12 +848,19 @@ export class TreeModel extends Events.EventEmitter {
}
public
refreshAll
(
elements
:
any
[],
recursive
:
boolean
=
true
):
WinJS
.
Promise
{
try
{
this
.
_beginDeferredEmit
();
return
this
.
_refreshAll
(
elements
,
recursive
);
}
finally
{
this
.
_endDeferredEmit
();
}
}
private
_refreshAll
(
elements
:
any
[],
recursive
:
boolean
):
WinJS
.
Promise
{
var
promises
=
[];
this
.
deferredEmit
(()
=>
{
for
(
var
i
=
0
,
len
=
elements
.
length
;
i
<
len
;
i
++
)
{
promises
.
push
(
this
.
refresh
(
elements
[
i
],
recursive
));
}
});
for
(
var
i
=
0
,
len
=
elements
.
length
;
i
<
len
;
i
++
)
{
promises
.
push
(
this
.
refresh
(
elements
[
i
],
recursive
));
}
return
WinJS
.
Promise
.
join
(
promises
);
}
...
...
src/vs/editor/browser/editorBrowser.ts
浏览文件 @
9df54d6f
...
...
@@ -65,7 +65,6 @@ export interface IView extends IDisposable {
change
(
callback
:
(
changeAccessor
:
IViewZoneChangeAccessor
)
=>
any
):
boolean
;
getWhitespaces
():
editorCommon
.
IEditorWhitespace
[];
renderOnce
(
callback
:
()
=>
any
):
any
;
render
(
now
:
boolean
,
everything
:
boolean
):
void
;
setAriaActiveDescendant
(
id
:
string
):
void
;
...
...
src/vs/editor/browser/view/viewController.ts
浏览文件 @
9df54d6f
...
...
@@ -4,14 +4,13 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
EventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
IKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
IEditorMouseEvent
,
I
MouseTarget
,
I
ViewController
,
IMouseDispatchData
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
IEditorMouseEvent
,
IViewController
,
IMouseDispatchData
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
IViewModel
}
from
'
vs/editor/common/viewModel/viewModel
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ViewOutgoingEvents
}
from
'
vs/editor/browser/view/viewOutgoingEvents
'
;
export
interface
TriggerCursorHandler
{
(
source
:
string
,
handlerId
:
string
,
payload
:
any
):
void
;
...
...
@@ -21,18 +20,18 @@ export class ViewController implements IViewController {
private
viewModel
:
IViewModel
;
private
triggerCursorHandler
:
TriggerCursorHandler
;
private
outgoingEvent
Bus
:
EventEmitter
;
private
outgoingEvent
s
:
ViewOutgoingEvents
;
private
commandService
:
ICommandService
;
constructor
(
viewModel
:
IViewModel
,
triggerCursorHandler
:
TriggerCursorHandler
,
outgoingEvent
Bus
:
EventEmitter
,
outgoingEvent
s
:
ViewOutgoingEvents
,
commandService
:
ICommandService
)
{
this
.
viewModel
=
viewModel
;
this
.
triggerCursorHandler
=
triggerCursorHandler
;
this
.
outgoingEvent
Bus
=
outgoingEventBu
s
;
this
.
outgoingEvent
s
=
outgoingEvent
s
;
this
.
commandService
=
commandService
;
}
...
...
@@ -247,57 +246,31 @@ export class ViewController implements IViewController {
return
this
.
viewModel
.
convertViewPositionToModelPosition
(
viewPosition
.
lineNumber
,
viewPosition
.
column
);
}
private
convertViewToModelRange
(
viewRange
:
Range
):
Range
{
return
this
.
viewModel
.
convertViewRangeToModelRange
(
viewRange
);
}
private
_convertViewToModelMouseTarget
(
target
:
IMouseTarget
):
IMouseTarget
{
return
{
element
:
target
.
element
,
type
:
target
.
type
,
position
:
target
.
position
?
this
.
convertViewToModelPosition
(
target
.
position
)
:
null
,
mouseColumn
:
target
.
mouseColumn
,
range
:
target
.
range
?
this
.
convertViewToModelRange
(
target
.
range
)
:
null
,
detail
:
target
.
detail
};
}
private
_convertViewToModelMouseEvent
(
e
:
IEditorMouseEvent
):
IEditorMouseEvent
{
if
(
e
.
target
)
{
return
{
event
:
e
.
event
,
target
:
this
.
_convertViewToModelMouseTarget
(
e
.
target
)
};
}
return
e
;
}
public
emitKeyDown
(
e
:
IKeyboardEvent
):
void
{
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
KeyDown
,
e
);
this
.
outgoingEvent
s
.
emitKeyDown
(
e
);
}
public
emitKeyUp
(
e
:
IKeyboardEvent
):
void
{
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
KeyUp
,
e
);
this
.
outgoingEvent
s
.
emitKeyUp
(
e
);
}
public
emitContextMenu
(
e
:
IEditorMouseEvent
):
void
{
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
ContextMenu
,
this
.
_convertViewToModelMouseEvent
(
e
)
);
this
.
outgoingEvent
s
.
emitContextMenu
(
e
);
}
public
emitMouseMove
(
e
:
IEditorMouseEvent
):
void
{
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
MouseMove
,
this
.
_convertViewToModelMouseEvent
(
e
)
);
this
.
outgoingEvent
s
.
emitMouseMove
(
e
);
}
public
emitMouseLeave
(
e
:
IEditorMouseEvent
):
void
{
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
MouseLeave
,
this
.
_convertViewToModelMouseEvent
(
e
)
);
this
.
outgoingEvent
s
.
emitMouseLeave
(
e
);
}
public
emitMouseUp
(
e
:
IEditorMouseEvent
):
void
{
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
MouseUp
,
this
.
_convertViewToModelMouseEvent
(
e
)
);
this
.
outgoingEvent
s
.
emitMouseUp
(
e
);
}
public
emitMouseDown
(
e
:
IEditorMouseEvent
):
void
{
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
MouseDown
,
this
.
_convertViewToModelMouseEvent
(
e
)
);
this
.
outgoingEvent
s
.
emitMouseDown
(
e
);
}
}
\ No newline at end of file
}
src/vs/editor/browser/view/viewImpl.ts
浏览文件 @
9df54d6f
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
E
ventEmitter
,
E
mitterEvent
,
IEventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
EmitterEvent
,
IEventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
timer
from
'
vs/base/common/timer
'
;
import
*
as
browser
from
'
vs/base/browser/browser
'
;
...
...
@@ -49,6 +49,7 @@ import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
import
{
ViewLinesViewportData
}
from
'
vs/editor/common/viewLayout/viewLinesViewportData
'
;
import
{
IRenderingContext
}
from
'
vs/editor/common/view/renderingContext
'
;
import
{
IPointerHandlerHelper
}
from
'
vs/editor/browser/controller/mouseHandler
'
;
import
{
ViewOutgoingEvents
}
from
'
vs/editor/browser/view/viewOutgoingEvents
'
;
export
class
View
extends
ViewEventHandler
implements
editorBrowser
.
IView
,
IDisposable
{
...
...
@@ -73,7 +74,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
private
keyboardHandler
:
KeyboardHandler
;
private
pointerHandler
:
PointerHandler
;
private
outgoingEvent
Bus
:
EventEmitter
;
private
outgoingEvent
s
:
ViewOutgoingEvents
;
// Dom nodes
private
linesContent
:
HTMLElement
;
...
...
@@ -100,9 +101,9 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
super
();
this
.
_isDisposed
=
false
;
this
.
_renderAnimationFrame
=
null
;
this
.
outgoingEvent
Bus
=
new
EventEmitter
(
);
this
.
outgoingEvent
s
=
new
ViewOutgoingEvents
(
model
);
let
viewController
=
new
ViewController
(
model
,
triggerCursorHandler
,
this
.
outgoingEvent
Bu
s
,
commandService
);
let
viewController
=
new
ViewController
(
model
,
triggerCursorHandler
,
this
.
outgoingEvents
,
commandService
);
this
.
listenersToRemove
=
[];
this
.
listenersToDispose
=
[];
...
...
@@ -463,7 +464,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
StyleMutator
.
setWidth
(
this
.
linesContentContainer
,
layoutInfo
.
contentWidth
);
StyleMutator
.
setHeight
(
this
.
linesContentContainer
,
layoutInfo
.
contentHeight
);
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
ViewLayoutChanged
,
layoutInfo
);
this
.
outgoingEvent
s
.
emitViewLayoutChanged
(
layoutInfo
);
return
false
;
}
public
onConfigurationChanged
(
e
:
editorCommon
.
IConfigurationChangedEvent
):
boolean
{
...
...
@@ -476,15 +477,15 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
return
false
;
}
public
onScrollChanged
(
e
:
editorCommon
.
IScrollEvent
):
boolean
{
this
.
outgoingEvent
Bus
.
emit
(
'
scroll
'
,
e
);
this
.
outgoingEvent
s
.
emitScrollChanged
(
e
);
return
false
;
}
public
onViewFocusChanged
(
isFocused
:
boolean
):
boolean
{
dom
.
toggleClass
(
this
.
domNode
,
'
focused
'
,
isFocused
);
if
(
isFocused
)
{
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
ViewFocusGained
,
{}
);
this
.
outgoingEvent
s
.
emitViewFocusGained
(
);
}
else
{
this
.
outgoingEvent
Bus
.
emit
(
editorCommon
.
EventType
.
ViewFocusLost
,
{}
);
this
.
outgoingEvent
s
.
emitViewFocusLost
(
);
}
return
false
;
}
...
...
@@ -516,7 +517,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
this
.
accumulatedModelEvents
=
[];
this
.
eventDispatcher
.
removeEventHandler
(
this
);
this
.
outgoingEvent
Bu
s
.
dispose
();
this
.
outgoingEvents
.
dispose
();
this
.
listenersToRemove
=
dispose
(
this
.
listenersToRemove
);
this
.
listenersToDispose
=
dispose
(
this
.
listenersToDispose
);
...
...
@@ -637,7 +638,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
if
(
this
.
_isDisposed
)
{
throw
new
Error
(
'
ViewImpl.getInternalEventBus: View is disposed
'
);
}
return
this
.
outgoingEvent
Bus
;
return
this
.
outgoingEvent
s
.
getInternalEventBus
()
;
}
public
saveState
():
editorCommon
.
IViewState
{
...
...
@@ -687,6 +688,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
throw
new
Error
(
'
ViewImpl.change: View is disposed
'
);
}
let
zonesHaveChanged
=
false
;
this
.
_renderOnce
(()
=>
{
// Handle events to avoid "adjusting" newly inserted view zones
this
.
_flushAnyAccumulatedEvents
();
...
...
@@ -735,10 +737,9 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
if
(
this
.
_isDisposed
)
{
throw
new
Error
(
'
ViewImpl.addContentWidget: View is disposed
'
);
}
this
.
_renderOnce
(()
=>
{
this
.
contentWidgets
.
addWidget
(
widgetData
.
widget
);
this
.
layoutContentWidget
(
widgetData
);
});
this
.
contentWidgets
.
addWidget
(
widgetData
.
widget
);
this
.
layoutContentWidget
(
widgetData
);
this
.
_scheduleRender
();
}
public
layoutContentWidget
(
widgetData
:
editorBrowser
.
IContentWidgetData
):
void
{
...
...
@@ -746,30 +747,27 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
throw
new
Error
(
'
ViewImpl.layoutContentWidget: View is disposed
'
);
}
this
.
_renderOnce
(()
=>
{
let
newPosition
=
widgetData
.
position
?
widgetData
.
position
.
position
:
null
;
let
newPreference
=
widgetData
.
position
?
widgetData
.
position
.
preference
:
null
;
this
.
contentWidgets
.
setWidgetPosition
(
widgetData
.
widget
,
newPosition
,
newPreference
);
});
let
newPosition
=
widgetData
.
position
?
widgetData
.
position
.
position
:
null
;
let
newPreference
=
widgetData
.
position
?
widgetData
.
position
.
preference
:
null
;
this
.
contentWidgets
.
setWidgetPosition
(
widgetData
.
widget
,
newPosition
,
newPreference
);
this
.
_scheduleRender
();
}
public
removeContentWidget
(
widgetData
:
editorBrowser
.
IContentWidgetData
):
void
{
if
(
this
.
_isDisposed
)
{
throw
new
Error
(
'
ViewImpl.removeContentWidget: View is disposed
'
);
}
this
.
_renderOnce
(()
=>
{
this
.
contentWidgets
.
removeWidget
(
widgetData
.
widget
);
});
this
.
contentWidgets
.
removeWidget
(
widgetData
.
widget
);
this
.
_scheduleRender
();
}
public
addOverlayWidget
(
widgetData
:
editorBrowser
.
IOverlayWidgetData
):
void
{
if
(
this
.
_isDisposed
)
{
throw
new
Error
(
'
ViewImpl.addOverlayWidget: View is disposed
'
);
}
this
.
_renderOnce
(()
=>
{
this
.
overlayWidgets
.
addWidget
(
widgetData
.
widget
);
this
.
layoutOverlayWidget
(
widgetData
);
});
this
.
overlayWidgets
.
addWidget
(
widgetData
.
widget
);
this
.
layoutOverlayWidget
(
widgetData
);
this
.
_scheduleRender
();
}
public
layoutOverlayWidget
(
widgetData
:
editorBrowser
.
IOverlayWidgetData
):
void
{
...
...
@@ -788,9 +786,8 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
if
(
this
.
_isDisposed
)
{
throw
new
Error
(
'
ViewImpl.removeOverlayWidget: View is disposed
'
);
}
this
.
_renderOnce
(()
=>
{
this
.
overlayWidgets
.
removeWidget
(
widgetData
.
widget
);
});
this
.
overlayWidgets
.
removeWidget
(
widgetData
.
widget
);
this
.
_scheduleRender
();
}
public
render
(
now
:
boolean
,
everything
:
boolean
):
void
{
...
...
@@ -806,20 +803,13 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp
}
}
public
renderOnce
(
callback
:
()
=>
any
):
any
{
if
(
this
.
_isDisposed
)
{
throw
new
Error
(
'
ViewImpl.renderOnce: View is disposed
'
);
}
return
this
.
_renderOnce
(
callback
);
}
// --- end Code Editor APIs
private
_renderOnce
(
callback
:
()
=>
any
):
any
{
if
(
this
.
_isDisposed
)
{
throw
new
Error
(
'
ViewImpl._renderOnce: View is disposed
'
);
}
return
this
.
outgoingEvent
Bu
s
.
deferredEmit
(()
=>
{
return
this
.
outgoingEvents
.
deferredEmit
(()
=>
{
let
r
=
safeInvokeNoArg
(
callback
);
this
.
_scheduleRender
();
return
r
;
...
...
src/vs/editor/browser/view/viewOutgoingEvents.ts
0 → 100644
浏览文件 @
9df54d6f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
EventEmitter
,
IEventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IViewModel
}
from
'
vs/editor/common/viewModel/viewModel
'
;
import
{
EventType
,
EditorLayoutInfo
,
IScrollEvent
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IEditorMouseEvent
,
IMouseTarget
}
from
'
vs/editor/browser/editorBrowser
'
;
export
class
ViewOutgoingEvents
extends
Disposable
{
private
_viewModel
:
IViewModel
;
private
_actual
:
EventEmitter
;
constructor
(
viewModel
:
IViewModel
)
{
super
();
this
.
_actual
=
this
.
_register
(
new
EventEmitter
());
}
public
getInternalEventBus
():
IEventEmitter
{
return
this
.
_actual
;
}
public
deferredEmit
<
T
>
(
callback
:
()
=>
T
):
T
{
return
this
.
_actual
.
deferredEmit
(
callback
);
}
public
emitViewLayoutChanged
(
layoutInfo
:
EditorLayoutInfo
):
void
{
this
.
_actual
.
emit
(
EventType
.
ViewLayoutChanged
,
layoutInfo
);
}
public
emitScrollChanged
(
e
:
IScrollEvent
):
void
{
this
.
_actual
.
emit
(
'
scroll
'
,
e
);
}
public
emitViewFocusGained
():
void
{
this
.
_actual
.
emit
(
EventType
.
ViewFocusGained
,
{});
}
public
emitViewFocusLost
():
void
{
this
.
_actual
.
emit
(
EventType
.
ViewFocusLost
,
{});
}
public
emitKeyDown
(
e
:
IKeyboardEvent
):
void
{
this
.
_actual
.
emit
(
EventType
.
KeyDown
,
e
);
}
public
emitKeyUp
(
e
:
IKeyboardEvent
):
void
{
this
.
_actual
.
emit
(
EventType
.
KeyUp
,
e
);
}
public
emitContextMenu
(
e
:
IEditorMouseEvent
):
void
{
this
.
_actual
.
emit
(
EventType
.
ContextMenu
,
this
.
_convertViewToModelMouseEvent
(
e
));
}
public
emitMouseMove
(
e
:
IEditorMouseEvent
):
void
{
this
.
_actual
.
emit
(
EventType
.
MouseMove
,
this
.
_convertViewToModelMouseEvent
(
e
));
}
public
emitMouseLeave
(
e
:
IEditorMouseEvent
):
void
{
this
.
_actual
.
emit
(
EventType
.
MouseLeave
,
this
.
_convertViewToModelMouseEvent
(
e
));
}
public
emitMouseUp
(
e
:
IEditorMouseEvent
):
void
{
this
.
_actual
.
emit
(
EventType
.
MouseUp
,
this
.
_convertViewToModelMouseEvent
(
e
));
}
public
emitMouseDown
(
e
:
IEditorMouseEvent
):
void
{
this
.
_actual
.
emit
(
EventType
.
MouseDown
,
this
.
_convertViewToModelMouseEvent
(
e
));
}
private
_convertViewToModelMouseEvent
(
e
:
IEditorMouseEvent
):
IEditorMouseEvent
{
if
(
e
.
target
)
{
return
{
event
:
e
.
event
,
target
:
this
.
_convertViewToModelMouseTarget
(
e
.
target
)
};
}
return
e
;
}
private
_convertViewToModelMouseTarget
(
target
:
IMouseTarget
):
IMouseTarget
{
return
{
element
:
target
.
element
,
type
:
target
.
type
,
position
:
target
.
position
?
this
.
_convertViewToModelPosition
(
target
.
position
)
:
null
,
mouseColumn
:
target
.
mouseColumn
,
range
:
target
.
range
?
this
.
_convertViewToModelRange
(
target
.
range
)
:
null
,
detail
:
target
.
detail
};
}
private
_convertViewToModelPosition
(
viewPosition
:
Position
):
Position
{
return
this
.
_viewModel
.
convertViewPositionToModelPosition
(
viewPosition
.
lineNumber
,
viewPosition
.
column
);
}
private
_convertViewToModelRange
(
viewRange
:
Range
):
Range
{
return
this
.
_viewModel
.
convertViewRangeToModelRange
(
viewRange
);
}
}
src/vs/editor/browser/widget/codeEditorWidget.ts
浏览文件 @
9df54d6f
...
...
@@ -462,23 +462,20 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
if
(
this
.
_view
)
{
this
.
domElement
.
appendChild
(
this
.
_view
.
domNode
);
this
.
_view
.
renderOnce
(()
=>
{
let
keys
=
Object
.
keys
(
this
.
contentWidgets
);
for
(
let
i
=
0
,
len
=
keys
.
length
;
i
<
len
;
i
++
)
{
let
widgetId
=
keys
[
i
];
this
.
_view
.
addContentWidget
(
this
.
contentWidgets
[
widgetId
]);
}
let
keys
=
Object
.
keys
(
this
.
contentWidgets
);
for
(
let
i
=
0
,
len
=
keys
.
length
;
i
<
len
;
i
++
)
{
let
widgetId
=
keys
[
i
];
this
.
_view
.
addContentWidget
(
this
.
contentWidgets
[
widgetId
]);
}
keys
=
Object
.
keys
(
this
.
overlayWidgets
);
for
(
let
i
=
0
,
len
=
keys
.
length
;
i
<
len
;
i
++
)
{
let
widgetId
=
keys
[
i
];
this
.
_view
.
addOverlayWidget
(
this
.
overlayWidgets
[
widgetId
]);
}
keys
=
Object
.
keys
(
this
.
overlayWidgets
);
for
(
let
i
=
0
,
len
=
keys
.
length
;
i
<
len
;
i
++
)
{
let
widgetId
=
keys
[
i
];
this
.
_view
.
addOverlayWidget
(
this
.
overlayWidgets
[
widgetId
]);
}
this
.
_view
.
render
(
false
,
true
);
this
.
hasView
=
true
;
});
this
.
_view
.
render
(
false
,
true
);
this
.
hasView
=
true
;
}
}
...
...
src/vs/editor/common/viewModel/viewModelImpl.ts
浏览文件 @
9df54d6f
...
...
@@ -91,14 +91,21 @@ export class ViewModel extends EventEmitter implements IViewModel {
}
public
setHiddenAreas
(
ranges
:
editorCommon
.
IRange
[]):
void
{
this
.
deferredEmit
(()
=>
{
let
lineMappingChanged
=
this
.
lines
.
setHiddenAreas
(
ranges
,
(
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
if
(
lineMappingChanged
)
{
this
.
emit
(
editorCommon
.
ViewEventNames
.
LineMappingChangedEvent
);
this
.
decorations
.
onLineMappingChanged
((
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
this
.
cursors
.
onLineMappingChanged
((
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
}
});
try
{
this
.
_beginDeferredEmit
();
this
.
_setHiddenAreas
(
ranges
);
}
finally
{
this
.
_endDeferredEmit
();
}
}
private
_setHiddenAreas
(
ranges
:
editorCommon
.
IRange
[]):
void
{
let
lineMappingChanged
=
this
.
lines
.
setHiddenAreas
(
ranges
,
(
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
if
(
lineMappingChanged
)
{
this
.
emit
(
editorCommon
.
ViewEventNames
.
LineMappingChangedEvent
);
this
.
decorations
.
onLineMappingChanged
((
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
this
.
cursors
.
onLineMappingChanged
((
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
}
}
public
dispose
():
void
{
...
...
@@ -161,141 +168,147 @@ export class ViewModel extends EventEmitter implements IViewModel {
}
private
onEvents
(
events
:
EmitterEvent
[]):
void
{
this
.
deferredEmit
(()
=>
{
try
{
this
.
_beginDeferredEmit
();
this
.
_onEvents
(
events
);
}
finally
{
this
.
_endDeferredEmit
();
}
}
let
hasContentChange
=
events
.
some
((
e
)
=>
e
.
getType
()
===
editorCommon
.
EventType
.
ModelRawContentChanged
),
previousCenteredModelRange
:
Range
;
if
(
!
hasContentChange
)
{
// We can only convert the current centered view range to the current centered model range if the model has no changes.
previousCenteredModelRange
=
this
.
getCurrentCenteredModelRange
();
}
private
_onEvents
(
events
:
EmitterEvent
[]):
void
{
let
hasContentChange
=
events
.
some
((
e
)
=>
e
.
getType
()
===
editorCommon
.
EventType
.
ModelRawContentChanged
),
previousCenteredModelRange
:
Range
;
if
(
!
hasContentChange
)
{
// We can only convert the current centered view range to the current centered model range if the model has no changes.
previousCenteredModelRange
=
this
.
getCurrentCenteredModelRange
();
}
let
i
:
number
,
len
:
number
,
e
:
EmitterEvent
,
data
:
any
,
modelContentChangedEvent
:
editorCommon
.
IModelContentChangedEvent
,
hadOtherModelChange
=
false
,
hadModelLineChangeThatChangedLineMapping
=
false
,
revealPreviousCenteredModelRange
=
false
;
for
(
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
e
=
events
[
i
];
data
=
e
.
getData
();
switch
(
e
.
getType
())
{
case
editorCommon
.
EventType
.
ModelRawContentChanged
:
modelContentChangedEvent
=
<
editorCommon
.
IModelContentChangedEvent
>
data
;
switch
(
modelContentChangedEvent
.
changeType
)
{
case
editorCommon
.
EventType
.
ModelRawContentChangedFlush
:
this
.
onModelFlushed
(
<
editorCommon
.
IModelContentChangedFlushEvent
>
modelContentChangedEvent
);
hadOtherModelChange
=
true
;
break
;
case
editorCommon
.
EventType
.
ModelRawContentChangedLinesDeleted
:
this
.
onModelLinesDeleted
(
<
editorCommon
.
IModelContentChangedLinesDeletedEvent
>
modelContentChangedEvent
);
hadOtherModelChange
=
true
;
break
;
case
editorCommon
.
EventType
.
ModelRawContentChangedLinesInserted
:
this
.
onModelLinesInserted
(
<
editorCommon
.
IModelContentChangedLinesInsertedEvent
>
modelContentChangedEvent
);
hadOtherModelChange
=
true
;
break
;
case
editorCommon
.
EventType
.
ModelRawContentChangedLineChanged
:
hadModelLineChangeThatChangedLineMapping
=
this
.
onModelLineChanged
(
<
editorCommon
.
IModelContentChangedLineChangedEvent
>
modelContentChangedEvent
);
break
;
default
:
console
.
info
(
'
ViewModel received unknown event:
'
);
console
.
info
(
e
);
}
break
;
case
editorCommon
.
EventType
.
ModelTokensChanged
:
this
.
onModelTokensChanged
(
<
editorCommon
.
IModelTokensChangedEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
ModelModeChanged
:
// That's ok, a model tokens changed event will follow shortly
break
;
case
editorCommon
.
EventType
.
ModelContentChanged2
:
// Ignore
break
;
case
editorCommon
.
EventType
.
ModelOptionsChanged
:
// A tab size change causes a line mapping changed event => all view parts will repaint OK, no further event needed here
let
prevLineCount
=
this
.
lines
.
getOutputLineCount
();
let
tabSizeChanged
=
this
.
_onTabSizeChange
(
this
.
model
.
getOptions
().
tabSize
);
let
newLineCount
=
this
.
lines
.
getOutputLineCount
();
if
(
tabSizeChanged
&&
prevLineCount
!==
newLineCount
)
{
revealPreviousCenteredModelRange
=
true
;
}
break
;
case
editorCommon
.
EventType
.
ModelDecorationsChanged
:
this
.
onModelDecorationsChanged
(
<
editorCommon
.
IModelDecorationsChangedEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
ModelDispose
:
// Ignore, since the editor will take care of this and destroy the view shortly
break
;
case
editorCommon
.
EventType
.
CursorPositionChanged
:
this
.
onCursorPositionChanged
(
<
editorCommon
.
ICursorPositionChangedEvent
>
data
);
this
.
_lastCursorPosition
=
(
<
editorCommon
.
ICursorPositionChangedEvent
>
data
).
position
;
break
;
case
editorCommon
.
EventType
.
CursorSelectionChanged
:
this
.
onCursorSelectionChanged
(
<
editorCommon
.
ICursorSelectionChangedEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
CursorRevealRange
:
this
.
onCursorRevealRange
(
<
editorCommon
.
ICursorRevealRangeEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
CursorScrollRequest
:
this
.
onCursorScrollRequest
(
<
editorCommon
.
ICursorScrollRequestEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
ConfigurationChanged
:
revealPreviousCenteredModelRange
=
this
.
_onWrappingIndentChange
(
this
.
configuration
.
editor
.
wrappingInfo
.
wrappingIndent
)
||
revealPreviousCenteredModelRange
;
revealPreviousCenteredModelRange
=
this
.
_onWrappingColumnChange
(
this
.
configuration
.
editor
.
wrappingInfo
.
wrappingColumn
,
this
.
configuration
.
editor
.
fontInfo
.
typicalFullwidthCharacterWidth
/
this
.
configuration
.
editor
.
fontInfo
.
typicalHalfwidthCharacterWidth
)
||
revealPreviousCenteredModelRange
;
this
.
_renderCustomLineNumbers
=
this
.
configuration
.
editor
.
viewInfo
.
renderCustomLineNumbers
;
this
.
_renderRelativeLineNumbers
=
this
.
configuration
.
editor
.
viewInfo
.
renderRelativeLineNumbers
;
if
((
<
editorCommon
.
IConfigurationChangedEvent
>
data
).
readOnly
)
{
// Must read again all decorations due to readOnly filtering
this
.
decorations
.
reset
(
this
.
model
);
var
decorationsChangedEvent
:
editorCommon
.
IViewDecorationsChangedEvent
=
{
inlineDecorationsChanged
:
false
};
this
.
emit
(
editorCommon
.
ViewEventNames
.
DecorationsChangedEvent
,
decorationsChangedEvent
);
}
this
.
emit
(
e
.
getType
(),
<
editorCommon
.
IConfigurationChangedEvent
>
data
);
break
;
default
:
console
.
info
(
'
View received unknown event:
'
);
console
.
info
(
e
);
}
let
i
:
number
,
len
:
number
,
e
:
EmitterEvent
,
data
:
any
,
modelContentChangedEvent
:
editorCommon
.
IModelContentChangedEvent
,
hadOtherModelChange
=
false
,
hadModelLineChangeThatChangedLineMapping
=
false
,
revealPreviousCenteredModelRange
=
false
;
for
(
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
e
=
events
[
i
];
data
=
e
.
getData
();
switch
(
e
.
getType
())
{
case
editorCommon
.
EventType
.
ModelRawContentChanged
:
modelContentChangedEvent
=
<
editorCommon
.
IModelContentChangedEvent
>
data
;
switch
(
modelContentChangedEvent
.
changeType
)
{
case
editorCommon
.
EventType
.
ModelRawContentChangedFlush
:
this
.
onModelFlushed
(
<
editorCommon
.
IModelContentChangedFlushEvent
>
modelContentChangedEvent
);
hadOtherModelChange
=
true
;
break
;
case
editorCommon
.
EventType
.
ModelRawContentChangedLinesDeleted
:
this
.
onModelLinesDeleted
(
<
editorCommon
.
IModelContentChangedLinesDeletedEvent
>
modelContentChangedEvent
);
hadOtherModelChange
=
true
;
break
;
case
editorCommon
.
EventType
.
ModelRawContentChangedLinesInserted
:
this
.
onModelLinesInserted
(
<
editorCommon
.
IModelContentChangedLinesInsertedEvent
>
modelContentChangedEvent
);
hadOtherModelChange
=
true
;
break
;
case
editorCommon
.
EventType
.
ModelRawContentChangedLineChanged
:
hadModelLineChangeThatChangedLineMapping
=
this
.
onModelLineChanged
(
<
editorCommon
.
IModelContentChangedLineChangedEvent
>
modelContentChangedEvent
);
break
;
default
:
console
.
info
(
'
ViewModel received unknown event:
'
);
console
.
info
(
e
);
}
break
;
case
editorCommon
.
EventType
.
ModelTokensChanged
:
this
.
onModelTokensChanged
(
<
editorCommon
.
IModelTokensChangedEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
ModelModeChanged
:
// That's ok, a model tokens changed event will follow shortly
break
;
case
editorCommon
.
EventType
.
ModelContentChanged2
:
// Ignore
break
;
case
editorCommon
.
EventType
.
ModelOptionsChanged
:
// A tab size change causes a line mapping changed event => all view parts will repaint OK, no further event needed here
let
prevLineCount
=
this
.
lines
.
getOutputLineCount
();
let
tabSizeChanged
=
this
.
_onTabSizeChange
(
this
.
model
.
getOptions
().
tabSize
);
let
newLineCount
=
this
.
lines
.
getOutputLineCount
();
if
(
tabSizeChanged
&&
prevLineCount
!==
newLineCount
)
{
revealPreviousCenteredModelRange
=
true
;
}
break
;
case
editorCommon
.
EventType
.
ModelDecorationsChanged
:
this
.
onModelDecorationsChanged
(
<
editorCommon
.
IModelDecorationsChangedEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
ModelDispose
:
// Ignore, since the editor will take care of this and destroy the view shortly
break
;
case
editorCommon
.
EventType
.
CursorPositionChanged
:
this
.
onCursorPositionChanged
(
<
editorCommon
.
ICursorPositionChangedEvent
>
data
);
this
.
_lastCursorPosition
=
(
<
editorCommon
.
ICursorPositionChangedEvent
>
data
).
position
;
break
;
case
editorCommon
.
EventType
.
CursorSelectionChanged
:
this
.
onCursorSelectionChanged
(
<
editorCommon
.
ICursorSelectionChangedEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
CursorRevealRange
:
this
.
onCursorRevealRange
(
<
editorCommon
.
ICursorRevealRangeEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
CursorScrollRequest
:
this
.
onCursorScrollRequest
(
<
editorCommon
.
ICursorScrollRequestEvent
>
data
);
break
;
case
editorCommon
.
EventType
.
ConfigurationChanged
:
revealPreviousCenteredModelRange
=
this
.
_onWrappingIndentChange
(
this
.
configuration
.
editor
.
wrappingInfo
.
wrappingIndent
)
||
revealPreviousCenteredModelRange
;
revealPreviousCenteredModelRange
=
this
.
_onWrappingColumnChange
(
this
.
configuration
.
editor
.
wrappingInfo
.
wrappingColumn
,
this
.
configuration
.
editor
.
fontInfo
.
typicalFullwidthCharacterWidth
/
this
.
configuration
.
editor
.
fontInfo
.
typicalHalfwidthCharacterWidth
)
||
revealPreviousCenteredModelRange
;
this
.
_renderCustomLineNumbers
=
this
.
configuration
.
editor
.
viewInfo
.
renderCustomLineNumbers
;
this
.
_renderRelativeLineNumbers
=
this
.
configuration
.
editor
.
viewInfo
.
renderRelativeLineNumbers
;
if
((
<
editorCommon
.
IConfigurationChangedEvent
>
data
).
readOnly
)
{
// Must read again all decorations due to readOnly filtering
this
.
decorations
.
reset
(
this
.
model
);
var
decorationsChangedEvent
:
editorCommon
.
IViewDecorationsChangedEvent
=
{
inlineDecorationsChanged
:
false
};
this
.
emit
(
editorCommon
.
ViewEventNames
.
DecorationsChangedEvent
,
decorationsChangedEvent
);
}
this
.
emit
(
e
.
getType
(),
<
editorCommon
.
IConfigurationChangedEvent
>
data
);
break
;
default
:
console
.
info
(
'
View received unknown event:
'
);
console
.
info
(
e
);
}
}
if
(
!
hadOtherModelChange
&&
hadModelLineChangeThatChangedLineMapping
)
{
this
.
emit
(
editorCommon
.
ViewEventNames
.
LineMappingChangedEvent
);
this
.
decorations
.
onLineMappingChanged
((
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
this
.
cursors
.
onLineMappingChanged
((
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
}
if
(
!
hadOtherModelChange
&&
hadModelLineChangeThatChangedLineMapping
)
{
this
.
emit
(
editorCommon
.
ViewEventNames
.
LineMappingChangedEvent
);
this
.
decorations
.
onLineMappingChanged
((
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
this
.
cursors
.
onLineMappingChanged
((
eventType
:
string
,
payload
:
any
)
=>
this
.
emit
(
eventType
,
payload
));
}
if
(
revealPreviousCenteredModelRange
&&
previousCenteredModelRange
)
{
this
.
_restoreCenteredModelRange
(
previousCenteredModelRange
);
}
});
if
(
revealPreviousCenteredModelRange
&&
previousCenteredModelRange
)
{
this
.
_restoreCenteredModelRange
(
previousCenteredModelRange
);
}
}
// --- begin inbound event conversion
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录