Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4a75f9b5
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,发现更多精彩内容 >>
提交
4a75f9b5
编写于
11月 07, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move more operations out of oneCursor
上级
4183dd9d
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
443 addition
and
384 deletion
+443
-384
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+2
-2
src/vs/editor/common/controller/cursorColumnSelection.ts
src/vs/editor/common/controller/cursorColumnSelection.ts
+5
-6
src/vs/editor/common/controller/cursorCommon.ts
src/vs/editor/common/controller/cursorCommon.ts
+120
-0
src/vs/editor/common/controller/cursorDeleteOperations.ts
src/vs/editor/common/controller/cursorDeleteOperations.ts
+7
-8
src/vs/editor/common/controller/cursorMoveOperations.ts
src/vs/editor/common/controller/cursorMoveOperations.ts
+78
-34
src/vs/editor/common/controller/cursorTypeOperations.ts
src/vs/editor/common/controller/cursorTypeOperations.ts
+16
-17
src/vs/editor/common/controller/cursorWordOperations.ts
src/vs/editor/common/controller/cursorWordOperations.ts
+83
-11
src/vs/editor/common/controller/oneCursor.ts
src/vs/editor/common/controller/oneCursor.ts
+132
-306
未找到文件。
src/vs/editor/common/controller/cursor.ts
浏览文件 @
4a75f9b5
...
...
@@ -1341,7 +1341,7 @@ export class Cursor extends EventEmitter {
private
_word
(
inSelectionMode
:
boolean
,
ctx
:
IMultipleCursorOperationContext
):
boolean
{
this
.
cursors
.
killSecondaryCursors
();
return
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
word
(
oneCursor
,
inSelectionMode
,
ctx
.
eventData
.
position
,
oneCtx
));
return
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
word
(
oneCursor
,
inSelectionMode
,
oneCursor
.
validatePosition
(
ctx
.
eventData
.
position
)
,
oneCtx
));
}
private
_lastCursorWord
(
ctx
:
IMultipleCursorOperationContext
):
boolean
{
...
...
@@ -1352,7 +1352,7 @@ export class Cursor extends EventEmitter {
var
lastAddedCursor
=
this
.
cursors
.
getLastAddedCursor
();
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
{
if
(
oneCursor
===
lastAddedCursor
)
{
return
OneCursorOp
.
word
(
oneCursor
,
true
,
ctx
.
eventData
.
position
,
oneCtx
);
return
OneCursorOp
.
word
(
oneCursor
,
true
,
oneCursor
.
validatePosition
(
ctx
.
eventData
.
position
)
,
oneCtx
);
}
return
false
;
});
...
...
src/vs/editor/common/controller/cursorColumnSelection.ts
浏览文件 @
4a75f9b5
...
...
@@ -6,8 +6,7 @@
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
SingleCursorState
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
export
interface
IColumnSelectResult
{
viewSelections
:
Selection
[];
...
...
@@ -72,7 +71,7 @@ export class ColumnSelection {
return
ColumnSelection
.
_columnSelect
(
config
,
model
,
fromViewPosition
.
lineNumber
,
fromViewVisibleColumn
,
toViewLineNumber
,
toViewVisualColumn
);
}
public
static
columnSelectLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
,
toViewLineNumber
:
number
,
toViewVisualColumn
:
number
):
IColumnSelectResult
{
public
static
columnSelectLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
,
toViewLineNumber
:
number
,
toViewVisualColumn
:
number
):
IColumnSelectResult
{
if
(
toViewVisualColumn
>
1
)
{
toViewVisualColumn
--
;
}
...
...
@@ -80,7 +79,7 @@ export class ColumnSelection {
return
this
.
columnSelect
(
config
,
model
,
cursor
.
selection
.
getStartPosition
(),
toViewLineNumber
,
toViewVisualColumn
);
}
public
static
columnSelectRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
,
toViewLineNumber
:
number
,
toViewVisualColumn
:
number
):
IColumnSelectResult
{
public
static
columnSelectRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
,
toViewLineNumber
:
number
,
toViewVisualColumn
:
number
):
IColumnSelectResult
{
let
maxVisualViewColumn
=
0
;
let
minViewLineNumber
=
Math
.
min
(
cursor
.
position
.
lineNumber
,
toViewLineNumber
);
let
maxViewLineNumber
=
Math
.
max
(
cursor
.
position
.
lineNumber
,
toViewLineNumber
);
...
...
@@ -97,7 +96,7 @@ export class ColumnSelection {
return
this
.
columnSelect
(
config
,
model
,
cursor
.
selection
.
getStartPosition
(),
toViewLineNumber
,
toViewVisualColumn
);
}
public
static
columnSelectUp
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
,
isPaged
:
boolean
,
toViewLineNumber
:
number
,
toViewVisualColumn
:
number
):
IColumnSelectResult
{
public
static
columnSelectUp
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
,
isPaged
:
boolean
,
toViewLineNumber
:
number
,
toViewVisualColumn
:
number
):
IColumnSelectResult
{
let
linesCount
=
isPaged
?
config
.
pageSize
:
1
;
toViewLineNumber
-=
linesCount
;
...
...
@@ -108,7 +107,7 @@ export class ColumnSelection {
return
this
.
columnSelect
(
config
,
model
,
cursor
.
selection
.
getStartPosition
(),
toViewLineNumber
,
toViewVisualColumn
);
}
public
static
columnSelectDown
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
,
isPaged
:
boolean
,
toViewLineNumber
:
number
,
toViewVisualColumn
:
number
):
IColumnSelectResult
{
public
static
columnSelectDown
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
,
isPaged
:
boolean
,
toViewLineNumber
:
number
,
toViewVisualColumn
:
number
):
IColumnSelectResult
{
let
linesCount
=
isPaged
?
config
.
pageSize
:
1
;
toViewLineNumber
+=
linesCount
;
...
...
src/vs/editor/common/controller/cursorCommon.ts
浏览文件 @
4a75f9b5
...
...
@@ -10,6 +10,8 @@ import * as strings from 'vs/base/common/strings';
import
{
IModeConfiguration
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
ICommand
,
CursorChangeReason
,
IConfigurationChangedEvent
,
TextModelResolvedOptions
,
IConfiguration
}
from
'
vs/editor/common/editorCommon
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
export
interface
CharacterMap
{
[
char
:
string
]:
string
;
...
...
@@ -65,6 +67,9 @@ export class CursorConfiguration {
}
}
/**
* Represents a simple model (either the model or the view model).
*/
export
interface
ICursorSimpleModel
{
getLineCount
():
number
;
getLineContent
(
lineNumber
:
number
):
string
;
...
...
@@ -74,6 +79,121 @@ export interface ICursorSimpleModel {
getLineLastNonWhitespaceColumn
(
lineNumber
:
number
):
number
;
}
/**
* Represents the cursor state on either the model or on the view model.
*/
export
class
SingleCursorState
{
_singleCursorStateBrand
:
void
;
// --- selection can start as a range (think double click and drag)
public
readonly
selectionStart
:
Range
;
public
readonly
selectionStartLeftoverVisibleColumns
:
number
;
public
readonly
position
:
Position
;
public
readonly
leftoverVisibleColumns
:
number
;
public
readonly
selection
:
Selection
;
constructor
(
selectionStart
:
Range
,
selectionStartLeftoverVisibleColumns
:
number
,
position
:
Position
,
leftoverVisibleColumns
:
number
,
)
{
this
.
selectionStart
=
selectionStart
;
this
.
selectionStartLeftoverVisibleColumns
=
selectionStartLeftoverVisibleColumns
;
this
.
position
=
position
;
this
.
leftoverVisibleColumns
=
leftoverVisibleColumns
;
this
.
selection
=
SingleCursorState
.
_computeSelection
(
this
.
selectionStart
,
this
.
position
);
}
public
equals
(
other
:
SingleCursorState
)
{
return
(
this
.
selectionStartLeftoverVisibleColumns
===
other
.
selectionStartLeftoverVisibleColumns
&&
this
.
leftoverVisibleColumns
===
other
.
leftoverVisibleColumns
&&
this
.
position
.
equals
(
other
.
position
)
&&
this
.
selectionStart
.
equalsRange
(
other
.
selectionStart
)
);
}
public
hasSelection
():
boolean
{
return
(
!
this
.
selection
.
isEmpty
()
||
!
this
.
selectionStart
.
isEmpty
());
}
public
withSelectionStartLeftoverVisibleColumns
(
selectionStartLeftoverVisibleColumns
:
number
):
SingleCursorState
{
return
new
SingleCursorState
(
this
.
selectionStart
,
selectionStartLeftoverVisibleColumns
,
this
.
position
,
this
.
leftoverVisibleColumns
);
}
public
withSelectionStart
(
selectionStart
:
Range
):
SingleCursorState
{
return
new
SingleCursorState
(
selectionStart
,
0
,
this
.
position
,
this
.
leftoverVisibleColumns
);
}
public
collapse
():
SingleCursorState
{
return
new
SingleCursorState
(
new
Range
(
this
.
position
.
lineNumber
,
this
.
position
.
column
,
this
.
position
.
lineNumber
,
this
.
position
.
column
),
0
,
this
.
position
,
0
);
}
public
move
(
inSelectionMode
:
boolean
,
position
:
Position
,
leftoverVisibleColumns
:
number
):
SingleCursorState
{
if
(
inSelectionMode
)
{
// move just position
return
new
SingleCursorState
(
this
.
selectionStart
,
this
.
selectionStartLeftoverVisibleColumns
,
position
,
leftoverVisibleColumns
);
}
else
{
// move everything
return
new
SingleCursorState
(
new
Range
(
position
.
lineNumber
,
position
.
column
,
position
.
lineNumber
,
position
.
column
),
leftoverVisibleColumns
,
position
,
leftoverVisibleColumns
);
}
}
private
static
_computeSelection
(
selectionStart
:
Range
,
position
:
Position
):
Selection
{
let
startLineNumber
:
number
,
startColumn
:
number
,
endLineNumber
:
number
,
endColumn
:
number
;
if
(
selectionStart
.
isEmpty
())
{
startLineNumber
=
selectionStart
.
startLineNumber
;
startColumn
=
selectionStart
.
startColumn
;
endLineNumber
=
position
.
lineNumber
;
endColumn
=
position
.
column
;
}
else
{
if
(
position
.
isBeforeOrEqual
(
selectionStart
.
getStartPosition
()))
{
startLineNumber
=
selectionStart
.
endLineNumber
;
startColumn
=
selectionStart
.
endColumn
;
endLineNumber
=
position
.
lineNumber
;
endColumn
=
position
.
column
;
}
else
{
startLineNumber
=
selectionStart
.
startLineNumber
;
startColumn
=
selectionStart
.
startColumn
;
endLineNumber
=
position
.
lineNumber
;
endColumn
=
position
.
column
;
}
}
return
new
Selection
(
startLineNumber
,
startColumn
,
endLineNumber
,
endColumn
);
}
}
export
class
EditOperationResult
{
_editOperationBrand
:
void
;
...
...
src/vs/editor/common/controller/cursorDeleteOperations.ts
浏览文件 @
4a75f9b5
...
...
@@ -5,15 +5,14 @@
'
use strict
'
;
import
{
ReplaceCommand
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
EditOperationResult
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
SingleCursorState
,
EditOperationResult
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
MoveOperations
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
export
class
DeleteOperations
{
public
static
deleteRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
deleteRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
let
deleteSelection
:
Range
=
cursor
.
selection
;
...
...
@@ -44,7 +43,7 @@ export class DeleteOperations {
});
}
public
static
deleteAllRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
deleteAllRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
let
selection
=
cursor
.
selection
;
if
(
selection
.
isEmpty
())
{
...
...
@@ -70,7 +69,7 @@ export class DeleteOperations {
return
this
.
deleteRight
(
config
,
model
,
cursor
);
}
public
static
autoClosingPairDelete
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
autoClosingPairDelete
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
...
...
@@ -108,7 +107,7 @@ export class DeleteOperations {
});
}
public
static
deleteLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
deleteLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
let
r
=
this
.
autoClosingPairDelete
(
config
,
model
,
cursor
);
if
(
r
)
{
// This was a case for an auto-closing pair delete
...
...
@@ -165,7 +164,7 @@ export class DeleteOperations {
});
}
public
static
deleteAllLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
deleteAllLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
let
r
=
this
.
autoClosingPairDelete
(
config
,
model
,
cursor
);
if
(
r
)
{
// This was a case for an auto-closing pair delete
...
...
@@ -196,7 +195,7 @@ export class DeleteOperations {
return
this
.
deleteLeft
(
config
,
model
,
cursor
);
}
public
static
cut
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
,
enableEmptySelectionClipboard
:
boolean
):
EditOperationResult
{
public
static
cut
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
,
enableEmptySelectionClipboard
:
boolean
):
EditOperationResult
{
let
selection
=
cursor
.
selection
;
if
(
selection
.
isEmpty
())
{
...
...
src/vs/editor/common/controller/cursorMoveOperations.ts
浏览文件 @
4a75f9b5
...
...
@@ -4,12 +4,13 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
SingleCursorState
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
CursorChangeReason
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
export
class
Cursor
MoveResult
{
_cursor
MoveResult
Brand
:
void
;
export
class
Cursor
Position
{
_cursor
Position
Brand
:
void
;
public
readonly
lineNumber
:
number
;
public
readonly
column
:
number
;
...
...
@@ -22,28 +23,27 @@ export class CursorMoveResult {
}
}
export
class
MoveOperationResult
{
_
m
oveOperationBrand
:
void
;
export
class
Single
MoveOperationResult
{
_
singleM
oveOperationBrand
:
void
;
readonly
inSelectionMode
:
boolean
;
readonly
lineNumber
:
number
;
readonly
column
:
number
;
readonly
leftoverVisibleColumns
:
number
;
public
static
fromMove
(
initialState
:
SingleCursorState
,
inSelectionMode
:
boolean
,
lineNumber
:
number
,
column
:
number
,
leftoverVisibleColumns
:
number
,
ensureInEditableRange
:
boolean
,
reason
:
CursorChangeReason
):
SingleMoveOperationResult
{
return
new
SingleMoveOperationResult
(
initialState
.
move
(
inSelectionMode
,
new
Position
(
lineNumber
,
column
),
leftoverVisibleColumns
),
ensureInEditableRange
,
reason
);
}
readonly
state
:
SingleCursorState
;
readonly
ensureInEditableRange
:
boolean
;
readonly
reason
:
CursorChangeReason
;
constructor
(
inSelectionMode
:
boolean
,
lineNumber
:
number
,
column
:
number
,
leftoverVisibleColumns
:
number
,
state
:
SingleCursorState
,
ensureInEditableRange
:
boolean
,
reason
:
CursorChangeReason
)
{
this
.
inSelectionMode
=
inSelectionMode
;
this
.
lineNumber
=
lineNumber
;
this
.
column
=
column
;
this
.
leftoverVisibleColumns
=
leftoverVisibleColumns
;
this
.
state
=
state
;
this
.
ensureInEditableRange
=
ensureInEditableRange
;
this
.
reason
=
reason
;
}
...
...
@@ -51,7 +51,7 @@ export class MoveOperationResult {
export
class
MoveOperations
{
public
static
left
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
lineNumber
:
number
,
column
:
number
):
Cursor
MoveResult
{
public
static
left
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
lineNumber
:
number
,
column
:
number
):
Cursor
Position
{
if
(
column
>
model
.
getLineMinColumn
(
lineNumber
))
{
if
(
CursorColumns
.
isLowSurrogate
(
model
,
lineNumber
,
column
-
2
))
{
...
...
@@ -65,10 +65,10 @@ export class MoveOperations {
column
=
model
.
getLineMaxColumn
(
lineNumber
);
}
return
new
Cursor
MoveResult
(
lineNumber
,
column
,
0
);
return
new
Cursor
Position
(
lineNumber
,
column
,
0
);
}
public
static
moveLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModelState
,
inSelectionMode
:
boolean
,
noOfColumns
:
number
):
MoveOperationResult
{
public
static
moveLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
,
inSelectionMode
:
boolean
,
noOfColumns
:
number
):
Single
MoveOperationResult
{
let
lineNumber
:
number
,
column
:
number
;
...
...
@@ -82,10 +82,10 @@ export class MoveOperations {
column
=
r
.
column
;
}
return
new
MoveOperationResult
(
inSelectionMode
,
lineNumber
,
column
,
0
,
true
,
CursorChangeReason
.
Explicit
);
return
SingleMoveOperationResult
.
fromMove
(
cursor
,
inSelectionMode
,
lineNumber
,
column
,
0
,
true
,
CursorChangeReason
.
Explicit
);
}
public
static
right
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
lineNumber
:
number
,
column
:
number
):
Cursor
MoveResult
{
public
static
right
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
lineNumber
:
number
,
column
:
number
):
Cursor
Position
{
if
(
column
<
model
.
getLineMaxColumn
(
lineNumber
))
{
if
(
CursorColumns
.
isHighSurrogate
(
model
,
lineNumber
,
column
-
1
))
{
...
...
@@ -99,10 +99,10 @@ export class MoveOperations {
column
=
model
.
getLineMinColumn
(
lineNumber
);
}
return
new
Cursor
MoveResult
(
lineNumber
,
column
,
0
);
return
new
Cursor
Position
(
lineNumber
,
column
,
0
);
}
public
static
moveRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModelState
,
inSelectionMode
:
boolean
,
noOfColumns
:
number
):
MoveOperationResult
{
public
static
moveRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
,
inSelectionMode
:
boolean
,
noOfColumns
:
number
):
Single
MoveOperationResult
{
let
lineNumber
:
number
,
column
:
number
;
...
...
@@ -116,10 +116,10 @@ export class MoveOperations {
column
=
r
.
column
;
}
return
new
MoveOperationResult
(
inSelectionMode
,
lineNumber
,
column
,
0
,
true
,
CursorChangeReason
.
Explicit
);
return
SingleMoveOperationResult
.
fromMove
(
cursor
,
inSelectionMode
,
lineNumber
,
column
,
0
,
true
,
CursorChangeReason
.
Explicit
);
}
public
static
down
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
lineNumber
:
number
,
column
:
number
,
leftoverVisibleColumns
:
number
,
count
:
number
,
allowMoveOnLastLine
:
boolean
):
Cursor
MoveResult
{
public
static
down
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
lineNumber
:
number
,
column
:
number
,
leftoverVisibleColumns
:
number
,
count
:
number
,
allowMoveOnLastLine
:
boolean
):
Cursor
Position
{
const
currentVisibleColumn
=
CursorColumns
.
visibleColumnFromColumn
(
model
.
getLineContent
(
lineNumber
),
column
,
config
.
tabSize
)
+
leftoverVisibleColumns
;
lineNumber
=
lineNumber
+
count
;
...
...
@@ -143,10 +143,10 @@ export class MoveOperations {
leftoverVisibleColumns
=
currentVisibleColumn
-
CursorColumns
.
visibleColumnFromColumn
(
model
.
getLineContent
(
lineNumber
),
column
,
config
.
tabSize
);
return
new
Cursor
MoveResult
(
lineNumber
,
column
,
leftoverVisibleColumns
);
return
new
Cursor
Position
(
lineNumber
,
column
,
leftoverVisibleColumns
);
}
public
static
moveDown
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModelState
,
inSelectionMode
:
boolean
,
linesCount
:
number
):
MoveOperationResult
{
public
static
moveDown
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
,
inSelectionMode
:
boolean
,
linesCount
:
number
):
Single
MoveOperationResult
{
let
lineNumber
:
number
,
column
:
number
;
...
...
@@ -161,10 +161,26 @@ export class MoveOperations {
let
r
=
MoveOperations
.
down
(
config
,
model
,
lineNumber
,
column
,
cursor
.
leftoverVisibleColumns
,
linesCount
,
true
);
return
new
MoveOperationResult
(
inSelectionMode
,
r
.
lineNumber
,
r
.
column
,
r
.
leftoverVisibleColumns
,
true
,
CursorChangeReason
.
Explicit
);
return
SingleMoveOperationResult
.
fromMove
(
cursor
,
inSelectionMode
,
r
.
lineNumber
,
r
.
column
,
r
.
leftoverVisibleColumns
,
true
,
CursorChangeReason
.
Explicit
);
}
public
static
up
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
lineNumber
:
number
,
column
:
number
,
leftoverVisibleColumns
:
number
,
count
:
number
,
allowMoveOnFirstLine
:
boolean
):
CursorMoveResult
{
public
static
translateDown
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
):
SingleMoveOperationResult
{
let
selection
=
cursor
.
selection
;
let
selectionStart
=
MoveOperations
.
down
(
config
,
model
,
selection
.
selectionStartLineNumber
,
selection
.
selectionStartColumn
,
cursor
.
selectionStartLeftoverVisibleColumns
,
1
,
false
);
let
position
=
MoveOperations
.
down
(
config
,
model
,
selection
.
positionLineNumber
,
selection
.
positionColumn
,
cursor
.
leftoverVisibleColumns
,
1
,
false
);
let
tmp
=
new
SingleCursorState
(
new
Range
(
selectionStart
.
lineNumber
,
selectionStart
.
column
,
selectionStart
.
lineNumber
,
selectionStart
.
column
),
selectionStart
.
leftoverVisibleColumns
,
new
Position
(
position
.
lineNumber
,
position
.
column
),
position
.
leftoverVisibleColumns
);
return
new
SingleMoveOperationResult
(
tmp
,
true
,
CursorChangeReason
.
Explicit
);
}
public
static
up
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
lineNumber
:
number
,
column
:
number
,
leftoverVisibleColumns
:
number
,
count
:
number
,
allowMoveOnFirstLine
:
boolean
):
CursorPosition
{
const
currentVisibleColumn
=
CursorColumns
.
visibleColumnFromColumn
(
model
.
getLineContent
(
lineNumber
),
column
,
config
.
tabSize
)
+
leftoverVisibleColumns
;
lineNumber
=
lineNumber
-
count
;
...
...
@@ -187,10 +203,10 @@ export class MoveOperations {
leftoverVisibleColumns
=
currentVisibleColumn
-
CursorColumns
.
visibleColumnFromColumn
(
model
.
getLineContent
(
lineNumber
),
column
,
config
.
tabSize
);
return
new
Cursor
MoveResult
(
lineNumber
,
column
,
leftoverVisibleColumns
);
return
new
Cursor
Position
(
lineNumber
,
column
,
leftoverVisibleColumns
);
}
public
static
moveUp
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModelState
,
inSelectionMode
:
boolean
,
linesCount
:
number
):
MoveOperationResult
{
public
static
moveUp
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
,
inSelectionMode
:
boolean
,
linesCount
:
number
):
Single
MoveOperationResult
{
let
lineNumber
:
number
,
column
:
number
;
...
...
@@ -205,6 +221,34 @@ export class MoveOperations {
let
r
=
MoveOperations
.
up
(
config
,
model
,
lineNumber
,
column
,
cursor
.
leftoverVisibleColumns
,
linesCount
,
true
);
return
new
MoveOperationResult
(
inSelectionMode
,
r
.
lineNumber
,
r
.
column
,
r
.
leftoverVisibleColumns
,
true
,
CursorChangeReason
.
Explicit
);
return
SingleMoveOperationResult
.
fromMove
(
cursor
,
inSelectionMode
,
r
.
lineNumber
,
r
.
column
,
r
.
leftoverVisibleColumns
,
true
,
CursorChangeReason
.
Explicit
);
}
public
static
translateUp
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
):
SingleMoveOperationResult
{
let
selection
=
cursor
.
selection
;
let
selectionStart
=
MoveOperations
.
up
(
config
,
model
,
selection
.
selectionStartLineNumber
,
selection
.
selectionStartColumn
,
cursor
.
selectionStartLeftoverVisibleColumns
,
1
,
false
);
let
position
=
MoveOperations
.
up
(
config
,
model
,
selection
.
positionLineNumber
,
selection
.
positionColumn
,
cursor
.
leftoverVisibleColumns
,
1
,
false
);
let
tmp
=
new
SingleCursorState
(
new
Range
(
selectionStart
.
lineNumber
,
selectionStart
.
column
,
selectionStart
.
lineNumber
,
selectionStart
.
column
),
selectionStart
.
leftoverVisibleColumns
,
new
Position
(
position
.
lineNumber
,
position
.
column
),
position
.
leftoverVisibleColumns
);
return
new
SingleMoveOperationResult
(
tmp
,
true
,
CursorChangeReason
.
Explicit
);
}
public
static
moveToBeginningOfBuffer
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
,
inSelectionMode
:
boolean
):
SingleMoveOperationResult
{
return
SingleMoveOperationResult
.
fromMove
(
cursor
,
inSelectionMode
,
1
,
1
,
0
,
true
,
CursorChangeReason
.
Explicit
);
}
public
static
moveToEndOfBuffer
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
,
inSelectionMode
:
boolean
):
SingleMoveOperationResult
{
let
lastLineNumber
=
model
.
getLineCount
();
let
lastColumn
=
model
.
getLineMaxColumn
(
lastLineNumber
);
return
SingleMoveOperationResult
.
fromMove
(
cursor
,
inSelectionMode
,
lastLineNumber
,
lastColumn
,
0
,
true
,
CursorChangeReason
.
Explicit
);
}
}
src/vs/editor/common/controller/cursorTypeOperations.ts
浏览文件 @
4a75f9b5
...
...
@@ -6,10 +6,9 @@
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
ReplaceCommand
,
ReplaceCommandWithoutChangingPosition
,
ReplaceCommandWithOffsetCursorState
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
EditOperationResult
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
SingleCursorState
,
EditOperationResult
,
CursorColumns
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
CursorChangeReason
,
ICommand
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
ShiftCommand
}
from
'
vs/editor/common/commands/shiftCommand
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
...
...
@@ -22,7 +21,7 @@ import { IElectricAction } from 'vs/editor/common/modes/supports/electricCharact
export
class
TypeOperations
{
public
static
indent
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
indent
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
return
new
EditOperationResult
(
new
ShiftCommand
(
cursor
.
selection
,
{
isUnshift
:
false
,
...
...
@@ -36,7 +35,7 @@ export class TypeOperations {
);
}
public
static
outdent
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
outdent
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
return
new
EditOperationResult
(
new
ShiftCommand
(
cursor
.
selection
,
{
isUnshift
:
true
,
...
...
@@ -50,7 +49,7 @@ export class TypeOperations {
);
}
public
static
paste
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
,
text
:
string
,
pasteOnNewLine
:
boolean
):
EditOperationResult
{
public
static
paste
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
,
text
:
string
,
pasteOnNewLine
:
boolean
):
EditOperationResult
{
let
position
=
cursor
.
position
;
let
selection
=
cursor
.
selection
;
...
...
@@ -138,7 +137,7 @@ export class TypeOperations {
return
new
ReplaceCommand
(
selection
,
typeText
);
}
public
static
tab
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
tab
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
let
selection
=
cursor
.
selection
;
if
(
selection
.
isEmpty
())
{
...
...
@@ -178,7 +177,7 @@ export class TypeOperations {
}
}
public
static
replacePreviousChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
,
txt
:
string
,
replaceCharCnt
:
number
):
EditOperationResult
{
public
static
replacePreviousChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
,
txt
:
string
,
replaceCharCnt
:
number
):
EditOperationResult
{
let
pos
=
cursor
.
position
;
let
startColumn
=
Math
.
max
(
1
,
pos
.
column
-
replaceCharCnt
);
let
range
=
new
Range
(
pos
.
lineNumber
,
startColumn
,
pos
.
lineNumber
,
pos
.
column
);
...
...
@@ -239,7 +238,7 @@ export class TypeOperations {
});
}
private
static
_typeInterceptorEnter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
,
ch
:
string
):
EditOperationResult
{
private
static
_typeInterceptorEnter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
,
ch
:
string
):
EditOperationResult
{
if
(
ch
!==
'
\n
'
)
{
return
null
;
}
...
...
@@ -247,7 +246,7 @@ export class TypeOperations {
return
TypeOperations
.
_enter
(
config
,
model
,
false
,
cursor
.
selection
);
}
private
static
_typeInterceptorAutoClosingCloseChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
,
ch
:
string
):
EditOperationResult
{
private
static
_typeInterceptorAutoClosingCloseChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
...
...
@@ -274,7 +273,7 @@ export class TypeOperations {
});
}
private
static
_typeInterceptorAutoClosingOpenChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
,
ch
:
string
):
EditOperationResult
{
private
static
_typeInterceptorAutoClosingOpenChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
...
...
@@ -323,7 +322,7 @@ export class TypeOperations {
});
}
private
static
_typeInterceptorSurroundSelection
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
,
ch
:
string
):
EditOperationResult
{
private
static
_typeInterceptorSurroundSelection
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
autoClosingBrackets
)
{
return
null
;
}
...
...
@@ -366,7 +365,7 @@ export class TypeOperations {
});
}
private
static
_typeInterceptorElectricChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
,
ch
:
string
):
EditOperationResult
{
private
static
_typeInterceptorElectricChar
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
,
ch
:
string
):
EditOperationResult
{
if
(
!
config
.
electricChars
.
hasOwnProperty
(
ch
))
{
return
null
;
}
...
...
@@ -421,7 +420,7 @@ export class TypeOperations {
return
null
;
}
public
static
typeWithInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
,
ch
:
string
):
EditOperationResult
{
public
static
typeWithInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
,
ch
:
string
):
EditOperationResult
{
let
r
:
EditOperationResult
=
null
;
r
=
r
||
this
.
_typeInterceptorEnter
(
config
,
model
,
cursor
,
ch
);
...
...
@@ -434,14 +433,14 @@ export class TypeOperations {
return
r
;
}
public
static
typeWithoutInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
,
str
:
string
):
EditOperationResult
{
public
static
typeWithoutInterceptors
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
,
str
:
string
):
EditOperationResult
{
return
new
EditOperationResult
(
TypeOperations
.
typeCommand
(
cursor
.
selection
,
str
,
false
),
{
shouldPushStackElementBefore
:
false
,
shouldPushStackElementAfter
:
false
});
}
public
static
lineInsertBefore
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
lineInsertBefore
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
let
lineNumber
=
cursor
.
position
.
lineNumber
;
if
(
lineNumber
===
1
)
{
...
...
@@ -457,13 +456,13 @@ export class TypeOperations {
return
this
.
_enter
(
config
,
model
,
false
,
new
Range
(
lineNumber
,
column
,
lineNumber
,
column
));
}
public
static
lineInsertAfter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
lineInsertAfter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
let
position
=
cursor
.
position
;
let
column
=
model
.
getLineMaxColumn
(
position
.
lineNumber
);
return
this
.
_enter
(
config
,
model
,
false
,
new
Range
(
position
.
lineNumber
,
column
,
position
.
lineNumber
,
column
));
}
public
static
lineBreakInsert
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
public
static
lineBreakInsert
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
return
this
.
_enter
(
config
,
model
,
true
,
cursor
.
selection
);
}
}
src/vs/editor/common/controller/cursorWordOperations.ts
浏览文件 @
4a75f9b5
...
...
@@ -4,13 +4,12 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
EditOperationResult
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
SingleCursorState
,
EditOperationResult
,
CursorConfiguration
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
CharacterClassifier
}
from
'
vs/editor/common/core/characterClassifier
'
;
import
{
MoveOperationResult
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
import
{
Single
MoveOperationResult
}
from
'
vs/editor/common/controller/cursorMoveOperations
'
;
import
{
CursorChangeReason
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CursorModelState
}
from
'
vs/editor/common/controller/oneCursor
'
;
import
{
DeleteOperations
}
from
'
vs/editor/common/controller/cursorDeleteOperations
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
...
...
@@ -195,7 +194,7 @@ export class WordOperations {
return
0
;
}
public
static
moveWordLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModelState
,
inSelectionMode
:
boolean
,
wordNavigationType
:
WordNavigationType
):
MoveOperationResult
{
public
static
moveWordLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
,
inSelectionMode
:
boolean
,
wordNavigationType
:
WordNavigationType
):
Single
MoveOperationResult
{
let
position
=
cursor
.
position
;
let
lineNumber
=
position
.
lineNumber
;
let
column
=
position
.
column
;
...
...
@@ -226,10 +225,10 @@ export class WordOperations {
}
}
return
new
MoveOperationResult
(
inSelectionMode
,
lineNumber
,
column
,
0
,
true
,
CursorChangeReason
.
Explicit
);
return
SingleMoveOperationResult
.
fromMove
(
cursor
,
inSelectionMode
,
lineNumber
,
column
,
0
,
true
,
CursorChangeReason
.
Explicit
);
}
public
static
moveWordRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModelState
,
inSelectionMode
:
boolean
,
wordNavigationType
:
WordNavigationType
):
MoveOperationResult
{
public
static
moveWordRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
,
inSelectionMode
:
boolean
,
wordNavigationType
:
WordNavigationType
):
Single
MoveOperationResult
{
let
position
=
cursor
.
position
;
let
lineNumber
=
position
.
lineNumber
;
let
column
=
position
.
column
;
...
...
@@ -260,10 +259,10 @@ export class WordOperations {
}
}
return
new
MoveOperationResult
(
inSelectionMode
,
lineNumber
,
column
,
0
,
true
,
CursorChangeReason
.
Explicit
);
return
SingleMoveOperationResult
.
fromMove
(
cursor
,
inSelectionMode
,
lineNumber
,
column
,
0
,
true
,
CursorChangeReason
.
Explicit
);
}
private
static
_deleteWordLeftWhitespace
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
private
static
_deleteWordLeftWhitespace
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
let
position
=
cursor
.
position
;
let
lineContent
=
model
.
getLineContent
(
position
.
lineNumber
);
let
startIndex
=
position
.
column
-
2
;
...
...
@@ -278,7 +277,7 @@ export class WordOperations {
return
null
;
}
public
static
deleteWordLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
,
whitespaceHeuristics
:
boolean
,
wordNavigationType
:
WordNavigationType
):
EditOperationResult
{
public
static
deleteWordLeft
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
,
whitespaceHeuristics
:
boolean
,
wordNavigationType
:
WordNavigationType
):
EditOperationResult
{
let
r
=
DeleteOperations
.
autoClosingPairDelete
(
config
,
model
,
cursor
);
if
(
r
)
{
// This was a case for an auto-closing pair delete
...
...
@@ -347,7 +346,7 @@ export class WordOperations {
return
len
;
}
private
static
_deleteWordRightWhitespace
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
):
EditOperationResult
{
private
static
_deleteWordRightWhitespace
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
):
EditOperationResult
{
let
position
=
cursor
.
position
;
let
lineContent
=
model
.
getLineContent
(
position
.
lineNumber
);
let
startIndex
=
position
.
column
-
1
;
...
...
@@ -363,7 +362,7 @@ export class WordOperations {
return
null
;
}
public
static
deleteWordRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
CursorModel
State
,
whitespaceHeuristics
:
boolean
,
wordNavigationType
:
WordNavigationType
):
EditOperationResult
{
public
static
deleteWordRight
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursor
State
,
whitespaceHeuristics
:
boolean
,
wordNavigationType
:
WordNavigationType
):
EditOperationResult
{
let
selection
=
cursor
.
selection
;
...
...
@@ -438,4 +437,77 @@ export class WordOperations {
// fall back to normal deleteRight behavior
return
DeleteOperations
.
deleteRight
(
config
,
model
,
cursor
);
}
public
static
word
(
config
:
CursorConfiguration
,
model
:
ICursorSimpleModel
,
cursor
:
SingleCursorState
,
inSelectionMode
:
boolean
,
position
:
Position
):
SingleMoveOperationResult
{
let
prevWord
=
WordOperations
.
findPreviousWordOnLine
(
config
,
model
,
position
);
let
isInPrevWord
=
(
prevWord
&&
prevWord
.
wordType
===
WordType
.
Regular
&&
prevWord
.
start
<
position
.
column
-
1
&&
position
.
column
-
1
<=
prevWord
.
end
);
let
nextWord
=
WordOperations
.
findNextWordOnLine
(
config
,
model
,
position
);
let
isInNextWord
=
(
nextWord
&&
nextWord
.
wordType
===
WordType
.
Regular
&&
nextWord
.
start
<
position
.
column
-
1
&&
position
.
column
-
1
<=
nextWord
.
end
);
if
(
!
inSelectionMode
||
!
cursor
.
hasSelection
())
{
let
startColumn
:
number
;
let
endColumn
:
number
;
if
(
isInPrevWord
)
{
startColumn
=
prevWord
.
start
+
1
;
endColumn
=
prevWord
.
end
+
1
;
}
else
if
(
isInNextWord
)
{
startColumn
=
nextWord
.
start
+
1
;
endColumn
=
nextWord
.
end
+
1
;
}
else
{
if
(
prevWord
)
{
startColumn
=
prevWord
.
end
+
1
;
}
else
{
startColumn
=
1
;
}
if
(
nextWord
)
{
endColumn
=
nextWord
.
start
+
1
;
}
else
{
endColumn
=
model
.
getLineMaxColumn
(
position
.
lineNumber
);
}
}
return
new
SingleMoveOperationResult
(
new
SingleCursorState
(
new
Range
(
position
.
lineNumber
,
startColumn
,
position
.
lineNumber
,
endColumn
),
0
,
new
Position
(
position
.
lineNumber
,
endColumn
),
0
),
false
,
CursorChangeReason
.
Explicit
);
}
let
startColumn
:
number
;
let
endColumn
:
number
;
if
(
isInPrevWord
)
{
startColumn
=
prevWord
.
start
+
1
;
endColumn
=
prevWord
.
end
+
1
;
}
else
if
(
isInNextWord
)
{
startColumn
=
nextWord
.
start
+
1
;
endColumn
=
nextWord
.
end
+
1
;
}
else
{
startColumn
=
position
.
column
;
endColumn
=
position
.
column
;
}
let
lineNumber
=
position
.
lineNumber
;
let
column
:
number
;
if
(
position
.
isBeforeOrEqual
(
cursor
.
selectionStart
.
getStartPosition
()))
{
column
=
startColumn
;
let
possiblePosition
=
new
Position
(
lineNumber
,
column
);
if
(
cursor
.
selectionStart
.
containsPosition
(
possiblePosition
))
{
column
=
cursor
.
selectionStart
.
endColumn
;
}
}
else
{
column
=
endColumn
;
let
possiblePosition
=
new
Position
(
lineNumber
,
column
);
if
(
cursor
.
selectionStart
.
containsPosition
(
possiblePosition
))
{
column
=
cursor
.
selectionStart
.
startColumn
;
}
}
return
SingleMoveOperationResult
.
fromMove
(
cursor
,
cursor
.
hasSelection
(),
lineNumber
,
column
,
0
,
false
,
CursorChangeReason
.
Explicit
);
}
}
src/vs/editor/common/controller/oneCursor.ts
浏览文件 @
4a75f9b5
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录