Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
db27c552
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,发现更多精彩内容 >>
未验证
提交
db27c552
编写于
12月 18, 2020
作者:
A
Alexandru Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adopt `ICodeEditor.executeEdits`
上级
c1b988bc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
106 deletion
+13
-106
src/vs/editor/common/commands/replaceCommand.ts
src/vs/editor/common/commands/replaceCommand.ts
+0
-50
src/vs/editor/contrib/linesOperations/linesOperations.ts
src/vs/editor/contrib/linesOperations/linesOperations.ts
+13
-56
未找到文件。
src/vs/editor/common/commands/replaceCommand.ts
浏览文件 @
db27c552
...
...
@@ -142,53 +142,3 @@ export class ReplaceCommandThatPreservesSelection implements ICommand {
return
helper
.
getTrackedSelection
(
this
.
_selectionId
!
);
}
}
export
class
ReplaceCommandThatModifiesSelection
implements
ICommand
{
private
readonly
_range
:
Range
;
private
readonly
_text
:
string
;
private
readonly
_initialSelection
:
Selection
;
private
readonly
_initialText
:
string
;
private
readonly
_forceMoveMarkers
:
boolean
;
constructor
(
editRange
:
Range
,
text
:
string
,
initialSelection
:
Selection
,
initialText
:
string
,
forceMoveMarkers
:
boolean
=
false
)
{
this
.
_range
=
editRange
;
this
.
_text
=
text
;
this
.
_initialSelection
=
initialSelection
;
this
.
_initialText
=
initialText
;
this
.
_forceMoveMarkers
=
forceMoveMarkers
;
}
public
getEditOperations
(
model
:
ITextModel
,
builder
:
IEditOperationBuilder
):
void
{
builder
.
addTrackedEditOperation
(
this
.
_range
,
this
.
_text
,
this
.
_forceMoveMarkers
);
}
public
computeCursorState
(
model
:
ITextModel
,
helper
:
ICursorStateComputerData
):
Selection
{
let
startColumn
=
0
;
let
endColumn
=
0
;
const
modifiedLines
=
this
.
_text
.
split
(
'
\n
'
);
const
initialLines
=
this
.
_initialText
.
split
(
'
\n
'
);
const
{
selectionStartLineNumber
,
positionLineNumber
,
selectionStartColumn
,
positionColumn
}
=
this
.
_initialSelection
;
const
lastInitialLineLength
=
initialLines
[
initialLines
.
length
-
1
].
length
;
const
lastModifiedLineLength
=
modifiedLines
[
modifiedLines
.
length
-
1
].
length
;
if
(
selectionStartLineNumber
<
positionLineNumber
||
(
selectionStartLineNumber
===
positionLineNumber
&&
selectionStartColumn
<
positionColumn
))
{
startColumn
=
selectionStartColumn
;
endColumn
=
positionColumn
+
(
lastModifiedLineLength
-
lastInitialLineLength
);
}
else
if
(
selectionStartLineNumber
>
positionLineNumber
||
(
selectionStartLineNumber
===
positionLineNumber
&&
selectionStartColumn
>
positionColumn
))
{
endColumn
=
positionColumn
;
startColumn
=
selectionStartColumn
+
(
lastModifiedLineLength
-
lastInitialLineLength
);
}
else
{
startColumn
=
selectionStartColumn
;
endColumn
=
positionColumn
;
}
return
new
Selection
(
selectionStartLineNumber
,
startColumn
,
positionLineNumber
,
endColumn
);
}
}
src/vs/editor/contrib/linesOperations/linesOperations.ts
浏览文件 @
db27c552
...
...
@@ -8,7 +8,7 @@ import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import
{
CoreEditingCommands
}
from
'
vs/editor/browser/controller/coreCommands
'
;
import
{
ICodeEditor
,
IActiveCodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
EditorAction
,
IActionOptions
,
ServicesAccessor
,
registerEditorAction
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
ReplaceCommand
,
ReplaceCommandThatPreservesSelection
,
ReplaceCommandThatSelectsText
,
ReplaceCommandThatModifiesSelection
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
ReplaceCommand
,
ReplaceCommandThatPreservesSelection
,
ReplaceCommandThatSelectsText
}
from
'
vs/editor/common/commands/replaceCommand
'
;
import
{
TrimTrailingWhitespaceCommand
}
from
'
vs/editor/common/commands/trimTrailingWhitespaceCommand
'
;
import
{
TypeOperations
}
from
'
vs/editor/common/controller/cursorTypeOperations
'
;
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
...
...
@@ -939,43 +939,39 @@ export class TransposeAction extends EditorAction {
export
abstract
class
AbstractCaseAction
extends
EditorAction
{
public
run
(
_accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
{
le
t
selections
=
editor
.
getSelections
();
cons
t
selections
=
editor
.
getSelections
();
if
(
selections
===
null
)
{
return
;
}
le
t
model
=
editor
.
getModel
();
cons
t
model
=
editor
.
getModel
();
if
(
model
===
null
)
{
return
;
}
let
wordSeparators
=
editor
.
getOption
(
EditorOption
.
wordSeparators
);
let
commands
:
ICommand
[]
=
[];
const
wordSeparators
=
editor
.
getOption
(
EditorOption
.
wordSeparators
);
const
textEdits
:
IIdentifiedSingleEditOperation
[]
=
[];
for
(
let
i
=
0
,
len
=
selections
.
length
;
i
<
len
;
i
++
)
{
let
selection
=
selections
[
i
];
for
(
const
selection
of
selections
)
{
if
(
selection
.
isEmpty
())
{
le
t
cursor
=
selection
.
getStartPosition
();
cons
t
cursor
=
selection
.
getStartPosition
();
const
word
=
editor
.
getConfiguredWordAtPosition
(
cursor
);
if
(
!
word
)
{
continue
;
}
let
wordRange
=
new
Range
(
cursor
.
lineNumber
,
word
.
startColumn
,
cursor
.
lineNumber
,
word
.
endColumn
);
let
text
=
model
.
getValueInRange
(
wordRange
);
commands
.
push
(
new
ReplaceCommandThatPreservesSelection
(
wordRange
,
this
.
_modifyText
(
text
,
wordSeparators
),
new
Selection
(
cursor
.
lineNumber
,
cursor
.
column
,
cursor
.
lineNumber
,
cursor
.
column
)));
const
wordRange
=
new
Range
(
cursor
.
lineNumber
,
word
.
startColumn
,
cursor
.
lineNumber
,
word
.
endColumn
);
const
text
=
model
.
getValueInRange
(
wordRange
);
textEdits
.
push
(
EditOperation
.
replace
(
wordRange
,
this
.
_modifyText
(
text
,
wordSeparators
)));
}
else
{
le
t
text
=
model
.
getValueInRange
(
selection
);
commands
.
push
(
new
ReplaceCommandThatPreservesSelection
(
selection
,
this
.
_modifyText
(
text
,
wordSeparators
),
selection
));
cons
t
text
=
model
.
getValueInRange
(
selection
);
textEdits
.
push
(
EditOperation
.
replace
(
selection
,
this
.
_modifyText
(
text
,
wordSeparators
)
));
}
}
editor
.
pushUndoStop
();
editor
.
execute
Commands
(
this
.
id
,
command
s
);
editor
.
execute
Edits
(
this
.
id
,
textEdit
s
);
editor
.
pushUndoStop
();
}
...
...
@@ -1059,45 +1055,6 @@ export class SnakeCaseAction extends AbstractCaseAction {
});
}
public
run
(
_accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
{
const
selections
=
editor
.
getSelections
();
if
(
selections
===
null
)
{
return
;
}
const
model
=
editor
.
getModel
();
if
(
model
===
null
)
{
return
;
}
const
wordSeparators
=
editor
.
getOption
(
EditorOption
.
wordSeparators
);
const
commands
:
ICommand
[]
=
[];
for
(
const
selection
of
selections
)
{
if
(
selection
.
isEmpty
())
{
const
cursor
=
selection
.
getStartPosition
();
const
word
=
editor
.
getConfiguredWordAtPosition
(
cursor
);
if
(
!
word
)
{
continue
;
}
const
wordRange
=
new
Range
(
cursor
.
lineNumber
,
word
.
startColumn
,
cursor
.
lineNumber
,
word
.
endColumn
);
const
text
=
model
.
getValueInRange
(
wordRange
);
commands
.
push
(
new
ReplaceCommandThatModifiesSelection
(
wordRange
,
this
.
_modifyText
(
text
,
wordSeparators
),
new
Selection
(
cursor
.
lineNumber
,
cursor
.
column
,
cursor
.
lineNumber
,
cursor
.
column
),
text
));
}
else
{
const
text
=
model
.
getValueInRange
(
selection
);
commands
.
push
(
new
ReplaceCommandThatModifiesSelection
(
selection
,
this
.
_modifyText
(
text
,
wordSeparators
),
selection
,
text
));
}
}
editor
.
pushUndoStop
();
editor
.
executeCommands
(
this
.
id
,
commands
);
editor
.
pushUndoStop
();
}
protected
_modifyText
(
text
:
string
,
wordSeparators
:
string
):
string
{
return
text
.
replace
(
/
(?<
=
\p
{Ll}
)(\p
{Lu}
)
|
(?<
!
\b
|_
)(\p
{Lu}
)(?=\p
{Ll}
)
/gmu
,
'
_$&
'
).
toLocaleLowerCase
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录