Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
77b19e50
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,发现更多精彩内容 >>
提交
77b19e50
编写于
7月 19, 2016
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement line up and down for cursor move #9143
上级
e83b5b41
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
160 addition
and
34 deletion
+160
-34
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+13
-3
src/vs/editor/common/controller/oneCursor.ts
src/vs/editor/common/controller/oneCursor.ts
+17
-21
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+47
-3
src/vs/editor/test/common/controller/cursor.test.ts
src/vs/editor/test/common/controller/cursor.test.ts
+69
-6
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+14
-1
未找到文件。
src/vs/editor/common/controller/cursor.ts
浏览文件 @
77b19e50
...
...
@@ -1128,7 +1128,7 @@ export class Cursor extends EventEmitter {
}
private
_cursorMove
(
ctx
:
IMultipleCursorOperationContext
):
boolean
{
return
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
move
(
oneCursor
,
!!
ctx
.
eventData
.
inSelectionMode
,
ctx
.
eventData
.
to
,
ctx
.
eventSource
,
oneCtx
));
return
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
move
(
oneCursor
,
ctx
.
eventData
,
ctx
.
eventSource
,
oneCtx
));
}
private
_columnSelectToLineNumber
:
number
=
0
;
...
...
@@ -1294,11 +1294,21 @@ export class Cursor extends EventEmitter {
}
private
_moveDown
(
inSelectionMode
:
boolean
,
isPaged
:
boolean
,
ctx
:
IMultipleCursorOperationContext
):
boolean
{
return
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
moveDown
(
oneCursor
,
inSelectionMode
,
isPaged
,
ctx
.
eventData
&&
ctx
.
eventData
.
pageSize
||
0
,
oneCtx
));
ctx
.
eventData
=
ctx
.
eventData
||
{};
ctx
.
eventData
.
to
=
editorCommon
.
CursorMoveViewPosition
.
LineDown
;
ctx
.
eventData
.
inSelectionMode
=
inSelectionMode
;
ctx
.
eventData
.
isPaged
=
isPaged
;
return
this
.
_cursorMove
(
ctx
);
}
private
_moveUp
(
inSelectionMode
:
boolean
,
isPaged
:
boolean
,
ctx
:
IMultipleCursorOperationContext
):
boolean
{
return
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
moveUp
(
oneCursor
,
inSelectionMode
,
isPaged
,
ctx
.
eventData
&&
ctx
.
eventData
.
pageSize
||
0
,
oneCtx
));
ctx
.
eventData
=
ctx
.
eventData
||
{};
ctx
.
eventData
.
to
=
editorCommon
.
CursorMoveViewPosition
.
LineUp
;
ctx
.
eventData
.
inSelectionMode
=
inSelectionMode
;
ctx
.
eventData
.
isPaged
=
isPaged
;
return
this
.
_cursorMove
(
ctx
);
}
private
_moveToBeginningOfLine
(
inSelectionMode
:
boolean
,
ctx
:
IMultipleCursorOperationContext
):
boolean
{
...
...
src/vs/editor/common/controller/oneCursor.ts
浏览文件 @
77b19e50
...
...
@@ -6,7 +6,6 @@
import
{
onUnexpectedError
,
illegalArgument
}
from
'
vs/base/common/errors
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
*
as
types
from
'
vs/base/common/types
'
;
import
{
ReplaceCommand
,
ReplaceCommandWithOffsetCursorState
,
ReplaceCommandWithoutChangingPosition
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
ShiftCommand
}
from
'
vs/editor/common/commands/shiftCommand
'
;
import
{
SurroundSelectionCommand
}
from
'
vs/editor/common/commands/surroundSelectionCommand
'
;
...
...
@@ -631,19 +630,6 @@ export class OneCursorOp {
validatedViewPosition
=
cursor
.
convertModelPositionToViewPosition
(
validatedPosition
.
lineNumber
,
validatedPosition
.
column
);
}
return
this
.
move
(
cursor
,
inSelectionMode
,
validatedViewPosition
,
eventSource
,
ctx
);
}
public
static
move
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
to
:
editorCommon
.
IPosition
|
string
,
eventSource
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
if
(
!
to
)
{
illegalArgument
(
'
to
'
);
}
if
(
types
.
isString
(
to
))
{
return
this
.
moveToLogicalViewPosition
(
cursor
,
inSelectionMode
,
to
,
ctx
);
}
let
viewPosition
:
editorCommon
.
IPosition
=
<
editorCommon
.
IPosition
>
to
;
let
reason
=
(
eventSource
===
'
mouse
'
?
editorCommon
.
CursorChangeReason
.
Explicit
:
editorCommon
.
CursorChangeReason
.
NotSet
);
if
(
eventSource
===
'
api
'
)
{
ctx
.
shouldRevealVerticalInCenter
=
true
;
...
...
@@ -651,15 +637,21 @@ export class OneCursorOp {
if
(
reason
)
{
ctx
.
cursorPositionChangeReason
=
reason
;
}
cursor
.
moveViewPosition
(
inSelectionMode
,
v
iewPosition
.
lineNumber
,
v
iewPosition
.
column
,
0
,
false
);
cursor
.
moveViewPosition
(
inSelectionMode
,
v
alidatedViewPosition
.
lineNumber
,
validatedV
iewPosition
.
column
,
0
,
false
);
return
true
;
}
private
static
moveToLogicalViewPosition
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
cursorMoveViewPosition
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
public
static
move
(
cursor
:
OneCursor
,
moveParams
:
editorCommon
.
CursorMoveArguments
,
eventSource
:
string
,
ctx
:
IOneCursorOperationContext
):
boolean
{
if
(
!
moveParams
.
to
)
{
illegalArgument
(
'
to
'
);
}
let
inSelectionMode
=
!!
moveParams
.
inSelectionMode
;
let
validatedViewPosition
=
cursor
.
getValidViewPosition
();
let
viewLineNumber
=
validatedViewPosition
.
lineNumber
;
let
noOfLines
=
moveParams
.
isPaged
?
(
moveParams
.
pageSize
||
cursor
.
getPageSize
())
:
moveParams
.
noOfLines
;
let
viewColumn
;
switch
(
cursorMoveViewPosition
)
{
switch
(
moveParams
.
to
)
{
case
editorCommon
.
CursorMoveViewPosition
.
LineStart
:
viewColumn
=
cursor
.
getViewLineMinColumn
(
viewLineNumber
);
break
;
...
...
@@ -675,6 +667,10 @@ export class OneCursorOp {
case
editorCommon
.
CursorMoveViewPosition
.
LineLastNonWhitespaceCharacter
:
viewColumn
=
cursor
.
getViewLineLastNonWhiteSpaceColumn
(
viewLineNumber
);
break
;
case
editorCommon
.
CursorMoveViewPosition
.
LineUp
:
return
this
.
moveUp
(
cursor
,
inSelectionMode
,
noOfLines
,
ctx
);
case
editorCommon
.
CursorMoveViewPosition
.
LineDown
:
return
this
.
moveDown
(
cursor
,
inSelectionMode
,
noOfLines
,
ctx
);
default
:
return
false
;
}
...
...
@@ -866,8 +862,8 @@ export class OneCursorOp {
return
true
;
}
public
static
moveDown
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
isPaged
:
boolean
,
usePageSize
:
number
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
linesCount
=
isPaged
?
(
usePageSize
||
cursor
.
getPageSize
())
:
1
;
public
static
moveDown
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
noOfLines
:
number
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
linesCount
=
noOfLines
>
0
?
noOfLines
:
1
;
let
viewLineNumber
:
number
,
viewColumn
:
number
;
...
...
@@ -907,8 +903,8 @@ export class OneCursorOp {
return
true
;
}
public
static
moveUp
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
isPaged
:
boolean
,
usePageSize
:
number
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
linesCount
=
isPaged
?
(
usePageSize
||
cursor
.
getPageSize
())
:
1
;
public
static
moveUp
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
noOfLines
:
number
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
linesCount
=
noOfLines
>
0
?
noOfLines
:
1
;
let
viewLineNumber
:
number
,
viewColumn
:
number
;
...
...
src/vs/editor/common/editorCommon.ts
浏览文件 @
77b19e50
...
...
@@ -4175,14 +4175,58 @@ export var EventType = {
};
/**
*
Logical p
ositions in the view for cursor move command.
*
P
ositions in the view for cursor move command.
*/
export
const
CursorMoveViewPosition
=
{
LineStart
:
'
lineStart
'
,
LineFirstNonWhitespaceCharacter
:
'
lineFirstNonWhitespaceCharacter
'
,
LineColumnCenter
:
'
lineColumnCenter
'
,
LineEnd
:
'
lineEnd
'
,
LineLastNonWhitespaceCharacter
:
'
lineLastNonWhitespaceCharacter
'
LineLastNonWhitespaceCharacter
:
'
lineLastNonWhitespaceCharacter
'
,
LineUp
:
'
lineUp
'
,
LineDown
:
'
lineDown
'
};
/**
* Arguments for Cursor move command
*/
export
interface
CursorMoveArguments
{
to
:
string
;
inSelectionMode
?:
boolean
;
noOfLines
?:
number
;
isPaged
?:
boolean
;
pageSize
?:
number
;
};
/**
* @internal
*/
let
isCursorMoveArgs
=
function
(
arg
):
boolean
{
if
(
!
types
.
isObject
(
arg
))
{
return
false
;
}
if
(
!
types
.
isString
(
arg
.
to
))
{
return
false
;
}
if
(
!
types
.
isUndefined
(
arg
.
inSelectionMode
)
&&
!
types
.
isBoolean
(
arg
.
inSelectionMode
))
{
return
false
;
}
if
(
!
types
.
isUndefined
(
arg
.
noOfLines
)
&&
!
types
.
isNumber
(
arg
.
noOfLines
))
{
return
false
;
}
if
(
!
types
.
isUndefined
(
arg
.
isPaged
)
&&
!
types
.
isBoolean
(
arg
.
isPaged
))
{
return
false
;
}
if
(
!
types
.
isUndefined
(
arg
.
pageSize
)
&&
!
types
.
isNumber
(
arg
.
pageSize
))
{
return
false
;
}
return
true
;
};
/**
...
...
@@ -4195,7 +4239,7 @@ export var CommandDescription = {
{
name
:
nls
.
localize
(
'
editorCommand.cursorMove.arg.name
'
,
"
Cursor move argument
"
),
description
:
nls
.
localize
(
'
editorCommand.cursorMove.arg.description
'
,
"
Argument containing mandatory 'to' value and an optional 'inSelectionMode' value. Value of 'to' has to be a defined value in `CursorMoveViewPosition`.
"
),
constraint
:
(
arg
)
=>
types
.
isObject
(
arg
)
&&
types
.
isString
(
arg
.
to
)
&&
(
types
.
isUndefined
(
arg
.
inSelectionMode
)
||
types
.
isBoolean
(
arg
.
inSelectionMode
))
constraint
:
isCursorMoveArgs
}
]
}
...
...
src/vs/editor/test/common/controller/cursor.test.ts
浏览文件 @
77b19e50
...
...
@@ -56,8 +56,12 @@ function moveToLineLastNonWhiteSpaceCharacter(cursor: Cursor) {
move
(
cursor
,
{
to
:
CursorMoveViewPosition
.
LineLastNonWhitespaceCharacter
});
}
function
moveToPosition
(
cursor
:
Cursor
,
lineNumber
:
number
,
column
:
number
)
{
move
(
cursor
,
{
to
:
new
Position
(
lineNumber
,
column
)});
function
moveUpByCursorMoveCommand
(
cursor
:
Cursor
,
noOfLines
:
number
=
1
,
inSelectionMode
?:
boolean
)
{
move
(
cursor
,
{
to
:
CursorMoveViewPosition
.
LineUp
,
noOfLines
:
noOfLines
,
inSelectionMode
:
inSelectionMode
});
}
function
moveDownByCursorMoveCommand
(
cursor
:
Cursor
,
noOfLines
:
number
=
1
,
inSelectionMode
?:
boolean
)
{
move
(
cursor
,
{
to
:
CursorMoveViewPosition
.
LineDown
,
noOfLines
:
noOfLines
,
inSelectionMode
:
inSelectionMode
});
}
function
moveTo
(
cursor
:
Cursor
,
lineNumber
:
number
,
column
:
number
,
inSelectionMode
:
boolean
=
false
)
{
...
...
@@ -221,7 +225,7 @@ suite('Editor Controller - Cursor', () => {
cursorEqual
(
thisCursor
,
1
,
1
);
});
// ---------
move to first character of line
// ---------
cursor move command
test
(
'
move to first character of line from middle
'
,
()
=>
{
moveTo
(
thisCursor
,
1
,
8
);
...
...
@@ -319,11 +323,70 @@ suite('Editor Controller - Cursor', () => {
cursorEqual
(
thisCursor
,
1
,
11
);
});
test
(
'
move to position
'
,
()
=>
{
moveToPosition
(
thisCursor
,
3
,
10
);
cursorEqual
(
thisCursor
,
3
,
10
);
test
(
'
move up by cursor move command
'
,
()
=>
{
moveTo
(
thisCursor
,
3
,
5
);
cursorEqual
(
thisCursor
,
3
,
5
);
moveUpByCursorMoveCommand
(
thisCursor
,
2
);
cursorEqual
(
thisCursor
,
1
,
5
);
moveUpByCursorMoveCommand
(
thisCursor
,
1
);
cursorEqual
(
thisCursor
,
1
,
1
);
});
test
(
'
move up with selection by cursor move command
'
,
()
=>
{
moveTo
(
thisCursor
,
3
,
5
);
cursorEqual
(
thisCursor
,
3
,
5
);
moveUpByCursorMoveCommand
(
thisCursor
,
1
,
true
);
cursorEqual
(
thisCursor
,
2
,
2
,
3
,
5
);
moveUp
(
thisCursor
,
1
,
true
);
cursorEqual
(
thisCursor
,
1
,
5
,
3
,
5
);
});
test
(
'
move up and down with tabs by cursor move command
'
,
()
=>
{
moveTo
(
thisCursor
,
1
,
5
);
cursorEqual
(
thisCursor
,
1
,
5
);
moveDownByCursorMoveCommand
(
thisCursor
,
4
);
cursorEqual
(
thisCursor
,
5
,
2
);
moveUpByCursorMoveCommand
(
thisCursor
,
1
);
cursorEqual
(
thisCursor
,
4
,
1
);
moveUpByCursorMoveCommand
(
thisCursor
,
1
);
cursorEqual
(
thisCursor
,
3
,
5
);
moveUpByCursorMoveCommand
(
thisCursor
,
1
);
cursorEqual
(
thisCursor
,
2
,
2
);
moveUpByCursorMoveCommand
(
thisCursor
,
1
);
cursorEqual
(
thisCursor
,
1
,
5
);
});
test
(
'
move up and down with end of lines starting from a long one by cursor move command
'
,
()
=>
{
moveToEndOfLine
(
thisCursor
);
cursorEqual
(
thisCursor
,
1
,
LINE1
.
length
-
1
);
moveToEndOfLine
(
thisCursor
);
cursorEqual
(
thisCursor
,
1
,
LINE1
.
length
+
1
);
moveDownByCursorMoveCommand
(
thisCursor
,
2
);
cursorEqual
(
thisCursor
,
3
,
LINE3
.
length
+
1
);
moveDownByCursorMoveCommand
(
thisCursor
,
1
);
cursorEqual
(
thisCursor
,
4
,
LINE4
.
length
+
1
);
moveDownByCursorMoveCommand
(
thisCursor
,
1
);
cursorEqual
(
thisCursor
,
5
,
LINE5
.
length
+
1
);
moveUpByCursorMoveCommand
(
thisCursor
,
4
);
cursorEqual
(
thisCursor
,
1
,
LINE1
.
length
+
1
);
});
// --- end of cursor move command tests
test
(
'
move
'
,
()
=>
{
moveTo
(
thisCursor
,
1
,
2
);
cursorEqual
(
thisCursor
,
1
,
2
);
...
...
src/vs/monaco.d.ts
浏览文件 @
77b19e50
...
...
@@ -3190,7 +3190,7 @@ declare module monaco.editor {
};
/**
*
Logical p
ositions in the view for cursor move command.
*
P
ositions in the view for cursor move command.
*/
export
const
CursorMoveViewPosition
:
{
LineStart
:
string
;
...
...
@@ -3198,8 +3198,21 @@ declare module monaco.editor {
LineColumnCenter
:
string
;
LineEnd
:
string
;
LineLastNonWhitespaceCharacter
:
string
;
LineUp
:
string
;
LineDown
:
string
;
};
/**
* Arguments for Cursor move command
*/
export
interface
CursorMoveArguments
{
to
:
string
;
inSelectionMode
?:
boolean
;
noOfLines
?:
number
;
isPaged
?:
boolean
;
pageSize
?:
number
;
}
/**
* Built-in commands.
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录