Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0e8cd85d
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,发现更多精彩内容 >>
提交
0e8cd85d
编写于
5月 19, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplifications
上级
972223e5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
60 deletion
+33
-60
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+33
-60
未找到文件。
src/vs/editor/common/controller/cursor.ts
浏览文件 @
0e8cd85d
...
@@ -21,26 +21,6 @@ import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations
...
@@ -21,26 +21,6 @@ import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations
import
{
TextModelEventType
,
ModelRawContentChangedEvent
,
RawContentChangedType
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
TextModelEventType
,
ModelRawContentChangedEvent
,
RawContentChangedType
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
CursorEventType
,
CursorChangeReason
,
ICursorPositionChangedEvent
,
VerticalRevealType
,
ICursorSelectionChangedEvent
,
ICursorRevealRangeEvent
,
CursorScrollRequest
}
from
'
vs/editor/common/controller/cursorEvents
'
;
import
{
CursorEventType
,
CursorChangeReason
,
ICursorPositionChangedEvent
,
VerticalRevealType
,
ICursorSelectionChangedEvent
,
ICursorRevealRangeEvent
,
CursorScrollRequest
}
from
'
vs/editor/common/controller/cursorEvents
'
;
class
CursorOperationArgs
<
T
>
{
public
readonly
eventSource
:
string
;
public
readonly
eventData
:
T
;
constructor
(
eventSource
:
string
,
eventData
:
T
)
{
this
.
eventSource
=
eventSource
;
this
.
eventData
=
eventData
;
}
}
interface
ICommandData
{
operations
:
editorCommon
.
IIdentifiedSingleEditOperation
[];
hadTrackedEditOperation
:
boolean
;
}
interface
ICommandsData
{
operations
:
editorCommon
.
IIdentifiedSingleEditOperation
[];
hadTrackedEditOperation
:
boolean
;
}
export
class
Cursor
extends
Disposable
implements
ICursors
{
export
class
Cursor
extends
Disposable
implements
ICursors
{
public
onDidChangePosition
(
listener
:
(
e
:
ICursorPositionChangedEvent
)
=>
void
):
IDisposable
{
public
onDidChangePosition
(
listener
:
(
e
:
ICursorPositionChangedEvent
)
=>
void
):
IDisposable
{
...
@@ -457,8 +437,6 @@ export class Cursor extends Disposable implements ICursors {
...
@@ -457,8 +437,6 @@ export class Cursor extends Disposable implements ICursors {
return
;
return
;
}
}
const
args
=
new
CursorOperationArgs
(
source
,
payload
);
const
oldSelections
=
this
.
_cursors
.
getSelections
();
const
oldSelections
=
this
.
_cursors
.
getSelections
();
const
oldViewSelections
=
this
.
_cursors
.
getViewSelections
();
const
oldViewSelections
=
this
.
_cursors
.
getViewSelections
();
let
cursorChangeReason
=
CursorChangeReason
.
NotSet
;
let
cursorChangeReason
=
CursorChangeReason
.
NotSet
;
...
@@ -471,20 +449,20 @@ export class Cursor extends Disposable implements ICursors {
...
@@ -471,20 +449,20 @@ export class Cursor extends Disposable implements ICursors {
try
{
try
{
switch
(
handlerId
)
{
switch
(
handlerId
)
{
case
H
.
Type
:
case
H
.
Type
:
this
.
_
executeEditOperation
(
this
.
_type
(
args
)
);
this
.
_
type
(
source
,
<
string
>
payload
.
text
);
break
;
break
;
case
H
.
ReplacePreviousChar
:
case
H
.
ReplacePreviousChar
:
this
.
_
executeEditOperation
(
this
.
_replacePreviousChar
(
args
)
);
this
.
_
replacePreviousChar
(
<
string
>
payload
.
text
,
<
number
>
payload
.
replaceCharCnt
);
break
;
break
;
case
H
.
Paste
:
case
H
.
Paste
:
cursorChangeReason
=
CursorChangeReason
.
Paste
;
cursorChangeReason
=
CursorChangeReason
.
Paste
;
this
.
_
executeEditOperation
(
this
.
_paste
(
args
)
);
this
.
_
paste
(
<
string
>
payload
.
text
,
<
boolean
>
payload
.
pasteOnNewLine
);
break
;
break
;
case
H
.
Cut
:
case
H
.
Cut
:
this
.
_
executeEditOperation
(
this
.
_cut
(
args
)
);
this
.
_
cut
(
);
break
;
break
;
case
H
.
Undo
:
case
H
.
Undo
:
...
@@ -498,11 +476,11 @@ export class Cursor extends Disposable implements ICursors {
...
@@ -498,11 +476,11 @@ export class Cursor extends Disposable implements ICursors {
break
;
break
;
case
H
.
ExecuteCommand
:
case
H
.
ExecuteCommand
:
this
.
_ex
ecuteEditOperation
(
this
.
_externalExecuteCommand
(
args
)
);
this
.
_ex
ternalExecuteCommand
(
<
editorCommon
.
ICommand
>
payload
);
break
;
break
;
case
H
.
ExecuteCommands
:
case
H
.
ExecuteCommands
:
this
.
_ex
ecuteEditOperation
(
this
.
_externalExecuteCommands
(
args
)
);
this
.
_ex
ternalExecuteCommands
(
<
editorCommon
.
ICommand
[]
>
payload
);
break
;
break
;
}
}
}
catch
(
err
)
{
}
catch
(
err
)
{
...
@@ -514,18 +492,14 @@ export class Cursor extends Disposable implements ICursors {
...
@@ -514,18 +492,14 @@ export class Cursor extends Disposable implements ICursors {
const
newSelections
=
this
.
_cursors
.
getSelections
();
const
newSelections
=
this
.
_cursors
.
getSelections
();
const
newViewSelections
=
this
.
_cursors
.
getViewSelections
();
const
newViewSelections
=
this
.
_cursors
.
getViewSelections
();
if
(
Cursor
.
_somethingChanged
(
oldSelections
,
oldViewSelections
,
newSelections
,
newViewSelections
))
{
if
(
Cursor
.
_somethingChanged
(
oldSelections
,
oldViewSelections
,
newSelections
,
newViewSelections
))
{
this
.
_emitCursorPositionChanged
(
args
.
eventS
ource
,
cursorChangeReason
);
this
.
_emitCursorPositionChanged
(
s
ource
,
cursorChangeReason
);
this
.
_revealRange
(
RevealTarget
.
Primary
,
VerticalRevealType
.
Simple
,
true
);
this
.
_revealRange
(
RevealTarget
.
Primary
,
VerticalRevealType
.
Simple
,
true
);
this
.
_emitCursorSelectionChanged
(
args
.
eventS
ource
,
cursorChangeReason
);
this
.
_emitCursorSelectionChanged
(
s
ource
,
cursorChangeReason
);
}
}
}
}
// -------------------- START editing operations
private
_type
(
source
:
string
,
text
:
string
):
void
{
if
(
!
this
.
_isDoingComposition
&&
source
===
'
keyboard
'
)
{
private
_type
(
args
:
CursorOperationArgs
<
{
text
:
string
;
}
>
):
EditOperationResult
{
const
text
=
args
.
eventData
.
text
;
if
(
!
this
.
_isDoingComposition
&&
args
.
eventSource
===
'
keyboard
'
)
{
// If this event is coming straight from the keyboard, look for electric characters and enter
// If this event is coming straight from the keyboard, look for electric characters and enter
for
(
let
i
=
0
,
len
=
text
.
length
;
i
<
len
;
i
++
)
{
for
(
let
i
=
0
,
len
=
text
.
length
;
i
<
len
;
i
++
)
{
...
@@ -542,48 +516,37 @@ export class Cursor extends Disposable implements ICursors {
...
@@ -542,48 +516,37 @@ export class Cursor extends Disposable implements ICursors {
this
.
_executeEditOperation
(
TypeOperations
.
typeWithInterceptors
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
chr
));
this
.
_executeEditOperation
(
TypeOperations
.
typeWithInterceptors
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
chr
));
}
}
return
null
;
}
else
{
}
else
{
return
TypeOperations
.
typeWithoutInterceptors
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
text
);
this
.
_executeEditOperation
(
TypeOperations
.
typeWithoutInterceptors
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
text
)
);
}
}
}
}
private
_replacePreviousChar
(
args
:
CursorOperationArgs
<
{
text
:
string
;
replaceCharCnt
:
number
;
}
>
):
EditOperationResult
{
private
_replacePreviousChar
(
text
:
string
,
replaceCharCnt
:
number
):
void
{
const
text
=
args
.
eventData
.
text
;
this
.
_executeEditOperation
(
TypeOperations
.
replacePreviousChar
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
text
,
replaceCharCnt
));
const
replaceCharCnt
=
args
.
eventData
.
replaceCharCnt
;
return
TypeOperations
.
replacePreviousChar
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
text
,
replaceCharCnt
);
}
}
private
_paste
(
args
:
CursorOperationArgs
<
{
pasteOnNewLine
:
boolean
;
text
:
string
;
}
>
):
EditOperationResult
{
private
_paste
(
text
:
string
,
pasteOnNewLine
:
boolean
):
void
{
const
pasteOnNewLine
=
args
.
eventData
.
pasteOnNewLine
;
this
.
_executeEditOperation
(
TypeOperations
.
paste
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
pasteOnNewLine
,
text
));
const
text
=
args
.
eventData
.
text
;
return
TypeOperations
.
paste
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(),
pasteOnNewLine
,
text
);
}
}
private
_cut
(
args
:
CursorOperationArgs
<
void
>
):
EditOperationResult
{
private
_cut
(
):
void
{
return
DeleteOperations
.
cut
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
(
));
this
.
_executeEditOperation
(
DeleteOperations
.
cut
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
getSelections
()
));
}
}
// -------------------- END editing operations
private
_externalExecuteCommand
(
command
:
editorCommon
.
ICommand
):
void
{
private
_externalExecuteCommand
(
args
:
CursorOperationArgs
<
editorCommon
.
ICommand
>
):
EditOperationResult
{
const
command
=
args
.
eventData
;
this
.
_cursors
.
killSecondaryCursors
();
this
.
_cursors
.
killSecondaryCursors
();
return
new
EditOperationResult
([
command
],
{
this
.
_executeEditOperation
(
new
EditOperationResult
([
command
],
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
false
shouldPushStackElementAfter
:
false
});
})
)
;
}
}
private
_externalExecuteCommands
(
args
:
CursorOperationArgs
<
editorCommon
.
ICommand
[]
>
):
EditOperationResult
{
private
_externalExecuteCommands
(
commands
:
editorCommon
.
ICommand
[]):
void
{
const
commands
=
args
.
eventData
;
this
.
_executeEditOperation
(
new
EditOperationResult
(
commands
,
{
return
new
EditOperationResult
(
commands
,
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
false
shouldPushStackElementAfter
:
false
});
})
)
;
}
}
}
}
...
@@ -594,6 +557,16 @@ interface IExecContext {
...
@@ -594,6 +557,16 @@ interface IExecContext {
readonly
positionMarkers
:
string
[];
readonly
positionMarkers
:
string
[];
}
}
interface
ICommandData
{
operations
:
editorCommon
.
IIdentifiedSingleEditOperation
[];
hadTrackedEditOperation
:
boolean
;
}
interface
ICommandsData
{
operations
:
editorCommon
.
IIdentifiedSingleEditOperation
[];
hadTrackedEditOperation
:
boolean
;
}
class
CommandExecutor
{
class
CommandExecutor
{
public
static
executeCommands
(
model
:
editorCommon
.
IModel
,
selectionsBefore
:
Selection
[],
commands
:
editorCommon
.
ICommand
[]):
Selection
[]
{
public
static
executeCommands
(
model
:
editorCommon
.
IModel
,
selectionsBefore
:
Selection
[],
commands
:
editorCommon
.
ICommand
[]):
Selection
[]
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录