Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
e0119398
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,发现更多精彩内容 >>
提交
e0119398
编写于
7月 21, 2016
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement left, right cursor move commands
上级
d4fac8e9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
129 addition
and
29 deletion
+129
-29
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+13
-5
src/vs/editor/common/controller/oneCursor.ts
src/vs/editor/common/controller/oneCursor.ts
+26
-16
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+4
-3
src/vs/editor/test/common/controller/cursorMoveCommand.test.ts
...s/editor/test/common/controller/cursorMoveCommand.test.ts
+82
-2
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+4
-3
未找到文件。
src/vs/editor/common/controller/cursor.ts
浏览文件 @
e0119398
...
...
@@ -1253,15 +1253,23 @@ export class Cursor extends EventEmitter {
}
private
_moveLeft
(
inSelectionMode
:
boolean
,
ctx
:
IMultipleCursorOperationContext
):
boolean
{
return
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
moveLeft
(
oneCursor
,
inSelectionMode
,
oneCtx
));
ctx
.
eventData
=
ctx
.
eventData
||
{};
ctx
.
eventData
.
to
=
editorCommon
.
CursorMovePosition
.
Left
;
ctx
.
eventData
.
select
=
inSelectionMode
;
return
this
.
_cursorMove
(
ctx
);
}
private
_moveWordLeft
(
inSelectionMode
:
boolean
,
wordNavigationType
:
WordNavigationType
,
ctx
:
IMultipleCursorOperationContext
):
boolean
{
return
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
moveWordLeft
(
oneCursor
,
inSelectionMode
,
wordNavigationType
,
oneCtx
));
}
private
_moveRight
(
inSelectionMode
:
boolean
,
ctx
:
IMultipleCursorOperationContext
):
boolean
{
return
this
.
_invokeForAll
(
ctx
,
(
cursorIndex
:
number
,
oneCursor
:
OneCursor
,
oneCtx
:
IOneCursorOperationContext
)
=>
OneCursorOp
.
moveRight
(
oneCursor
,
inSelectionMode
,
oneCtx
));
private
_moveRight
(
inSelectionMode
:
boolean
,
ctx
:
IMultipleCursorOperationContext
):
boolean
{
ctx
.
eventData
=
ctx
.
eventData
||
{};
ctx
.
eventData
.
to
=
editorCommon
.
CursorMovePosition
.
Right
;
ctx
.
eventData
.
select
=
inSelectionMode
;
return
this
.
_cursorMove
(
ctx
);
}
private
_moveWordRight
(
inSelectionMode
:
boolean
,
wordNavigationType
:
WordNavigationType
,
ctx
:
IMultipleCursorOperationContext
):
boolean
{
...
...
@@ -1272,7 +1280,7 @@ export class Cursor extends EventEmitter {
ctx
.
eventData
=
ctx
.
eventData
||
{};
ctx
.
eventData
.
to
=
editorCommon
.
CursorMovePosition
.
Down
;
ctx
.
eventData
.
select
=
inSelectionMode
;
ctx
.
eventData
.
by
=
editorCommon
.
CursorMoveByUnit
.
WrappedLine
s
;
ctx
.
eventData
.
by
=
editorCommon
.
CursorMoveByUnit
.
WrappedLine
;
ctx
.
eventData
.
isPaged
=
isPaged
;
return
this
.
_cursorMove
(
ctx
);
...
...
@@ -1282,7 +1290,7 @@ export class Cursor extends EventEmitter {
ctx
.
eventData
=
ctx
.
eventData
||
{};
ctx
.
eventData
.
to
=
editorCommon
.
CursorMovePosition
.
Up
;
ctx
.
eventData
.
select
=
inSelectionMode
;
ctx
.
eventData
.
by
=
editorCommon
.
CursorMoveByUnit
.
WrappedLine
s
;
ctx
.
eventData
.
by
=
editorCommon
.
CursorMoveByUnit
.
WrappedLine
;
ctx
.
eventData
.
isPaged
=
isPaged
;
return
this
.
_cursorMove
(
ctx
);
...
...
src/vs/editor/common/controller/oneCursor.ts
浏览文件 @
e0119398
...
...
@@ -581,6 +581,12 @@ export class OneCursor {
public
getViewLineCenterColumn
(
lineNumber
:
number
):
number
{
return
Math
.
round
((
this
.
getViewLineMaxColumn
(
lineNumber
)
+
this
.
getViewLineMinColumn
(
lineNumber
))
/
2
);
}
public
getViewLineSize
(
lineNumber
:
number
):
number
{
return
this
.
getViewLineMaxColumn
(
lineNumber
)
-
this
.
getViewLineMinColumn
(
lineNumber
);
}
public
getViewHalfLineSize
(
lineNumber
:
number
):
number
{
return
Math
.
round
(
this
.
getViewLineSize
(
lineNumber
)
/
2
);
}
public
getViewLineFirstNonWhiteSpaceColumn
(
lineNumber
:
number
):
number
{
return
this
.
viewModelHelper
.
viewModel
.
getLineFirstNonWhitespaceColumn
(
lineNumber
);
}
...
...
@@ -677,6 +683,20 @@ export class OneCursorOp {
let
noOfLines
=
moveParams
.
isPaged
?
(
moveParams
.
pageSize
||
cursor
.
getPageSize
())
:
moveParams
.
amount
;
let
viewColumn
;
switch
(
moveParams
.
to
)
{
case
editorCommon
.
CursorMovePosition
.
Left
:
return
this
.
moveLeft
(
cursor
,
inSelectionMode
,
editorCommon
.
CursorMoveByUnit
.
HalfLine
===
moveParams
.
by
?
cursor
.
getViewHalfLineSize
(
viewLineNumber
)
:
moveParams
.
amount
,
ctx
);
case
editorCommon
.
CursorMovePosition
.
Right
:
return
this
.
moveRight
(
cursor
,
inSelectionMode
,
editorCommon
.
CursorMoveByUnit
.
HalfLine
===
moveParams
.
by
?
cursor
.
getViewHalfLineSize
(
viewLineNumber
)
:
moveParams
.
amount
,
ctx
);
case
editorCommon
.
CursorMovePosition
.
Up
:
if
(
editorCommon
.
CursorMoveByUnit
.
WrappedLine
===
moveParams
.
by
)
{
return
this
.
moveUp
(
cursor
,
inSelectionMode
,
noOfLines
,
ctx
);
}
return
false
;
case
editorCommon
.
CursorMovePosition
.
Down
:
if
(
editorCommon
.
CursorMoveByUnit
.
WrappedLine
===
moveParams
.
by
)
{
return
this
.
moveDown
(
cursor
,
inSelectionMode
,
noOfLines
,
ctx
);
}
return
false
;
case
editorCommon
.
CursorMovePosition
.
WrappedLineStart
:
viewColumn
=
cursor
.
getViewLineMinColumn
(
viewLineNumber
);
break
;
...
...
@@ -692,22 +712,12 @@ export class OneCursorOp {
case
editorCommon
.
CursorMovePosition
.
WrappedLineLastNonWhitespaceCharacter
:
viewColumn
=
cursor
.
getViewLineLastNonWhiteSpaceColumn
(
viewLineNumber
);
break
;
case
editorCommon
.
CursorMovePosition
.
Up
:
if
(
editorCommon
.
CursorMoveByUnit
.
WrappedLines
===
moveParams
.
by
)
{
return
this
.
moveUp
(
cursor
,
inSelectionMode
,
noOfLines
,
ctx
);
}
return
false
;
case
editorCommon
.
CursorMovePosition
.
Down
:
if
(
editorCommon
.
CursorMoveByUnit
.
WrappedLines
===
moveParams
.
by
)
{
return
this
.
moveDown
(
cursor
,
inSelectionMode
,
noOfLines
,
ctx
);
}
return
false
;
case
editorCommon
.
CursorMovePosition
.
ViewPortTop
:
viewLineNumber
=
cursor
.
convertModelPositionToViewPosition
(
cursor
.
getLineFromViewPortTop
(
noOfLines
),
1
).
lineNumber
;
viewLineNumber
=
cursor
.
convertModelPositionToViewPosition
(
cursor
.
getLineFromViewPortTop
(
moveParams
.
amount
),
1
).
lineNumber
;
viewColumn
=
cursor
.
getViewLineFirstNonWhiteSpaceColumn
(
viewLineNumber
);
break
;
case
editorCommon
.
CursorMovePosition
.
ViewPortBottom
:
viewLineNumber
=
cursor
.
convertModelPositionToViewPosition
(
cursor
.
getLineFromViewPortBottom
(
noOfLines
),
1
).
lineNumber
;;
viewLineNumber
=
cursor
.
convertModelPositionToViewPosition
(
cursor
.
getLineFromViewPortBottom
(
moveParams
.
amount
),
1
).
lineNumber
;;
viewColumn
=
cursor
.
getViewLineFirstNonWhiteSpaceColumn
(
viewLineNumber
);
break
;
case
editorCommon
.
CursorMovePosition
.
ViewPortCenter
:
...
...
@@ -789,7 +799,7 @@ export class OneCursorOp {
return
this
.
_columnSelectOp
(
cursor
,
toViewLineNumber
,
toViewVisualColumn
);
}
public
static
moveLeft
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
ctx
:
IOneCursorOperationContext
):
boolean
{
public
static
moveLeft
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
noOfColumns
:
number
=
1
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
viewLineNumber
:
number
,
viewColumn
:
number
;
...
...
@@ -801,7 +811,7 @@ export class OneCursorOp {
viewColumn
=
viewSelectionStart
.
column
;
}
else
{
let
validatedViewPosition
=
cursor
.
getValidViewPosition
();
let
r
=
cursor
.
getLeftOfViewPosition
(
validatedViewPosition
.
lineNumber
,
validatedViewPosition
.
column
);
let
r
=
cursor
.
getLeftOfViewPosition
(
validatedViewPosition
.
lineNumber
,
validatedViewPosition
.
column
-
(
noOfColumns
-
1
)
);
viewLineNumber
=
r
.
lineNumber
;
viewColumn
=
r
.
column
;
}
...
...
@@ -847,7 +857,7 @@ export class OneCursorOp {
return
true
;
}
public
static
moveRight
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
ctx
:
IOneCursorOperationContext
):
boolean
{
public
static
moveRight
(
cursor
:
OneCursor
,
inSelectionMode
:
boolean
,
noOfColumns
:
number
=
1
,
ctx
:
IOneCursorOperationContext
):
boolean
{
let
viewLineNumber
:
number
,
viewColumn
:
number
;
...
...
@@ -859,7 +869,7 @@ export class OneCursorOp {
viewColumn
=
viewSelectionEnd
.
column
;
}
else
{
let
validatedViewPosition
=
cursor
.
getValidViewPosition
();
let
r
=
cursor
.
getRightOfViewPosition
(
validatedViewPosition
.
lineNumber
,
validatedViewPosition
.
column
);
let
r
=
cursor
.
getRightOfViewPosition
(
validatedViewPosition
.
lineNumber
,
validatedViewPosition
.
column
+
(
noOfColumns
-
1
)
);
viewLineNumber
=
r
.
lineNumber
;
viewColumn
=
r
.
column
;
}
...
...
src/vs/editor/common/editorCommon.ts
浏览文件 @
e0119398
...
...
@@ -4206,9 +4206,10 @@ export const CursorMovePosition = {
* Units for Cursor move 'by' argument
*/
export
const
CursorMoveByUnit
=
{
Lines
:
'
lines
'
,
WrappedLines
:
'
wrappedLines
'
,
Characters
:
'
characters
'
Line
:
'
line
'
,
WrappedLine
:
'
wrappedLine
'
,
Character
:
'
character
'
,
HalfLine
:
'
halfLine
'
};
/**
...
...
src/vs/editor/test/common/controller/cursorMoveCommand.test.ts
浏览文件 @
e0119398
...
...
@@ -46,6 +46,78 @@ suite('Cursor move command test', () => {
thisConfiguration
.
dispose
();
});
test
(
'
move left should move to left character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveLeft
(
thisCursor
);
cursorEqual
(
thisCursor
,
1
,
7
);
});
test
(
'
move left should move to left by n characters
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveLeft
(
thisCursor
,
3
);
cursorEqual
(
thisCursor
,
1
,
5
);
});
test
(
'
move left should move to left by half line
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveLeft
(
thisCursor
,
1
,
CursorMoveByUnit
.
HalfLine
);
cursorEqual
(
thisCursor
,
1
,
1
);
});
test
(
'
move left moves to previous line
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
2
,
3
);
moveLeft
(
thisCursor
,
10
);
cursorEqual
(
thisCursor
,
1
,
LINE1
.
length
+
1
);
});
test
(
'
move right should move to right character
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
5
);
moveRight
(
thisCursor
);
cursorEqual
(
thisCursor
,
1
,
6
);
});
test
(
'
move right should move to right by n characters
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
2
);
moveRight
(
thisCursor
,
6
);
cursorEqual
(
thisCursor
,
1
,
8
);
});
test
(
'
move right should move to right by half line
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
4
);
moveRight
(
thisCursor
,
1
,
CursorMoveByUnit
.
HalfLine
);
cursorEqual
(
thisCursor
,
1
,
14
);
});
test
(
'
move right moves to next line
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
moveRight
(
thisCursor
,
100
);
cursorEqual
(
thisCursor
,
2
,
1
);
});
test
(
'
move to first character of line from middle
'
,
()
=>
{
thisCursor
=
aCursor
();
moveTo
(
thisCursor
,
1
,
8
);
...
...
@@ -404,12 +476,20 @@ function moveToLineLastNonWhiteSpaceCharacter(cursor: Cursor) {
move
(
cursor
,
{
to
:
CursorMovePosition
.
WrappedLineLastNonWhitespaceCharacter
});
}
function
moveLeft
(
cursor
:
Cursor
,
amount
?:
number
,
by
?:
string
,
select
?:
boolean
)
{
move
(
cursor
,
{
to
:
CursorMovePosition
.
Left
,
by
:
by
,
amount
:
amount
,
select
:
select
});
}
function
moveRight
(
cursor
:
Cursor
,
amount
?:
number
,
by
?:
string
,
select
?:
boolean
)
{
move
(
cursor
,
{
to
:
CursorMovePosition
.
Right
,
by
:
by
,
amount
:
amount
,
select
:
select
});
}
function
moveUp
(
cursor
:
Cursor
,
noOfLines
:
number
=
1
,
select
?:
boolean
)
{
move
(
cursor
,
{
to
:
CursorMovePosition
.
Up
,
by
:
CursorMoveByUnit
.
WrappedLine
s
,
amount
:
noOfLines
,
select
:
select
});
move
(
cursor
,
{
to
:
CursorMovePosition
.
Up
,
by
:
CursorMoveByUnit
.
WrappedLine
,
amount
:
noOfLines
,
select
:
select
});
}
function
moveDown
(
cursor
:
Cursor
,
noOfLines
:
number
=
1
,
select
?:
boolean
)
{
move
(
cursor
,
{
to
:
CursorMovePosition
.
Down
,
by
:
CursorMoveByUnit
.
WrappedLine
s
,
amount
:
noOfLines
,
select
:
select
});
move
(
cursor
,
{
to
:
CursorMovePosition
.
Down
,
by
:
CursorMoveByUnit
.
WrappedLine
,
amount
:
noOfLines
,
select
:
select
});
}
function
moveToTop
(
cursor
:
Cursor
,
noOfLines
:
number
=
1
,
select
?:
boolean
)
{
...
...
src/vs/monaco.d.ts
浏览文件 @
e0119398
...
...
@@ -3216,9 +3216,10 @@ declare module monaco.editor {
* Units for Cursor move 'by' argument
*/
export
const
CursorMoveByUnit
:
{
Lines
:
string
;
WrappedLines
:
string
;
Characters
:
string
;
Line
:
string
;
WrappedLine
:
string
;
Character
:
string
;
HalfLine
:
string
;
};
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录