Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
05f7db06
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,发现更多精彩内容 >>
提交
05f7db06
编写于
8月 09, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #27216: Change editor selection when a valid `selectionchange` event comes in.
上级
f329f2ba
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
74 addition
and
10 deletion
+74
-10
src/vs/editor/browser/controller/textAreaHandler.ts
src/vs/editor/browser/controller/textAreaHandler.ts
+8
-0
src/vs/editor/browser/controller/textAreaInput.ts
src/vs/editor/browser/controller/textAreaInput.ts
+17
-10
src/vs/editor/browser/view/viewController.ts
src/vs/editor/browser/view/viewController.ts
+8
-0
src/vs/editor/common/controller/coreCommands.ts
src/vs/editor/common/controller/coreCommands.ts
+20
-0
src/vs/editor/common/viewModel/viewModel.ts
src/vs/editor/common/viewModel/viewModel.ts
+1
-0
src/vs/editor/common/viewModel/viewModelImpl.ts
src/vs/editor/common/viewModel/viewModelImpl.ts
+16
-0
src/vs/editor/test/browser/controller/imeTester.ts
src/vs/editor/test/browser/controller/imeTester.ts
+4
-0
未找到文件。
src/vs/editor/browser/controller/textAreaHandler.ts
浏览文件 @
05f7db06
...
...
@@ -168,6 +168,10 @@ export class TextAreaHandler extends ViewPart {
}
return
PagedScreenReaderStrategy
.
fromEditorSelection
(
currentState
,
simpleModel
,
this
.
_selections
[
0
]);
},
deduceModelPosition
:
(
viewAnchorPosition
:
Position
,
deltaOffset
:
number
,
lineFeedCnt
:
number
):
Position
=>
{
return
this
.
_context
.
model
.
deduceModelPositionRelativeToViewPosition
(
viewAnchorPosition
,
deltaOffset
,
lineFeedCnt
);
}
};
...
...
@@ -201,6 +205,10 @@ export class TextAreaHandler extends ViewPart {
}
}));
this
.
_register
(
this
.
_textAreaInput
.
onSelectionChangeRequest
((
modelSelection
:
Selection
)
=>
{
this
.
_viewController
.
setSelection
(
'
keyboard
'
,
modelSelection
);
}));
this
.
_register
(
this
.
_textAreaInput
.
onCompositionStart
(()
=>
{
const
lineNumber
=
this
.
_selections
[
0
].
startLineNumber
;
const
column
=
this
.
_selections
[
0
].
startColumn
;
...
...
src/vs/editor/browser/controller/textAreaInput.ts
浏览文件 @
05f7db06
...
...
@@ -5,6 +5,8 @@
'
use strict
'
;
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
...
...
@@ -37,7 +39,7 @@ export interface ITextAreaInputHost {
getPlainTextToCopy
():
string
;
getHTMLToCopy
():
string
;
getScreenReaderContent
(
currentState
:
TextAreaState
):
TextAreaState
;
// deduceEditorPosition(anchor: Position, delta
: number, lineFeedCnt: number): Position;
deduceModelPosition
(
viewAnchorPosition
:
Position
,
deltaOffset
:
number
,
lineFeedCnt
:
number
):
Position
;
}
/**
...
...
@@ -80,6 +82,9 @@ export class TextAreaInput extends Disposable {
private
_onCompositionEnd
=
this
.
_register
(
new
Emitter
<
void
>
());
public
onCompositionEnd
:
Event
<
void
>
=
this
.
_onCompositionEnd
.
event
;
private
_onSelectionChangeRequest
=
this
.
_register
(
new
Emitter
<
Selection
>
());
public
onSelectionChangeRequest
:
Event
<
Selection
>
=
this
.
_onSelectionChangeRequest
.
event
;
// ---
private
readonly
_host
:
ITextAreaInputHost
;
...
...
@@ -363,16 +368,18 @@ export class TextAreaInput extends Disposable {
return
;
}
// const newSelectionStartPosition = this._textAreaState.deduceEditorPosition(newSelectionStart);
// const newSelectionEndPosition = this._textAreaState.deduceEditorPosition(newSelectionEnd);
const
_newSelectionStartPosition
=
this
.
_textAreaState
.
deduceEditorPosition
(
newSelectionStart
);
const
newSelectionStartPosition
=
this
.
_host
.
deduceModelPosition
(
_newSelectionStartPosition
[
0
],
_newSelectionStartPosition
[
1
],
_newSelectionStartPosition
[
2
]);
const
_newSelectionEndPosition
=
this
.
_textAreaState
.
deduceEditorPosition
(
newSelectionEnd
);
const
newSelectionEndPosition
=
this
.
_host
.
deduceModelPosition
(
_newSelectionEndPosition
[
0
],
_newSelectionEndPosition
[
1
],
_newSelectionEndPosition
[
2
]);
const
newSelection
=
new
Selection
(
newSelectionStartPosition
.
lineNumber
,
newSelectionStartPosition
.
column
,
newSelectionEndPosition
.
lineNumber
,
newSelectionEndPosition
.
column
);
// // TODO: React here to the new text area selection
// console.warn('!!!!!!!' + Date.now() + ':: RECEIVED selectionchange');
// console.log(this._textArea.getSelectionStart(), this._textArea.getSelectionEnd());
// console.log(this._textAreaState.selectionStart, this._textAreaState.selectionEnd);
// console.log(this._textAreaState.selectionStartPosition, this._textAreaState.selectionEndPosition);
// console.log(newSelectionStartPosition);
// console.log(newSelectionEndPosition);
this
.
_onSelectionChangeRequest
.
fire
(
newSelection
);
}));
}
...
...
src/vs/editor/browser/view/viewController.ts
浏览文件 @
05f7db06
...
...
@@ -6,6 +6,7 @@
import
{
IKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
IEditorMouseEvent
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
...
...
@@ -93,6 +94,13 @@ export class ViewController {
this
.
commandService
.
executeCommand
(
editorCommon
.
Handler
.
Cut
,
{});
}
public
setSelection
(
source
:
string
,
modelSelection
:
Selection
):
void
{
this
.
_execCoreEditorCommandFunc
(
CoreNavigationCommands
.
SetSelection
,
{
source
:
source
,
selection
:
modelSelection
});
}
private
_validateViewColumn
(
viewPosition
:
Position
):
Position
{
let
minColumn
=
this
.
viewModel
.
getLineMinColumn
(
viewPosition
.
lineNumber
);
if
(
viewPosition
.
column
<
minColumn
)
{
...
...
src/vs/editor/common/controller/coreCommands.ts
浏览文件 @
05f7db06
...
...
@@ -1507,6 +1507,26 @@ export namespace CoreNavigationCommands {
);
}
});
export
const
SetSelection
:
CoreEditorCommand
=
registerEditorCommand
(
new
class
extends
CoreEditorCommand
{
constructor
()
{
super
({
id
:
'
setSelection
'
,
precondition
:
null
});
}
public
runCoreEditorCommand
(
cursors
:
ICursors
,
args
:
any
):
void
{
cursors
.
context
.
model
.
pushStackElement
();
cursors
.
setStates
(
args
.
source
,
CursorChangeReason
.
Explicit
,
[
CursorState
.
fromModelSelection
(
args
.
selection
)
]
);
}
});
}
export
namespace
CoreEditingCommands
{
...
...
src/vs/editor/common/viewModel/viewModel.ts
浏览文件 @
05f7db06
...
...
@@ -137,6 +137,7 @@ export interface IViewModel {
getModelLineMaxColumn
(
modelLineNumber
:
number
):
number
;
validateModelPosition
(
modelPosition
:
IPosition
):
Position
;
deduceModelPositionRelativeToViewPosition
(
viewAnchorPosition
:
Position
,
deltaOffset
:
number
,
lineFeedCnt
:
number
):
Position
;
getPlainTextToCopy
(
ranges
:
Range
[],
emptySelectionClipboard
:
boolean
):
string
;
getHTMLToCopy
(
ranges
:
Range
[],
emptySelectionClipboard
:
boolean
):
string
;
}
...
...
src/vs/editor/common/viewModel/viewModelImpl.ts
浏览文件 @
05f7db06
...
...
@@ -440,6 +440,22 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
return
this
.
model
.
validatePosition
(
position
);
}
public
deduceModelPositionRelativeToViewPosition
(
viewAnchorPosition
:
Position
,
deltaOffset
:
number
,
lineFeedCnt
:
number
):
Position
{
const
modelAnchor
=
this
.
coordinatesConverter
.
convertViewPositionToModelPosition
(
viewAnchorPosition
);
if
(
this
.
model
.
getEOL
().
length
===
2
)
{
// This model uses CRLF, so the delta must take that into account
if
(
deltaOffset
<
0
)
{
deltaOffset
-=
lineFeedCnt
;
}
else
{
deltaOffset
+=
lineFeedCnt
;
}
}
const
modelAnchorOffset
=
this
.
model
.
getOffsetAt
(
modelAnchor
);
const
resultOffset
=
modelAnchorOffset
+
deltaOffset
;
return
this
.
model
.
getPositionAt
(
resultOffset
);
}
public
getPlainTextToCopy
(
ranges
:
Range
[],
emptySelectionClipboard
:
boolean
):
string
{
let
newLineCharacter
=
this
.
model
.
getEOL
();
...
...
src/vs/editor/test/browser/controller/imeTester.ts
浏览文件 @
05f7db06
...
...
@@ -7,6 +7,7 @@
import
{
TextAreaInput
,
ITextAreaInputHost
}
from
'
vs/editor/browser/controller/textAreaInput
'
;
import
{
ISimpleModel
,
TextAreaState
,
PagedScreenReaderStrategy
}
from
'
vs/editor/browser/controller/textAreaState
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
createFastDomNode
}
from
'
vs/base/browser/fastDomNode
'
;
import
*
as
browser
from
'
vs/base/browser/browser
'
;
...
...
@@ -100,6 +101,9 @@ function doCreateTest(description: string, inputStr: string, expectedStr: string
const
selection
=
new
Range
(
1
,
1
+
cursorOffset
,
1
,
1
+
cursorOffset
+
cursorLength
);
return
PagedScreenReaderStrategy
.
fromEditorSelection
(
currentState
,
model
,
selection
);
},
deduceModelPosition
:
(
viewAnchorPosition
:
Position
,
deltaOffset
:
number
,
lineFeedCnt
:
number
):
Position
=>
{
return
null
;
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录