Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
b4631d39
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,发现更多精彩内容 >>
未验证
提交
b4631d39
编写于
5月 25, 2020
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Emit ReadOnlyEditAttemptEvent through view model
上级
81e71a4a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
23 deletion
+47
-23
src/vs/editor/browser/widget/codeEditorWidget.ts
src/vs/editor/browser/widget/codeEditorWidget.ts
+3
-4
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+5
-8
src/vs/editor/common/viewModel/viewModelEventDispatcher.ts
src/vs/editor/common/viewModel/viewModelEventDispatcher.ts
+18
-0
src/vs/editor/common/viewModel/viewModelImpl.ts
src/vs/editor/common/viewModel/viewModelImpl.ts
+21
-11
未找到文件。
src/vs/editor/browser/widget/codeEditorWidget.ts
浏览文件 @
b4631d39
...
...
@@ -1473,10 +1473,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
// Someone might destroy the model from under the editor, so prevent any exceptions by setting a null model
listenersToRemove
.
push
(
model
.
onWillDispose
(()
=>
this
.
setModel
(
null
)));
listenersToRemove
.
push
(
viewModel
.
cursor
.
onDidAttemptReadOnlyEdit
(()
=>
{
this
.
_onDidAttemptReadOnlyEdit
.
fire
(
undefined
);
}));
listenersToRemove
.
push
(
viewModel
.
onEvent
((
e
)
=>
{
switch
(
e
.
kind
)
{
case
OutgoingViewModelEventKind
.
ContentSizeChanged
:
...
...
@@ -1491,6 +1487,9 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
case
OutgoingViewModelEventKind
.
ViewZonesChanged
:
this
.
_onDidChangeViewZones
.
fire
();
break
;
case
OutgoingViewModelEventKind
.
ReadOnlyEditAttempt
:
this
.
_onDidAttemptReadOnlyEdit
.
fire
();
break
;
case
OutgoingViewModelEventKind
.
CursorStateChanged
:
{
if
(
e
.
reachedMaxCursorCount
)
{
this
.
_notificationService
.
warn
(
nls
.
localize
(
'
cursors.maximum
'
,
"
The number of cursors has been limited to {0}.
"
,
Cursor
.
MAX_CURSOR_COUNT
));
...
...
src/vs/editor/common/controller/cursor.ts
浏览文件 @
b4631d39
...
...
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
CursorCollection
}
from
'
vs/editor/common/controller/cursorCollection
'
;
import
{
CursorColumns
,
CursorConfiguration
,
CursorContext
,
CursorState
,
EditOperationResult
,
EditOperationType
,
IColumnSelectData
,
PartialCursorState
,
ICursorSimpleModel
}
from
'
vs/editor/common/controller/cursorCommon
'
;
...
...
@@ -124,9 +123,6 @@ export class Cursor extends Disposable {
public
static
readonly
MAX_CURSOR_COUNT
=
10000
;
private
readonly
_onDidAttemptReadOnlyEdit
:
Emitter
<
void
>
=
this
.
_register
(
new
Emitter
<
void
>
());
public
readonly
onDidAttemptReadOnlyEdit
:
Event
<
void
>
=
this
.
_onDidAttemptReadOnlyEdit
.
event
;
private
readonly
_model
:
ITextModel
;
private
_knownModelVersionId
:
number
;
private
readonly
_viewModel
:
ICursorSimpleModel
;
...
...
@@ -598,7 +594,6 @@ export class Cursor extends Disposable {
private
_executeEdit
(
callback
:
()
=>
void
,
eventsCollector
:
ViewModelEventsCollector
,
source
:
string
|
null
|
undefined
,
cursorChangeReason
:
CursorChangeReason
=
CursorChangeReason
.
NotSet
):
void
{
if
(
this
.
context
.
cursorConfig
.
readOnly
)
{
// we cannot edit when read only...
this
.
_onDidAttemptReadOnlyEdit
.
fire
(
undefined
);
return
;
}
...
...
@@ -621,15 +616,17 @@ export class Cursor extends Disposable {
}
}
public
setIsDoingComposition
(
isDoingComposition
:
boolean
):
void
{
this
.
_isDoingComposition
=
isDoingComposition
;
}
public
startComposition
(
eventsCollector
:
ViewModelEventsCollector
):
void
{
this
.
_isDoingComposition
=
true
;
this
.
_selectionsWhenCompositionStarted
=
this
.
getSelections
().
slice
(
0
);
}
public
endComposition
(
eventsCollector
:
ViewModelEventsCollector
,
source
?:
string
|
null
|
undefined
):
void
{
this
.
_isDoingComposition
=
false
;
this
.
_executeEdit
(()
=>
{
if
(
!
this
.
_isDoingComposition
&&
source
===
'
keyboard
'
)
{
if
(
source
===
'
keyboard
'
)
{
// composition finishes, let's check if we need to auto complete if necessary.
const
autoClosedCharacters
=
AutoClosedAction
.
getAllAutoClosedCharacters
(
this
.
_autoClosedActions
);
this
.
_executeEditOperation
(
TypeOperations
.
compositionEndWithInterceptors
(
this
.
_prevEditOperationType
,
this
.
context
.
cursorConfig
,
this
.
_model
,
this
.
_selectionsWhenCompositionStarted
,
this
.
getSelections
(),
autoClosedCharacters
));
...
...
src/vs/editor/common/viewModel/viewModelEventDispatcher.ts
浏览文件 @
b4631d39
...
...
@@ -176,6 +176,7 @@ export const enum OutgoingViewModelEventKind {
FocusChanged
,
ScrollChanged
,
ViewZonesChanged
,
ReadOnlyEditAttempt
,
CursorStateChanged
,
}
...
...
@@ -366,10 +367,27 @@ export class CursorStateChangedEvent {
}
}
export
class
ReadOnlyEditAttemptEvent
{
public
readonly
kind
=
OutgoingViewModelEventKind
.
ReadOnlyEditAttempt
;
constructor
()
{
}
public
isNoOp
():
boolean
{
return
false
;
}
public
merge
(
other
:
OutgoingViewModelEvent
):
ReadOnlyEditAttemptEvent
{
return
this
;
}
}
export
type
OutgoingViewModelEvent
=
(
ContentSizeChangedEvent
|
FocusChangedEvent
|
ScrollChangedEvent
|
ViewZonesChangedEvent
|
ReadOnlyEditAttemptEvent
|
CursorStateChangedEvent
);
src/vs/editor/common/viewModel/viewModelImpl.ts
浏览文件 @
b4631d39
...
...
@@ -30,7 +30,7 @@ import { Cursor } from 'vs/editor/common/controller/cursor';
import
{
PartialCursorState
,
CursorState
,
IColumnSelectData
,
EditOperationType
,
CursorConfiguration
}
from
'
vs/editor/common/controller/cursorCommon
'
;
import
{
CursorChangeReason
}
from
'
vs/editor/common/controller/cursorEvents
'
;
import
{
IWhitespaceChangeAccessor
}
from
'
vs/editor/common/viewLayout/linesLayout
'
;
import
{
ViewModelEventDispatcher
,
OutgoingViewModelEvent
,
FocusChangedEvent
,
ScrollChangedEvent
,
ViewZonesChangedEvent
,
ViewModelEventsCollector
}
from
'
vs/editor/common/viewModel/viewModelEventDispatcher
'
;
import
{
ViewModelEventDispatcher
,
OutgoingViewModelEvent
,
FocusChangedEvent
,
ScrollChangedEvent
,
ViewZonesChangedEvent
,
ViewModelEventsCollector
,
ReadOnlyEditAttemptEvent
}
from
'
vs/editor/common/viewModel/viewModelEventDispatcher
'
;
import
{
ViewEventHandler
}
from
'
vs/editor/common/viewModel/viewEventHandler
'
;
const
USE_IDENTITY_LINES_COLLECTION
=
true
;
...
...
@@ -52,7 +52,7 @@ export class ViewModel extends Disposable implements IViewModel {
private
readonly
lines
:
IViewModelLinesCollection
;
public
readonly
coordinatesConverter
:
ICoordinatesConverter
;
public
readonly
viewLayout
:
ViewLayout
;
p
ublic
readonly
cursor
:
Cursor
;
p
rivate
readonly
cursor
:
Cursor
;
private
readonly
decorations
:
ViewModelDecorations
;
constructor
(
...
...
@@ -914,32 +914,42 @@ export class ViewModel extends Disposable implements IViewModel {
this
.
_withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
restoreState
(
eventsCollector
,
states
));
}
private
_executeCursorEdit
(
callback
:
(
eventsCollector
:
ViewModelEventsCollector
)
=>
void
):
void
{
if
(
this
.
cursor
.
context
.
cursorConfig
.
readOnly
)
{
// we cannot edit when read only...
this
.
_eventDispatcher
.
emitOutgoingEvent
(
new
ReadOnlyEditAttemptEvent
());
return
;
}
this
.
_withViewEventsCollector
(
callback
);
}
public
executeEdits
(
source
:
string
|
null
|
undefined
,
edits
:
IIdentifiedSingleEditOperation
[],
cursorStateComputer
:
ICursorStateComputer
):
void
{
this
.
_
withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
executeEdits
(
eventsCollector
,
source
,
edits
,
cursorStateComputer
));
this
.
_
executeCursorEdit
(
eventsCollector
=>
this
.
cursor
.
executeEdits
(
eventsCollector
,
source
,
edits
,
cursorStateComputer
));
}
public
startComposition
():
void
{
this
.
_withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
startComposition
(
eventsCollector
));
this
.
cursor
.
setIsDoingComposition
(
true
);
this
.
_executeCursorEdit
(
eventsCollector
=>
this
.
cursor
.
startComposition
(
eventsCollector
));
}
public
endComposition
(
source
?:
string
|
null
|
undefined
):
void
{
this
.
_withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
endComposition
(
eventsCollector
,
source
));
this
.
cursor
.
setIsDoingComposition
(
false
);
this
.
_executeCursorEdit
(
eventsCollector
=>
this
.
cursor
.
endComposition
(
eventsCollector
,
source
));
}
public
type
(
text
:
string
,
source
?:
string
|
null
|
undefined
):
void
{
this
.
_
withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
type
(
eventsCollector
,
text
,
source
));
this
.
_
executeCursorEdit
(
eventsCollector
=>
this
.
cursor
.
type
(
eventsCollector
,
text
,
source
));
}
public
replacePreviousChar
(
text
:
string
,
replaceCharCnt
:
number
,
source
?:
string
|
null
|
undefined
):
void
{
this
.
_
withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
replacePreviousChar
(
eventsCollector
,
text
,
replaceCharCnt
,
source
));
this
.
_
executeCursorEdit
(
eventsCollector
=>
this
.
cursor
.
replacePreviousChar
(
eventsCollector
,
text
,
replaceCharCnt
,
source
));
}
public
paste
(
text
:
string
,
pasteOnNewLine
:
boolean
,
multicursorText
?:
string
[]
|
null
|
undefined
,
source
?:
string
|
null
|
undefined
):
void
{
this
.
_
withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
paste
(
eventsCollector
,
text
,
pasteOnNewLine
,
multicursorText
,
source
));
this
.
_
executeCursorEdit
(
eventsCollector
=>
this
.
cursor
.
paste
(
eventsCollector
,
text
,
pasteOnNewLine
,
multicursorText
,
source
));
}
public
cut
(
source
?:
string
|
null
|
undefined
):
void
{
this
.
_
withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
cut
(
eventsCollector
,
source
));
this
.
_
executeCursorEdit
(
eventsCollector
=>
this
.
cursor
.
cut
(
eventsCollector
,
source
));
}
public
executeCommand
(
command
:
ICommand
,
source
?:
string
|
null
|
undefined
):
void
{
this
.
_
withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
executeCommand
(
eventsCollector
,
command
,
source
));
this
.
_
executeCursorEdit
(
eventsCollector
=>
this
.
cursor
.
executeCommand
(
eventsCollector
,
command
,
source
));
}
public
executeCommands
(
commands
:
ICommand
[],
source
?:
string
|
null
|
undefined
):
void
{
this
.
_
withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
executeCommands
(
eventsCollector
,
commands
,
source
));
this
.
_
executeCursorEdit
(
eventsCollector
=>
this
.
cursor
.
executeCommands
(
eventsCollector
,
commands
,
source
));
}
public
revealPrimaryCursor
(
source
:
string
|
null
|
undefined
,
revealHorizontal
:
boolean
):
void
{
this
.
_withViewEventsCollector
(
eventsCollector
=>
this
.
cursor
.
revealPrimary
(
eventsCollector
,
source
,
revealHorizontal
,
ScrollType
.
Smooth
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录