Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
259b7bfb
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,发现更多精彩内容 >>
未验证
提交
259b7bfb
编写于
10月 18, 2019
作者:
A
Alexandru Dima
提交者:
GitHub
10月 18, 2019
浏览文件
操作
浏览文件
下载
差异文件
Add `cursorRedo` command (Ctrl+Shift+J) (#82620)
Add `cursorRedo` command (Ctrl+Shift+J)
上级
fca98f0b
a1ff8660
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
56 addition
and
34 deletion
+56
-34
src/vs/editor/contrib/cursorUndo/cursorUndo.ts
src/vs/editor/contrib/cursorUndo/cursorUndo.ts
+56
-34
未找到文件。
src/vs/editor/contrib/cursorUndo/cursorUndo.ts
浏览文件 @
259b7bfb
...
...
@@ -26,77 +26,83 @@ class CursorState {
}
}
export
class
CursorUndoController
extends
Disposable
implements
IEditorContribution
{
export
class
CursorUndo
Redo
Controller
extends
Disposable
implements
IEditorContribution
{
public
static
readonly
ID
=
'
editor.contrib.cursorUndoController
'
;
public
static
readonly
ID
=
'
editor.contrib.cursorUndo
Redo
Controller
'
;
public
static
get
(
editor
:
ICodeEditor
):
CursorUndoController
{
return
editor
.
getContribution
<
CursorUndo
Controller
>
(
CursorUn
doController
.
ID
);
public
static
get
(
editor
:
ICodeEditor
):
CursorUndo
Redo
Controller
{
return
editor
.
getContribution
<
CursorUndo
RedoController
>
(
CursorUndoRe
doController
.
ID
);
}
private
readonly
_editor
:
ICodeEditor
;
private
_isCursorUndo
:
boolean
;
private
_isCursorUndo
Redo
:
boolean
;
private
_undoStack
:
CursorState
[];
private
_redoStack
:
CursorState
[];
private
_prevState
:
CursorState
|
null
;
constructor
(
editor
:
ICodeEditor
)
{
super
();
this
.
_editor
=
editor
;
this
.
_isCursorUndo
=
false
;
this
.
_isCursorUndo
Redo
=
false
;
this
.
_undoStack
=
[];
this
.
_prevState
=
this
.
_readState
();
this
.
_redoStack
=
[];
this
.
_prevState
=
null
;
this
.
_register
(
editor
.
onDidChangeModel
((
e
)
=>
{
this
.
_undoStack
=
[];
this
.
_redoStack
=
[];
this
.
_prevState
=
null
;
}));
this
.
_register
(
editor
.
onDidChangeModelContent
((
e
)
=>
{
this
.
_undoStack
=
[];
this
.
_redoStack
=
[];
this
.
_prevState
=
null
;
}));
this
.
_register
(
editor
.
onDidChangeCursorSelection
((
e
)
=>
{
if
(
!
this
.
_isCursorUndo
&&
this
.
_prevState
)
{
this
.
_undoStack
.
push
(
this
.
_prevState
);
if
(
this
.
_undoStack
.
length
>
50
)
{
// keep the cursor undo stack bounded
this
.
_undoStack
.
shift
();
const
newState
=
new
CursorState
(
this
.
_editor
.
getSelections
()
!
);
if
(
!
this
.
_isCursorUndoRedo
&&
this
.
_prevState
)
{
const
isEqualToLastUndoStack
=
(
this
.
_undoStack
.
length
>
0
&&
this
.
_undoStack
[
this
.
_undoStack
.
length
-
1
].
equals
(
this
.
_prevState
));
if
(
!
isEqualToLastUndoStack
)
{
this
.
_undoStack
.
push
(
this
.
_prevState
);
this
.
_redoStack
=
[];
if
(
this
.
_undoStack
.
length
>
50
)
{
// keep the cursor undo stack bounded
this
.
_undoStack
.
shift
();
}
}
}
this
.
_prevState
=
this
.
_readState
()
;
this
.
_prevState
=
newState
;
}));
}
private
_readState
():
CursorState
|
null
{
if
(
!
this
.
_editor
.
hasModel
())
{
// no model => no state
return
null
;
public
cursorUndo
():
void
{
if
(
!
this
.
_editor
.
hasModel
()
||
this
.
_undoStack
.
length
===
0
)
{
return
;
}
return
new
CursorState
(
this
.
_editor
.
getSelections
());
this
.
_redoStack
.
push
(
new
CursorState
(
this
.
_editor
.
getSelections
()));
this
.
_applyState
(
this
.
_undoStack
.
pop
()
!
);
}
public
cursor
Un
do
():
void
{
if
(
!
this
.
_editor
.
hasModel
())
{
public
cursor
Re
do
():
void
{
if
(
!
this
.
_editor
.
hasModel
()
||
this
.
_redoStack
.
length
===
0
)
{
return
;
}
const
currState
=
new
CursorState
(
this
.
_editor
.
getSelections
());
while
(
this
.
_undoStack
.
length
>
0
)
{
const
prevState
=
this
.
_undoStack
.
pop
()
!
;
this
.
_undoStack
.
push
(
new
CursorState
(
this
.
_editor
.
getSelections
()));
this
.
_applyState
(
this
.
_redoStack
.
pop
()
!
);
}
if
(
!
prevState
.
equals
(
currState
))
{
this
.
_isCursorUndo
=
true
;
this
.
_editor
.
setSelections
(
prevState
.
selections
);
this
.
_editor
.
revealRangeInCenterIfOutsideViewport
(
prevState
.
selections
[
0
],
ScrollType
.
Smooth
);
this
.
_isCursorUndo
=
false
;
return
;
}
}
private
_applyState
(
state
:
CursorState
):
void
{
this
.
_isCursorUndoRedo
=
true
;
this
.
_editor
.
setSelections
(
state
.
selections
);
this
.
_editor
.
revealRangeInCenterIfOutsideViewport
(
state
.
selections
[
0
],
ScrollType
.
Smooth
);
this
.
_isCursorUndoRedo
=
false
;
}
}
...
...
@@ -116,9 +122,25 @@ export class CursorUndo extends EditorAction {
}
public
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
,
args
:
any
):
void
{
CursorUndoController
.
get
(
editor
).
cursorUndo
();
CursorUndoRedoController
.
get
(
editor
).
cursorUndo
();
}
}
export
class
CursorRedo
extends
EditorAction
{
constructor
()
{
super
({
id
:
'
cursorRedo
'
,
label
:
nls
.
localize
(
'
cursor.redo
'
,
"
Soft Redo
"
),
alias
:
'
Soft Redo
'
,
precondition
:
undefined
});
}
public
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
,
args
:
any
):
void
{
CursorUndoRedoController
.
get
(
editor
).
cursorRedo
();
}
}
registerEditorContribution
(
CursorUndo
Controller
.
ID
,
CursorUn
doController
);
registerEditorContribution
(
CursorUndo
RedoController
.
ID
,
CursorUndoRe
doController
);
registerEditorAction
(
CursorUndo
);
registerEditorAction
(
CursorRedo
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录