Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
fdcdafb6
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,发现更多精彩内容 >>
提交
fdcdafb6
编写于
9月 26, 2018
作者:
P
Peng Lyu
提交者:
rebornix
10月 02, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Native word operations first cut.
上级
09c73807
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
116 addition
and
0 deletion
+116
-0
src/vs/editor/contrib/wordOperations/nativeWordOperations.ts
src/vs/editor/contrib/wordOperations/nativeWordOperations.ts
+115
-0
src/vs/editor/editor.all.ts
src/vs/editor/editor.all.ts
+1
-0
未找到文件。
src/vs/editor/contrib/wordOperations/nativeWordOperations.ts
0 → 100644
浏览文件 @
fdcdafb6
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
ICodeEditor
,
IContentWidget
,
IContentWidgetPosition
,
ContentWidgetPositionPreference
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
registerEditorContribution
,
EditorCommand
,
registerEditorCommand
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
KeybindingWeight
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
export
class
NativeWordController
extends
Disposable
implements
editorCommon
.
IEditorContribution
{
private
static
readonly
_id
=
'
editor.contrib.nativeWordController
'
;
static
get
(
editor
:
ICodeEditor
):
NativeWordController
{
return
editor
.
getContribution
<
NativeWordController
>
(
NativeWordController
.
_id
);
}
getId
():
string
{
return
NativeWordController
.
_id
;
}
private
_editor
:
ICodeEditor
;
private
_widget
:
NativeLineEditableContent
;
constructor
(
editor
:
ICodeEditor
,
@
IContextKeyService
contextKeyService
:
IContextKeyService
)
{
super
();
this
.
_editor
=
editor
;
this
.
_widget
=
new
NativeLineEditableContent
(
this
.
_editor
);
}
moveLeft
()
{
let
position
=
this
.
_editor
.
getPosition
();
let
newPosition
=
this
.
_widget
.
moveWordLeft
(
this
.
_editor
,
position
);
console
.
log
(
newPosition
);
this
.
_editor
.
setSelections
([
new
Selection
(
newPosition
.
lineNumber
,
newPosition
.
column
,
newPosition
.
lineNumber
,
newPosition
.
column
)]);
this
.
_editor
.
focus
();
}
}
class
NativeLineEditableContent
implements
IContentWidget
{
private
_position
:
IPosition
;
getId
():
string
{
return
'
nativeLine
'
;
}
getDomNode
():
HTMLElement
{
return
this
.
_domNode
;
}
getPosition
():
IContentWidgetPosition
{
return
{
position
:
this
.
_position
,
preference
:
[
ContentWidgetPositionPreference
.
BELOW
]
};
}
private
_domNode
:
HTMLDivElement
;
private
_span
:
HTMLSpanElement
;
constructor
(
editor
:
ICodeEditor
)
{
this
.
_domNode
=
document
.
createElement
(
'
div
'
);
this
.
_domNode
.
style
.
top
=
'
-1000px
'
;
this
.
_domNode
.
style
.
width
=
'
1023px
'
;
this
.
_span
=
document
.
createElement
(
'
span
'
);
this
.
_span
.
contentEditable
=
'
true
'
;
this
.
_span
.
style
.
visibility
=
'
initial
'
;
this
.
_domNode
.
appendChild
(
this
.
_span
);
editor
.
addContentWidget
(
this
);
}
moveWordLeft
(
editor
:
ICodeEditor
,
position
:
IPosition
):
IPosition
{
this
.
_position
=
position
;
let
line
=
this
.
_position
.
lineNumber
;
let
content
=
editor
.
getModel
().
getLineContent
(
line
);
this
.
_span
.
textContent
=
content
.
substr
(
0
,
position
.
column
-
1
);
const
selection
=
window
.
getSelection
();
const
firstRange
=
selection
.
getRangeAt
(
0
);
console
.
log
(
firstRange
);
const
range
=
document
.
createRange
();
range
.
selectNodeContents
(
this
.
_span
);
selection
.
removeAllRanges
();
selection
.
addRange
(
range
);
selection
.
collapseToEnd
();
(
<
any
>
selection
).
modify
(
'
extend
'
,
'
backward
'
,
'
word
'
);
let
characterCnt
=
selection
.
toString
().
length
;
selection
.
removeAllRanges
();
selection
.
addRange
(
firstRange
);
return
{
lineNumber
:
line
,
column
:
this
.
_position
.
column
-
characterCnt
};
}
}
registerEditorContribution
(
NativeWordController
);
const
NativeCommand
=
EditorCommand
.
bindToContribution
<
NativeWordController
>
(
NativeWordController
.
get
);
registerEditorCommand
(
new
NativeCommand
({
id
:
'
editor.moveNativeWordLeft
'
,
precondition
:
null
,
handler
:
x
=>
x
.
moveLeft
(),
kbOpts
:
{
weight
:
KeybindingWeight
.
EditorContrib
+
5
,
kbExpr
:
EditorContextKeys
.
focus
,
primary
:
null
}
}));
\ No newline at end of file
src/vs/editor/editor.all.ts
浏览文件 @
fdcdafb6
...
...
@@ -42,4 +42,5 @@ import 'vs/editor/contrib/suggest/suggestController';
import
'
vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode
'
;
import
'
vs/editor/contrib/wordHighlighter/wordHighlighter
'
;
import
'
vs/editor/contrib/wordOperations/wordOperations
'
;
import
'
vs/editor/contrib/wordOperations/nativeWordOperations
'
;
import
'
vs/editor/contrib/wordPartOperations/wordPartOperations
'
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录