Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
e823738f
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,发现更多精彩内容 >>
提交
e823738f
编写于
2月 14, 2017
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
distingush mouse down/up and mosue drag/drop
上级
144782b5
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
84 addition
and
52 deletion
+84
-52
src/vs/editor/browser/controller/mouseHandler.ts
src/vs/editor/browser/controller/mouseHandler.ts
+23
-2
src/vs/editor/browser/editorBrowser.ts
src/vs/editor/browser/editorBrowser.ts
+6
-1
src/vs/editor/browser/view/viewController.ts
src/vs/editor/browser/view/viewController.ts
+8
-8
src/vs/editor/browser/view/viewOutgoingEvents.ts
src/vs/editor/browser/view/viewOutgoingEvents.ts
+4
-0
src/vs/editor/browser/widget/codeEditorWidget.ts
src/vs/editor/browser/widget/codeEditorWidget.ts
+1
-0
src/vs/editor/common/commonCodeEditor.ts
src/vs/editor/common/commonCodeEditor.ts
+4
-0
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+0
-38
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+1
-0
src/vs/editor/contrib/dragAndDrop/browser/dragAndDrop.ts
src/vs/editor/contrib/dragAndDrop/browser/dragAndDrop.ts
+31
-3
src/vs/editor/contrib/dragAndDrop/common/dragAndDropCommand.ts
...s/editor/contrib/dragAndDrop/common/dragAndDropCommand.ts
+1
-0
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+5
-0
未找到文件。
src/vs/editor/browser/controller/mouseHandler.ts
浏览文件 @
e823738f
...
...
@@ -418,6 +418,7 @@ class MouseDownOperation extends Disposable {
private
_onMouseDragThenMove
(
e
:
EditorMouseEvent
):
void
{
this
.
_lastMouseEvent
=
e
;
this
.
_mouseState
.
setModifiers
(
e
);
this
.
_mouseState
.
setMouseDownEvent
(
'
drag
'
);
let
position
=
this
.
_findMousePosition
(
e
,
true
);
if
(
!
position
)
{
...
...
@@ -437,7 +438,7 @@ class MouseDownOperation extends Disposable {
this
.
_mouseState
.
setStartedOnLineNumbers
(
targetType
===
editorCommon
.
MouseTargetType
.
GUTTER_LINE_NUMBERS
);
this
.
_mouseState
.
setModifiers
(
e
);
this
.
_mouseState
.
setMouseDownEvent
(
'
down
'
);
let
position
=
this
.
_findMousePosition
(
e
,
true
);
if
(
!
position
)
{
// Ignoring because position is unknown
...
...
@@ -452,6 +453,7 @@ class MouseDownOperation extends Disposable {
if
(
!
this
.
_mouseState
.
altKey
// we don't support multiple mouse
&&
e
.
detail
<
2
// only single click on a selection can work
&&
!
this
.
_isActive
// the mouse is not down yet
&&
!
this
.
_currentSelection
.
isEmpty
()
// we don't drag single cursor
&&
this
.
_currentSelection
.
containsPosition
(
position
.
position
)
// single click on a selection
)
{
this
.
_isActive
=
true
;
...
...
@@ -461,7 +463,16 @@ class MouseDownOperation extends Disposable {
createMouseMoveEventMerger
(
null
),
this
.
_mouseDragThenMoveEventHandler
.
handler
,
()
=>
{
this
.
_viewController
.
dragTo
(
'
mouse
'
,
this
.
_dragTargetPosition
);
if
(
this
.
_mouseState
.
lastMouseDownEvent
!==
'
drag
'
)
{
// the last event is mouse down which happens 16ms ago.
this
.
_dispatchMouse
(
position
,
e
.
shiftKey
);
}
else
{
this
.
_viewController
.
emitMouseDrop
({
event
:
e
,
target
:
this
.
_createMouseTarget
(
e
,
true
)
});
}
this
.
_stop
();
}
);
...
...
@@ -602,6 +613,7 @@ class MouseDownState {
private
_lastMouseDownPositionEqualCount
:
number
;
private
_lastMouseDownCount
:
number
;
private
_lastSetMouseDownCountTime
:
number
;
private
_lastMouseDownEvent
:
'
down
'
|
'
drag
'
|
'
move
'
;
constructor
()
{
this
.
_altKey
=
false
;
...
...
@@ -613,12 +625,17 @@ class MouseDownState {
this
.
_lastMouseDownPositionEqualCount
=
0
;
this
.
_lastMouseDownCount
=
0
;
this
.
_lastSetMouseDownCountTime
=
0
;
this
.
_lastMouseDownEvent
=
'
down
'
;
}
public
get
count
():
number
{
return
this
.
_lastMouseDownCount
;
}
public
get
lastMouseDownEvent
():
'
down
'
|
'
drag
'
|
'
move
'
{
return
this
.
_lastMouseDownEvent
;
}
public
setModifiers
(
source
:
EditorMouseEvent
)
{
this
.
_altKey
=
source
.
altKey
;
this
.
_ctrlKey
=
source
.
ctrlKey
;
...
...
@@ -626,6 +643,10 @@ class MouseDownState {
this
.
_shiftKey
=
source
.
shiftKey
;
}
public
setMouseDownEvent
(
event
:
'
down
'
|
'
drag
'
|
'
move
'
)
{
this
.
_lastMouseDownEvent
=
event
;
}
public
setStartedOnLineNumbers
(
startedOnLineNumbers
:
boolean
):
void
{
this
.
_startedOnLineNumbers
=
startedOnLineNumbers
;
}
...
...
src/vs/editor/browser/editorBrowser.ts
浏览文件 @
e823738f
...
...
@@ -120,7 +120,6 @@ export interface IMouseDispatchData {
export
interface
IViewController
{
dispatchMouse
(
data
:
IMouseDispatchData
);
dragTo
(
source
:
string
,
position
:
Position
):
void
;
moveTo
(
source
:
string
,
position
:
Position
):
void
;
paste
(
source
:
string
,
text
:
string
,
pasteOnNewLine
:
boolean
):
void
;
...
...
@@ -138,6 +137,7 @@ export interface IViewController {
emitMouseUp
(
e
:
IEditorMouseEvent
):
void
;
emitMouseDown
(
e
:
IEditorMouseEvent
):
void
;
emitMouseDrag
(
e
:
IEditorMouseEvent
):
void
;
emitMouseDrop
(
e
:
IEditorMouseEvent
):
void
;
}
/**
...
...
@@ -422,6 +422,11 @@ export interface ICodeEditor extends editorCommon.ICommonCodeEditor {
* @event
*/
onMouseDrag
(
listener
:
(
e
:
IEditorMouseEvent
)
=>
void
):
IDisposable
;
/**
* An event emitted on a "mousedrop".
* @event
*/
onMouseDrop
(
listener
:
(
e
:
IEditorMouseEvent
)
=>
void
):
IDisposable
;
/**
* An event emitted on a "contextmenu".
* @event
...
...
src/vs/editor/browser/view/viewController.ts
浏览文件 @
e823738f
...
...
@@ -143,14 +143,6 @@ export class ViewController implements IViewController {
}
}
public
dragTo
(
source
:
string
,
viewPosition
:
Position
):
void
{
viewPosition
=
this
.
_validateViewColumn
(
viewPosition
);
this
.
triggerCursorHandler
(
source
,
editorCommon
.
Handler
.
DragTo
,
{
position
:
this
.
convertViewToModelPosition
(
viewPosition
),
viewPosition
:
viewPosition
});
}
public
moveTo
(
source
:
string
,
viewPosition
:
Position
):
void
{
viewPosition
=
this
.
_validateViewColumn
(
viewPosition
);
this
.
triggerCursorHandler
(
source
,
editorCommon
.
Handler
.
MoveTo
,
{
...
...
@@ -277,14 +269,22 @@ export class ViewController implements IViewController {
}
public
emitMouseUp
(
e
:
IEditorMouseEvent
):
void
{
console
.
log
(
'
up
'
);
this
.
outgoingEvents
.
emitMouseUp
(
e
);
}
public
emitMouseDown
(
e
:
IEditorMouseEvent
):
void
{
console
.
log
(
'
down
'
);
this
.
outgoingEvents
.
emitMouseDown
(
e
);
}
public
emitMouseDrag
(
e
:
IEditorMouseEvent
):
void
{
console
.
log
(
'
drag
'
);
this
.
outgoingEvents
.
emitMouseDrag
(
e
);
}
public
emitMouseDrop
(
e
:
IEditorMouseEvent
):
void
{
console
.
log
(
'
drop
'
);
this
.
outgoingEvents
.
emitMouseDrop
(
e
);
}
}
src/vs/editor/browser/view/viewOutgoingEvents.ts
浏览文件 @
e823738f
...
...
@@ -78,6 +78,10 @@ export class ViewOutgoingEvents extends Disposable {
this
.
_actual
.
emit
(
EventType
.
MouseDrag
,
this
.
_convertViewToModelMouseEvent
(
e
));
}
public
emitMouseDrop
(
e
:
IEditorMouseEvent
):
void
{
this
.
_actual
.
emit
(
EventType
.
MouseDrop
,
this
.
_convertViewToModelMouseEvent
(
e
));
}
private
_convertViewToModelMouseEvent
(
e
:
IEditorMouseEvent
):
IEditorMouseEvent
{
if
(
e
.
target
)
{
return
{
...
...
src/vs/editor/browser/widget/codeEditorWidget.ts
浏览文件 @
e823738f
...
...
@@ -34,6 +34,7 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
public
readonly
onMouseUp
:
Event
<
editorBrowser
.
IEditorMouseEvent
>
=
fromEventEmitter
(
this
,
editorCommon
.
EventType
.
MouseUp
);
public
readonly
onMouseDown
:
Event
<
editorBrowser
.
IEditorMouseEvent
>
=
fromEventEmitter
(
this
,
editorCommon
.
EventType
.
MouseDown
);
public
readonly
onMouseDrag
:
Event
<
editorBrowser
.
IEditorMouseEvent
>
=
fromEventEmitter
(
this
,
editorCommon
.
EventType
.
MouseDrag
);
public
readonly
onMouseDrop
:
Event
<
editorBrowser
.
IEditorMouseEvent
>
=
fromEventEmitter
(
this
,
editorCommon
.
EventType
.
MouseDrop
);
public
readonly
onContextMenu
:
Event
<
editorBrowser
.
IEditorMouseEvent
>
=
fromEventEmitter
(
this
,
editorCommon
.
EventType
.
ContextMenu
);
public
readonly
onMouseMove
:
Event
<
editorBrowser
.
IEditorMouseEvent
>
=
fromEventEmitter
(
this
,
editorCommon
.
EventType
.
MouseMove
);
public
readonly
onMouseLeave
:
Event
<
editorBrowser
.
IEditorMouseEvent
>
=
fromEventEmitter
(
this
,
editorCommon
.
EventType
.
MouseLeave
);
...
...
src/vs/editor/common/commonCodeEditor.ts
浏览文件 @
e823738f
...
...
@@ -874,6 +874,10 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
this
.
emit
(
editorCommon
.
EventType
.
MouseDrag
,
e
);
break
;
case
editorCommon
.
EventType
.
MouseDrop
:
this
.
emit
(
editorCommon
.
EventType
.
MouseDrop
,
e
);
break
;
case
editorCommon
.
EventType
.
KeyUp
:
this
.
emit
(
editorCommon
.
EventType
.
KeyUp
,
e
);
break
;
...
...
src/vs/editor/common/controller/cursor.ts
浏览文件 @
e823738f
...
...
@@ -9,7 +9,6 @@ import * as strings from 'vs/base/common/strings';
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
EventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
DragAndDropCommand
}
from
'
vs/editor/common/commands/dragAndDropCommand
'
;
import
{
ReplaceCommand
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
CursorCollection
,
ICursorCollectionState
}
from
'
vs/editor/common/controller/cursorCollection
'
;
import
{
IOneCursorOperationContext
,
IViewModelHelper
,
OneCursor
,
OneCursorOp
}
from
'
vs/editor/common/controller/oneCursor
'
;
...
...
@@ -926,7 +925,6 @@ export class Cursor extends EventEmitter {
this
.
_handlers
[
H
.
WordSelect
]
=
(
ctx
)
=>
this
.
_word
(
false
,
ctx
);
this
.
_handlers
[
H
.
WordSelectDrag
]
=
(
ctx
)
=>
this
.
_word
(
true
,
ctx
);
this
.
_handlers
[
H
.
LastCursorWordSelect
]
=
(
ctx
)
=>
this
.
_lastCursorWord
(
ctx
);
this
.
_handlers
[
H
.
DragTo
]
=
(
ctx
)
=>
this
.
_dragTo
(
ctx
);
this
.
_handlers
[
H
.
CancelSelection
]
=
(
ctx
)
=>
this
.
_cancelSelection
(
ctx
);
this
.
_handlers
[
H
.
RemoveSecondaryCursors
]
=
(
ctx
)
=>
this
.
_removeSecondaryCursors
(
ctx
);
...
...
@@ -1308,42 +1306,6 @@ export class Cursor extends EventEmitter {
return
true
;
}
private
_dragTo
(
ctx
:
IMultipleCursorOperationContext
):
boolean
{
if
(
this
.
configuration
.
editor
.
readOnly
||
this
.
model
.
hasEditableRange
())
{
return
false
;
}
let
selections
=
this
.
getSelections
().
filter
(
selection
=>
!
selection
.
isEmpty
());
if
(
selections
.
length
!==
1
)
{
return
false
;
}
let
dragTargetPosition
=
ctx
.
eventData
.
position
;
if
(
selections
[
0
].
containsPosition
(
dragTargetPosition
))
{
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
{
if
(
oneCursor
.
modelState
.
selection
.
containsPosition
(
dragTargetPosition
))
{
return
OneCursorOp
.
moveTo
(
oneCursor
,
false
,
ctx
.
eventData
.
position
,
ctx
.
eventData
.
viewPosition
,
ctx
.
eventSource
,
oneCtx
);
}
return
false
;
});
return
true
;
}
else
{
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
{
if
(
!
oneCursor
.
modelState
.
selection
.
isEmpty
())
{
return
this
.
_doApplyEdit
(
cursorIndex
,
oneCursor
,
oneCtx
,
()
=>
new
EditOperationResult
(
new
DragAndDropCommand
(
oneCursor
.
modelState
.
selection
,
dragTargetPosition
),
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
false
}));
}
return
true
;
});
}
return
true
;
}
private
_removeSecondaryCursors
(
ctx
:
IMultipleCursorOperationContext
):
boolean
{
this
.
cursors
.
killSecondaryCursors
();
return
true
;
...
...
src/vs/editor/common/editorCommon.ts
浏览文件 @
e823738f
...
...
@@ -4137,6 +4137,7 @@ export var EventType = {
MouseMove
:
'
mousemove
'
,
MouseLeave
:
'
mouseleave
'
,
MouseDrag
:
'
mousedrag
'
,
MouseDrop
:
'
mousedrop
'
,
KeyDown
:
'
keydown
'
,
KeyUp
:
'
keyup
'
,
...
...
src/vs/editor/contrib/dragAndDrop/browser/dragAndDrop.ts
浏览文件 @
e823738f
...
...
@@ -11,7 +11,9 @@ import { ICodeEditor, IEditorMouseEvent } from 'vs/editor/browser/editorBrowser'
import
{
editorContribution
}
from
'
vs/editor/browser/editorBrowserExtensions
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
DragContentHintWidget
}
from
'
./dragContentHintWidget
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
DragAndDropCommand
}
from
'
../common/dragAndDropCommand
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
@
editorContribution
export
class
DragAndDropController
implements
editorCommon
.
IEditorContribution
{
...
...
@@ -21,6 +23,8 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
private
_editor
:
ICodeEditor
;
private
_toUnhook
:
IDisposable
[];
private
_contentWidget
:
DragContentHintWidget
;
private
_active
:
boolean
;
private
_dragSelection
:
Selection
;
static
get
(
editor
:
editorCommon
.
ICommonCodeEditor
):
DragAndDropController
{
return
editor
.
getContribution
<
DragAndDropController
>
(
DragAndDropController
.
ID
);
...
...
@@ -32,13 +36,37 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
this
.
_toUnhook
=
[];
this
.
_toUnhook
.
push
(
this
.
_editor
.
onMouseDrag
((
e
:
IEditorMouseEvent
)
=>
this
.
_onEditorMouseDrag
(
e
)));
this
.
_toUnhook
.
push
(
this
.
_editor
.
onMouse
Up
((
e
:
IEditorMouseEvent
)
=>
this
.
_hideWidgets
(
)));
this
.
_toUnhook
.
push
(
this
.
_editor
.
onMouse
Drop
((
e
:
IEditorMouseEvent
)
=>
this
.
_onEditorMouseDrop
(
e
)));
this
.
_contentWidget
=
new
DragContentHintWidget
(
editor
);
this
.
_active
=
false
;
}
private
_onEditorMouseDrag
(
mouseEvent
:
IEditorMouseEvent
):
void
{
let
target
=
mouseEvent
.
target
;
this
.
_contentWidget
.
showAt
(
target
.
position
);
if
(
this
.
_active
)
{
this
.
_contentWidget
.
showAt
(
target
.
position
);
}
else
{
let
possibleSelections
=
this
.
_editor
.
getSelections
().
filter
(
selection
=>
selection
.
containsPosition
(
target
.
position
));
if
(
possibleSelections
.
length
===
1
)
{
this
.
_active
=
true
;
this
.
_dragSelection
=
possibleSelections
[
0
];
this
.
_contentWidget
.
showAt
(
target
.
position
);
}
}
}
private
_onEditorMouseDrop
(
mouseEvent
:
IEditorMouseEvent
):
void
{
let
targetPosition
=
this
.
_contentWidget
.
getPosition
().
position
;
if
(
targetPosition
)
{
let
newCursorPosition
=
new
Position
(
targetPosition
.
lineNumber
,
targetPosition
.
column
);
this
.
_editor
.
executeCommand
(
DragAndDropController
.
ID
,
new
DragAndDropCommand
(
this
.
_dragSelection
,
newCursorPosition
));
}
this
.
_hideWidgets
();
this
.
_active
=
false
;
}
private
_hideWidgets
():
void
{
...
...
src/vs/editor/co
mmon/commands
/dragAndDropCommand.ts
→
src/vs/editor/co
ntrib/dragAndDrop/common
/dragAndDropCommand.ts
浏览文件 @
e823738f
...
...
@@ -9,6 +9,7 @@ import { Position } from 'vs/editor/common/core/position';
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
export
class
DragAndDropCommand
implements
editorCommon
.
ICommand
{
private
selection
:
Selection
;
...
...
src/vs/monaco.d.ts
浏览文件 @
e823738f
...
...
@@ -3762,6 +3762,11 @@ declare module monaco.editor {
* @event
*/
onMouseDrag
(
listener
:
(
e
:
IEditorMouseEvent
)
=>
void
):
IDisposable
;
/**
* An event emitted on a "mousedrop".
* @event
*/
onMouseDrop
(
listener
:
(
e
:
IEditorMouseEvent
)
=>
void
):
IDisposable
;
/**
* An event emitted on a "contextmenu".
* @event
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录