Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
158f8592
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,发现更多精彩内容 >>
提交
158f8592
编写于
8月 14, 2019
作者:
S
skprabhanjan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added preserveCase in search side bar
上级
12792640
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
85 addition
and
7 deletion
+85
-7
src/vs/workbench/contrib/search/browser/media/searchview.css
src/vs/workbench/contrib/search/browser/media/searchview.css
+14
-0
src/vs/workbench/contrib/search/browser/searchView.ts
src/vs/workbench/contrib/search/browser/searchView.ts
+11
-1
src/vs/workbench/contrib/search/browser/searchWidget.ts
src/vs/workbench/contrib/search/browser/searchWidget.ts
+28
-1
src/vs/workbench/contrib/search/common/searchModel.ts
src/vs/workbench/contrib/search/common/searchModel.ts
+12
-3
src/vs/workbench/services/search/common/replace.ts
src/vs/workbench/services/search/common/replace.ts
+20
-2
未找到文件。
src/vs/workbench/contrib/search/browser/media/searchview.css
浏览文件 @
158f8592
...
...
@@ -60,6 +60,20 @@
display
:
inline-flex
;
}
.search-view
.search-widget
.replace-input
{
position
:
relative
;
display
:
flex
;
display
:
-webkit-flex
;
vertical-align
:
middle
;
width
:
auto
!important
;
}
.search-view
.search-widget
.replace-input
>
.controls
{
position
:
absolute
;
top
:
3px
;
right
:
2px
;
}
.search-view
.search-widget
.replace-container.disabled
{
display
:
none
;
}
...
...
src/vs/workbench/contrib/search/browser/searchView.ts
浏览文件 @
158f8592
...
...
@@ -364,6 +364,7 @@ export class SearchView extends ViewletPanel {
const
searchHistory
=
history
.
search
||
this
.
viewletState
[
'
query.searchHistory
'
]
||
[];
const
replaceHistory
=
history
.
replace
||
this
.
viewletState
[
'
query.replaceHistory
'
]
||
[];
const
showReplace
=
typeof
this
.
viewletState
[
'
view.showReplace
'
]
===
'
boolean
'
?
this
.
viewletState
[
'
view.showReplace
'
]
:
true
;
const
preserveCase
=
this
.
viewletState
[
'
query.preserveCase
'
]
===
true
;
this
.
searchWidget
=
this
.
_register
(
this
.
instantiationService
.
createInstance
(
SearchWidget
,
container
,
<
ISearchWidgetOptions
>
{
value
:
contentPattern
,
...
...
@@ -372,7 +373,8 @@ export class SearchView extends ViewletPanel {
isCaseSensitive
:
isCaseSensitive
,
isWholeWords
:
isWholeWords
,
searchHistory
:
searchHistory
,
replaceHistory
:
replaceHistory
replaceHistory
:
replaceHistory
,
preserveCase
:
preserveCase
}));
if
(
showReplace
)
{
...
...
@@ -390,6 +392,12 @@ export class SearchView extends ViewletPanel {
this
.
viewModel
.
replaceActive
=
state
;
this
.
refreshTree
();
}));
this
.
_register
(
this
.
searchWidget
.
onPreserveCaseChange
((
state
)
=>
{
this
.
viewModel
.
preserveCase
=
state
;
this
.
refreshTree
();
}));
this
.
_register
(
this
.
searchWidget
.
onReplaceValueChanged
((
value
)
=>
{
this
.
viewModel
.
replaceString
=
this
.
searchWidget
.
getReplaceValue
();
this
.
delayedRefresh
.
trigger
(()
=>
this
.
refreshTree
());
...
...
@@ -1641,6 +1649,7 @@ export class SearchView extends ViewletPanel {
const
patternExcludes
=
this
.
inputPatternExcludes
.
getValue
().
trim
();
const
patternIncludes
=
this
.
inputPatternIncludes
.
getValue
().
trim
();
const
useExcludesAndIgnoreFiles
=
this
.
inputPatternExcludes
.
useExcludesAndIgnoreFiles
();
const
preserveCase
=
this
.
viewModel
.
preserveCase
;
this
.
viewletState
[
'
query.contentPattern
'
]
=
contentPattern
;
this
.
viewletState
[
'
query.regex
'
]
=
isRegex
;
...
...
@@ -1649,6 +1658,7 @@ export class SearchView extends ViewletPanel {
this
.
viewletState
[
'
query.folderExclusions
'
]
=
patternExcludes
;
this
.
viewletState
[
'
query.folderIncludes
'
]
=
patternIncludes
;
this
.
viewletState
[
'
query.useExcludesAndIgnoreFiles
'
]
=
useExcludesAndIgnoreFiles
;
this
.
viewletState
[
'
query.preserveCase
'
]
=
preserveCase
;
const
isReplaceShown
=
this
.
searchAndReplaceWidget
.
isReplaceShown
();
this
.
viewletState
[
'
view.showReplace
'
]
=
isReplaceShown
;
...
...
src/vs/workbench/contrib/search/browser/searchWidget.ts
浏览文件 @
158f8592
...
...
@@ -33,6 +33,7 @@ import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import
{
IViewletService
}
from
'
vs/workbench/services/viewlet/browser/viewlet
'
;
import
{
IEditorOptions
}
from
'
vs/editor/common/config/editorOptions
'
;
import
{
IAccessibilityService
,
AccessibilitySupport
}
from
'
vs/platform/accessibility/common/accessibility
'
;
import
{
Checkbox
}
from
'
vs/base/browser/ui/checkbox/checkbox
'
;
export
interface
ISearchWidgetOptions
{
value
?:
string
;
...
...
@@ -42,6 +43,7 @@ export interface ISearchWidgetOptions {
isWholeWords
?:
boolean
;
searchHistory
?:
string
[];
replaceHistory
?:
string
[];
preserveCase
?:
boolean
;
}
class
ReplaceAllAction
extends
Action
{
...
...
@@ -97,6 +99,7 @@ export class SearchWidget extends Widget {
replaceInputFocusTracker
:
dom
.
IFocusTracker
;
private
replaceInputBoxFocused
:
IContextKey
<
boolean
>
;
private
_replaceHistoryDelayer
:
Delayer
<
void
>
;
private
_preserveCase
:
Checkbox
;
private
ignoreGlobalFindBufferOnNextFocus
=
false
;
private
previousGlobalFindBufferValue
:
string
;
...
...
@@ -113,6 +116,9 @@ export class SearchWidget extends Widget {
private
_onReplaceStateChange
=
this
.
_register
(
new
Emitter
<
boolean
>
());
readonly
onReplaceStateChange
:
Event
<
boolean
>
=
this
.
_onReplaceStateChange
.
event
;
private
_onPreserveCaseChange
=
this
.
_register
(
new
Emitter
<
boolean
>
());
readonly
onPreserveCaseChange
:
Event
<
boolean
>
=
this
.
_onPreserveCaseChange
.
event
;
private
_onReplaceValueChanged
=
this
.
_register
(
new
Emitter
<
void
>
());
readonly
onReplaceValueChanged
:
Event
<
void
>
=
this
.
_onReplaceValueChanged
.
event
;
...
...
@@ -333,13 +339,34 @@ export class SearchWidget extends Widget {
private
renderReplaceInput
(
parent
:
HTMLElement
,
options
:
ISearchWidgetOptions
):
void
{
this
.
replaceContainer
=
dom
.
append
(
parent
,
dom
.
$
(
'
.replace-container.disabled
'
));
const
replaceBox
=
dom
.
append
(
this
.
replaceContainer
,
dom
.
$
(
'
.input-box
'
));
const
replaceBox
=
dom
.
append
(
this
.
replaceContainer
,
dom
.
$
(
'
.replace-input
'
));
this
.
replaceInput
=
this
.
_register
(
new
ContextScopedHistoryInputBox
(
replaceBox
,
this
.
contextViewService
,
{
ariaLabel
:
nls
.
localize
(
'
label.Replace
'
,
'
Replace: Type replace term and press Enter to preview or Escape to cancel
'
),
placeholder
:
nls
.
localize
(
'
search.replace.placeHolder
'
,
"
Replace
"
),
history
:
options
.
replaceHistory
||
[],
flexibleHeight
:
true
},
this
.
contextKeyService
));
this
.
_preserveCase
=
this
.
_register
(
new
Checkbox
({
actionClassName
:
'
monaco-preserve-case
'
,
title
:
nls
.
localize
(
'
label.preserveCaseCheckbox
'
,
"
Preserve Case
"
),
isChecked
:
!!
options
.
preserveCase
,
}));
this
.
_register
(
this
.
_preserveCase
.
onChange
(
viaKeyboard
=>
{
if
(
!
viaKeyboard
)
{
this
.
replaceInput
.
focus
();
this
.
_onPreserveCaseChange
.
fire
(
this
.
_preserveCase
.
checked
);
}
}));
let
controls
=
document
.
createElement
(
'
div
'
);
controls
.
className
=
'
controls
'
;
controls
.
style
.
display
=
'
block
'
;
controls
.
appendChild
(
this
.
_preserveCase
.
domNode
);
replaceBox
.
appendChild
(
controls
);
this
.
_register
(
attachInputBoxStyler
(
this
.
replaceInput
,
this
.
themeService
));
this
.
onkeydown
(
this
.
replaceInput
.
inputElement
,
(
keyboardEvent
)
=>
this
.
onReplaceInputKeyDown
(
keyboardEvent
));
this
.
replaceInput
.
value
=
options
.
replaceValue
||
''
;
...
...
src/vs/workbench/contrib/search/common/searchModel.ts
浏览文件 @
158f8592
...
...
@@ -103,17 +103,17 @@ export class Match {
}
const
fullMatchText
=
this
.
fullMatchText
();
let
replaceString
=
searchModel
.
replacePattern
.
getReplaceString
(
fullMatchText
);
let
replaceString
=
searchModel
.
replacePattern
.
getReplaceString
(
fullMatchText
,
searchModel
.
preserveCase
);
// If match string is not matching then regex pattern has a lookahead expression
if
(
replaceString
===
null
)
{
const
fullMatchTextWithTrailingContent
=
this
.
fullMatchText
(
true
);
replaceString
=
searchModel
.
replacePattern
.
getReplaceString
(
fullMatchTextWithTrailingContent
);
replaceString
=
searchModel
.
replacePattern
.
getReplaceString
(
fullMatchTextWithTrailingContent
,
searchModel
.
preserveCase
);
// Search/find normalize line endings - check whether \r prevents regex from matching
if
(
replaceString
===
null
)
{
const
fullMatchTextWithoutCR
=
fullMatchTextWithTrailingContent
.
replace
(
/
\r\n
/g
,
'
\n
'
);
replaceString
=
searchModel
.
replacePattern
.
getReplaceString
(
fullMatchTextWithoutCR
);
replaceString
=
searchModel
.
replacePattern
.
getReplaceString
(
fullMatchTextWithoutCR
,
searchModel
.
preserveCase
);
}
}
...
...
@@ -895,6 +895,7 @@ export class SearchModel extends Disposable {
private
_replaceActive
:
boolean
=
false
;
private
_replaceString
:
string
|
null
=
null
;
private
_replacePattern
:
ReplacePattern
|
null
=
null
;
private
_preserveCase
:
boolean
=
false
;
private
readonly
_onReplaceTermChanged
:
Emitter
<
void
>
=
this
.
_register
(
new
Emitter
<
void
>
());
readonly
onReplaceTermChanged
:
Event
<
void
>
=
this
.
_onReplaceTermChanged
.
event
;
...
...
@@ -926,6 +927,14 @@ export class SearchModel extends Disposable {
return
this
.
_replaceString
||
''
;
}
set
preserveCase
(
value
:
boolean
)
{
this
.
_preserveCase
=
value
;
}
get
preserveCase
():
boolean
{
return
this
.
_preserveCase
;
}
set
replaceString
(
replaceString
:
string
)
{
this
.
_replaceString
=
replaceString
;
if
(
this
.
_searchQuery
)
{
...
...
src/vs/workbench/services/search/common/replace.ts
浏览文件 @
158f8592
...
...
@@ -54,7 +54,7 @@ export class ReplacePattern {
* Returns the replace string for the first match in the given text.
* If text has no matches then returns null.
*/
getReplaceString
(
text
:
string
):
string
|
null
{
getReplaceString
(
text
:
string
,
preserveCase
?:
boolean
):
string
|
null
{
this
.
_regExp
.
lastIndex
=
0
;
let
match
=
this
.
_regExp
.
exec
(
text
);
if
(
match
)
{
...
...
@@ -65,12 +65,30 @@ export class ReplacePattern {
let
replaceString
=
text
.
replace
(
this
.
_regExp
,
this
.
pattern
);
return
replaceString
.
substr
(
match
.
index
,
match
[
0
].
length
-
(
text
.
length
-
replaceString
.
length
));
}
return
this
.
pattern
;
return
this
.
buildReplaceString
(
match
,
preserveCase
)
;
}
return
null
;
}
public
buildReplaceString
(
matches
:
string
[]
|
null
,
preserveCase
?:
boolean
):
string
{
if
(
preserveCase
&&
matches
&&
(
matches
[
0
]
!==
''
))
{
if
(
matches
[
0
].
toUpperCase
()
===
matches
[
0
])
{
return
this
.
_replacePattern
.
toUpperCase
();
}
else
if
(
matches
[
0
].
toLowerCase
()
===
matches
[
0
])
{
return
this
.
_replacePattern
.
toLowerCase
();
}
else
if
(
strings
.
containsUppercaseCharacter
(
matches
[
0
][
0
]))
{
return
this
.
_replacePattern
[
0
].
toUpperCase
()
+
this
.
_replacePattern
.
substr
(
1
);
}
else
{
// we don't understand its pattern yet.
return
this
.
_replacePattern
;
}
}
else
{
return
this
.
_replacePattern
;
}
}
/**
* \n => LF
* \t => TAB
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录