Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
5a40238c
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,发现更多精彩内容 >>
提交
5a40238c
编写于
5月 18, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move LineInsertBefore out of the cursor
上级
12738e3e
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
83 addition
and
62 deletion
+83
-62
src/vs/editor/browser/editor.all.ts
src/vs/editor/browser/editor.all.ts
+1
-0
src/vs/editor/common/commonCodeEditor.ts
src/vs/editor/common/commonCodeEditor.ts
+5
-1
src/vs/editor/common/controller/coreCommands.ts
src/vs/editor/common/controller/coreCommands.ts
+4
-1
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+0
-5
src/vs/editor/common/controller/cursorTypeOperations.ts
src/vs/editor/common/controller/cursorTypeOperations.ts
+3
-6
src/vs/editor/common/core/selection.ts
src/vs/editor/common/core/selection.ts
+8
-1
src/vs/editor/common/editorCommon.ts
src/vs/editor/common/editorCommon.ts
+6
-2
src/vs/editor/contrib/linesOperations/common/linesOperations.ts
.../editor/contrib/linesOperations/common/linesOperations.ts
+7
-2
src/vs/editor/contrib/linesOperations/test/common/linesOperations.test.ts
...ntrib/linesOperations/test/common/linesOperations.test.ts
+45
-2
src/vs/editor/test/common/controller/cursor.test.ts
src/vs/editor/test/common/controller/cursor.test.ts
+0
-42
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+4
-0
未找到文件。
src/vs/editor/browser/editor.all.ts
浏览文件 @
5a40238c
...
...
@@ -5,6 +5,7 @@
'
use strict
'
;
import
'
vs/editor/common/controller/coreCommands
'
;
import
'
vs/editor/browser/widget/codeEditorWidget
'
;
import
'
vs/editor/browser/widget/diffEditorWidget
'
;
...
...
src/vs/editor/common/commonCodeEditor.ts
浏览文件 @
5a40238c
...
...
@@ -13,7 +13,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import
{
IContextKey
,
IContextKeyServiceTarget
,
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
CommonEditorConfiguration
}
from
'
vs/editor/common/config/commonEditorConfig
'
;
import
{
Cursor
}
from
'
vs/editor/common/controller/cursor
'
;
import
{
CursorColumns
,
IViewModelHelper
,
ICursors
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
CursorColumns
,
IViewModelHelper
,
ICursors
,
CursorConfiguration
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
Position
,
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
,
ISelection
}
from
'
vs/editor/common/core/selection
'
;
...
...
@@ -698,6 +698,10 @@ export abstract class CommonCodeEditor extends Disposable implements editorCommo
return
this
.
cursor
;
}
public
_getCursorConfiguration
():
CursorConfiguration
{
return
this
.
cursor
.
context
.
config
;
}
public
pushUndoStop
():
boolean
{
if
(
!
this
.
model
)
{
return
false
;
...
...
src/vs/editor/common/controller/coreCommands.ts
浏览文件 @
5a40238c
...
...
@@ -1395,7 +1395,10 @@ export namespace CoreNavigationCommands {
);
}
});
};
}
export
namespace
CoreEditingCommands
{
}
namespace
Config
{
...
...
src/vs/editor/common/controller/cursor.ts
浏览文件 @
5a40238c
...
...
@@ -504,7 +504,6 @@ export class Cursor extends Disposable implements ICursors {
private
_registerHandlers
():
void
{
let
H
=
editorCommon
.
Handler
;
this
.
_handlers
[
H
.
LineInsertBefore
]
=
(
args
)
=>
this
.
_lineInsertBefore
(
args
);
this
.
_handlers
[
H
.
LineInsertAfter
]
=
(
args
)
=>
this
.
_lineInsertAfter
(
args
);
this
.
_handlers
[
H
.
LineBreakInsert
]
=
(
args
)
=>
this
.
_lineBreakInsert
(
args
);
...
...
@@ -559,10 +558,6 @@ export class Cursor extends Disposable implements ICursors {
return
r
;
}
private
_lineInsertBefore
(
args
:
CursorOperationArgs
<
void
>
):
EditOperationResult
{
return
TypeOperations
.
lineInsertBefore
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
_getAllCursorsModelState
());
}
private
_lineInsertAfter
(
args
:
CursorOperationArgs
<
void
>
):
EditOperationResult
{
return
TypeOperations
.
lineInsertAfter
(
this
.
context
.
config
,
this
.
context
.
model
,
this
.
_getAllCursorsModelState
());
}
...
...
src/vs/editor/common/controller/cursorTypeOperations.ts
浏览文件 @
5a40238c
...
...
@@ -582,11 +582,11 @@ export class TypeOperations {
});
}
public
static
lineInsertBefore
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
S
ingleCursorState
[]):
EditOperationResult
{
public
static
lineInsertBefore
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
S
election
[]):
ICommand
[]
{
let
commands
:
ICommand
[]
=
[];
for
(
let
i
=
0
,
len
=
cursors
.
length
;
i
<
len
;
i
++
)
{
const
cursor
=
cursors
[
i
];
let
lineNumber
=
cursor
.
position
.
l
ineNumber
;
let
lineNumber
=
cursor
.
position
L
ineNumber
;
if
(
lineNumber
===
1
)
{
commands
[
i
]
=
new
ReplaceCommandWithoutChangingPosition
(
new
Range
(
1
,
1
,
1
,
1
),
'
\n
'
);
...
...
@@ -597,10 +597,7 @@ export class TypeOperations {
commands
[
i
]
=
this
.
_enter
(
config
,
model
,
false
,
new
Range
(
lineNumber
,
column
,
lineNumber
,
column
));
}
}
return
new
EditOperationResult
(
commands
,
{
shouldPushStackElementBefore
:
true
,
shouldPushStackElementAfter
:
false
,
});
return
commands
;
}
public
static
lineInsertAfter
(
config
:
CursorConfiguration
,
model
:
ITokenizedModel
,
cursors
:
SingleCursorState
[]):
EditOperationResult
{
...
...
src/vs/editor/common/core/selection.ts
浏览文件 @
5a40238c
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
Position
,
IPosition
}
from
'
vs/editor/common/core/position
'
;
/**
* A selection in the editor.
...
...
@@ -129,6 +129,13 @@ export class Selection extends Range {
return
new
Selection
(
endLineNumber
,
endColumn
,
this
.
startLineNumber
,
this
.
startColumn
);
}
/**
* Get the position at `positionLineNumber` and `positionColumn`.
*/
public
getPosition
():
Position
{
return
new
Position
(
this
.
positionLineNumber
,
this
.
positionColumn
);
}
/**
* Create a new selection with a different `selectionStartLineNumber` and `selectionStartColumn`.
*/
...
...
src/vs/editor/common/editorCommon.ts
浏览文件 @
5a40238c
...
...
@@ -23,7 +23,7 @@ import {
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
*
as
editorOptions
from
'
vs/editor/common/config/editorOptions
'
;
import
{
ICursorPositionChangedEvent
,
ICursorSelectionChangedEvent
}
from
'
vs/editor/common/controller/cursorEvents
'
;
import
{
ICursors
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
ICursors
,
CursorConfiguration
}
from
'
vs/editor/common/controller/cursorCommon
'
;
/**
* Vertical Lane in the overview ruler of the editor.
...
...
@@ -1918,6 +1918,11 @@ export interface ICommonCodeEditor extends IEditor {
*/
_getCursors
():
ICursors
;
/**
* @internal
*/
_getCursorConfiguration
():
CursorConfiguration
;
/**
* Get all the decorations on a line (filtering out decorations from other editors).
*/
...
...
@@ -2078,7 +2083,6 @@ export var Handler = {
Undo
:
'
undo
'
,
Redo
:
'
redo
'
,
LineInsertBefore
:
'
lineInsertBefore
'
,
LineInsertAfter
:
'
lineInsertAfter
'
,
LineBreakInsert
:
'
lineBreakInsert
'
,
};
src/vs/editor/contrib/linesOperations/common/linesOperations.ts
浏览文件 @
5a40238c
...
...
@@ -18,6 +18,7 @@ import { editorAction, ServicesAccessor, IActionOptions, EditorAction, HandlerEd
import
{
CopyLinesCommand
}
from
'
./copyLinesCommand
'
;
import
{
DeleteLinesCommand
}
from
'
./deleteLinesCommand
'
;
import
{
MoveLinesCommand
}
from
'
./moveLinesCommand
'
;
import
{
TypeOperations
}
from
'
vs/editor/common/controller/cursorTypeOperations
'
;
// copy lines
...
...
@@ -329,20 +330,24 @@ class OutdentLinesAction extends HandlerEditorAction {
}
@
editorAction
class
InsertLineBeforeAction
extends
Handler
EditorAction
{
export
class
InsertLineBeforeAction
extends
EditorAction
{
constructor
()
{
super
({
id
:
'
editor.action.insertLineBefore
'
,
label
:
nls
.
localize
(
'
lines.insertBefore
'
,
"
Insert Line Above
"
),
alias
:
'
Insert Line Above
'
,
precondition
:
EditorContextKeys
.
writable
,
handlerId
:
Handler
.
LineInsertBefore
,
kbOpts
:
{
kbExpr
:
EditorContextKeys
.
textFocus
,
primary
:
KeyMod
.
CtrlCmd
|
KeyMod
.
Shift
|
KeyCode
.
Enter
}
});
}
public
run
(
accessor
:
ServicesAccessor
,
editor
:
ICommonCodeEditor
):
void
{
editor
.
pushUndoStop
();
editor
.
executeCommands
(
this
.
id
,
TypeOperations
.
lineInsertBefore
(
editor
.
_getCursorConfiguration
(),
editor
.
getModel
(),
editor
.
getSelections
()));
}
}
@
editorAction
...
...
src/vs/editor/contrib/linesOperations/test/common/linesOperations.test.ts
浏览文件 @
5a40238c
...
...
@@ -6,9 +6,11 @@
import
*
as
assert
from
'
assert
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
Handler
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Handler
,
IModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
withMockCodeEditor
}
from
'
vs/editor/test/common/mocks/mockCodeEditor
'
;
import
{
DeleteAllLeftAction
,
JoinLinesAction
,
TransposeAction
,
UpperCaseAction
,
LowerCaseAction
,
DeleteAllRightAction
}
from
'
vs/editor/contrib/linesOperations/common/linesOperations
'
;
import
{
DeleteAllLeftAction
,
JoinLinesAction
,
TransposeAction
,
UpperCaseAction
,
LowerCaseAction
,
DeleteAllRightAction
,
InsertLineBeforeAction
}
from
'
vs/editor/contrib/linesOperations/common/linesOperations
'
;
import
{
Cursor
}
from
"
vs/editor/common/controller/cursor
"
;
suite
(
'
Editor Contrib - Line Operations
'
,
()
=>
{
suite
(
'
DeleteAllLeftAction
'
,
()
=>
{
...
...
@@ -488,4 +490,45 @@ suite('Editor Contrib - Line Operations', () => {
});
});
});
test
(
'
InsertLineBeforeAction
'
,
function
()
{
function
testInsertLineBefore
(
lineNumber
:
number
,
column
:
number
,
callback
:
(
model
:
IModel
,
cursor
:
Cursor
)
=>
void
):
void
{
const
TEXT
=
[
'
First line
'
,
'
Second line
'
,
'
Third line
'
];
withMockCodeEditor
(
TEXT
,
{},
(
editor
,
cursor
)
=>
{
editor
.
setPosition
(
new
Position
(
lineNumber
,
column
));
let
insertLineBeforeAction
=
new
InsertLineBeforeAction
();
insertLineBeforeAction
.
run
(
null
,
editor
);
callback
(
editor
.
getModel
(),
cursor
);
});
}
testInsertLineBefore
(
1
,
3
,
(
model
,
cursor
)
=>
{
assert
.
deepEqual
(
cursor
.
getSelection
(),
new
Selection
(
1
,
1
,
1
,
1
));
assert
.
equal
(
model
.
getLineContent
(
1
),
''
);
assert
.
equal
(
model
.
getLineContent
(
2
),
'
First line
'
);
assert
.
equal
(
model
.
getLineContent
(
3
),
'
Second line
'
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
Third line
'
);
});
testInsertLineBefore
(
2
,
3
,
(
model
,
cursor
)
=>
{
assert
.
deepEqual
(
cursor
.
getSelection
(),
new
Selection
(
2
,
1
,
2
,
1
));
assert
.
equal
(
model
.
getLineContent
(
1
),
'
First line
'
);
assert
.
equal
(
model
.
getLineContent
(
2
),
''
);
assert
.
equal
(
model
.
getLineContent
(
3
),
'
Second line
'
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
Third line
'
);
});
testInsertLineBefore
(
3
,
3
,
(
model
,
cursor
)
=>
{
assert
.
deepEqual
(
cursor
.
getSelection
(),
new
Selection
(
3
,
1
,
3
,
1
));
assert
.
equal
(
model
.
getLineContent
(
1
),
'
First line
'
);
assert
.
equal
(
model
.
getLineContent
(
2
),
'
Second line
'
);
assert
.
equal
(
model
.
getLineContent
(
3
),
''
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
Third line
'
);
});
});
});
\ No newline at end of file
src/vs/editor/test/common/controller/cursor.test.ts
浏览文件 @
5a40238c
...
...
@@ -1930,48 +1930,6 @@ suite('Editor Controller - Cursor Configuration', () => {
mode
.
dispose
();
});
test
(
'
Insert line before
'
,
()
=>
{
let
testInsertLineBefore
=
(
lineNumber
:
number
,
column
:
number
,
callback
:
(
model
:
Model
,
cursor
:
Cursor
)
=>
void
)
=>
{
usingCursor
({
text
:
[
'
First line
'
,
'
Second line
'
,
'
Third line
'
],
},
(
model
,
cursor
)
=>
{
moveTo
(
cursor
,
lineNumber
,
column
,
false
);
assertCursor
(
cursor
,
new
Position
(
lineNumber
,
column
));
cursorCommand
(
cursor
,
H
.
LineInsertBefore
,
null
,
'
keyboard
'
);
callback
(
model
,
cursor
);
});
};
testInsertLineBefore
(
1
,
3
,
(
model
,
cursor
)
=>
{
assertCursor
(
cursor
,
new
Selection
(
1
,
1
,
1
,
1
));
assert
.
equal
(
model
.
getLineContent
(
1
),
''
);
assert
.
equal
(
model
.
getLineContent
(
2
),
'
First line
'
);
assert
.
equal
(
model
.
getLineContent
(
3
),
'
Second line
'
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
Third line
'
);
});
testInsertLineBefore
(
2
,
3
,
(
model
,
cursor
)
=>
{
assertCursor
(
cursor
,
new
Selection
(
2
,
1
,
2
,
1
));
assert
.
equal
(
model
.
getLineContent
(
1
),
'
First line
'
);
assert
.
equal
(
model
.
getLineContent
(
2
),
''
);
assert
.
equal
(
model
.
getLineContent
(
3
),
'
Second line
'
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
Third line
'
);
});
testInsertLineBefore
(
3
,
3
,
(
model
,
cursor
)
=>
{
assertCursor
(
cursor
,
new
Selection
(
3
,
1
,
3
,
1
));
assert
.
equal
(
model
.
getLineContent
(
1
),
'
First line
'
);
assert
.
equal
(
model
.
getLineContent
(
2
),
'
Second line
'
);
assert
.
equal
(
model
.
getLineContent
(
3
),
''
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
Third line
'
);
});
});
test
(
'
Insert line after
'
,
()
=>
{
let
testInsertLineAfter
=
(
lineNumber
:
number
,
column
:
number
,
callback
:
(
model
:
Model
,
cursor
:
Cursor
)
=>
void
)
=>
{
usingCursor
({
...
...
src/vs/monaco.d.ts
浏览文件 @
5a40238c
...
...
@@ -724,6 +724,10 @@ declare module monaco {
* Create a new selection with a different `positionLineNumber` and `positionColumn`.
*/
setEndPosition
(
endLineNumber
:
number
,
endColumn
:
number
):
Selection
;
/**
* Get the position at `positionLineNumber` and `positionColumn`.
*/
getPosition
():
Position
;
/**
* Create a new selection with a different `selectionStartLineNumber` and `selectionStartColumn`.
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录