Skip to content

Commit 4d25ba5

Browse files
author
chunqiuyiyu
committed
Modify search style and add hotkey of searching
1 parent 1b1fea6 commit 4d25ba5

File tree

9 files changed

+101
-45
lines changed

9 files changed

+101
-45
lines changed

app/commands/commandBindings/misc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as Panel from 'components/Panel/actions'
33
import * as SideBar from 'components/Panel/SideBar/actions'
44
import terminalState from 'components/Terminal/state'
55
import * as Terminal from 'components/Terminal/actions'
6+
import * as searchState from 'commons/Search/state'
67

78
const getComponentByName = name => window.refs[name].getWrappedInstance()
89
export default {
@@ -23,6 +24,9 @@ export default {
2324
'global:show_env': () => {
2425
SideBar.toggleSidePanelView('SIDEBAR.RIGHT.env')
2526
},
27+
'global:show_search': () => {
28+
SideBar.toggleSidePanelView('SIDEBAR.LEFT.find')
29+
},
2630
'modal:dismiss': (c) => {
2731
Modal.dismissModal()
2832
},

app/commands/keymaps.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ const keymapStore = observable({
9393
mac: 'cmd+f11',
9494
win: 'ctrl+f11',
9595
label: i18n`settings.keymap.into_zenmode`
96+
},
97+
{
98+
command: 'global:show_search',
99+
mac: 'cmd+shift+f',
100+
win: 'ctrl+shift+f',
101+
label: i18n`settings.keymap.search`
96102
}
97103
],
98104
pluginsKeymaps: [],

app/commons/Search/state.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { observable } from 'mobx'
1+
import { observable, map } from 'mobx'
22

33
export const ws = observable({
44
name: '',
55
status: false,
66
first: true
77
})
88

9-
export const searching = observable({
9+
export const searching = map({
1010
pattern: '',
1111
path: '',
1212
caseSensitive: false,
1313
word: false,
1414
isPattern: false,
15-
singleFork: false
15+
singleFork: false,
1616
})
1717

1818
export const searched = observable({

app/components/Search/search.new.jsx

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class SearchResultItem extends Component {
5656
let {start, end, length, innerStart, innerEnd, line, lineNum} = result;
5757
return (
5858
<div key={`${fileName}-${resultSize}-${lineNum}-${start}`} className='search-item-line' onClick={() => this.handleItemClick(path, innerStart, innerEnd, lineNum)}>
59-
<span className='search-item-content'>{line.substring(0, innerStart)}<b>{line.substring(innerStart, innerEnd)}</b>{line.substring(innerEnd)}</span>
59+
{line && <span className='search-item-content'>{line.substring(0, innerStart)}<b>{line.substring(innerStart, innerEnd)}</b>{line.substring(innerEnd)}</span>}
6060
</div>
6161
)})
6262
}
@@ -103,14 +103,18 @@ class SearchPanel extends Component {
103103
if (state.ws.first) {
104104
content = ''
105105
} else if (!state.searched.end) {
106-
content = 'Searching...'
106+
content = i18n`panel.left.searching`
107107
} else if(state.searched.message !== '') {
108108
content = state.searched.message;
109109
} else if (state.searched.results.length != 0) {
110110
const pattern = state.searching.pattern;
111-
let count = 0;
111+
const files = state.searched.results.length
112+
let number = 0
113+
let count = 0
114+
112115
content = state.searched.results.map((searchChunk) => {
113116
count++
117+
number += searchChunk.results.length
114118
return (<SearchResultItem
115119
key={`${pattern}-${count}`}
116120
fileName={searchChunk.fileName}
@@ -121,6 +125,7 @@ class SearchPanel extends Component {
121125
})
122126
return (
123127
<div className='search-result-list'>
128+
<div>{i18n`panel.result.tip${{ files, number }}`}</div>
124129
{content}
125130
</div>
126131
)
@@ -136,6 +141,11 @@ class SearchPanel extends Component {
136141
}
137142

138143
render () {
144+
const searching = state.searching
145+
const caseSensitive = searching.get('caseSensitive')
146+
const word = searching.get('word')
147+
const isPattern = searching.get('isPattern')
148+
139149
return (
140150
<div className='search-panel'>
141151
<div className='search-panel-title'>
@@ -148,46 +158,44 @@ class SearchPanel extends Component {
148158
value={state.keyword}
149159
onChange={this.handleKeywordChange}
150160
onKeyDown={this.onKeyDown}
151-
placeholder={i18n.get('panel.left.find')}
161+
placeholder={i18n.get(`panel.left.placeholder`)}
152162
/>
153163
</div>
154-
{/* <div className='search-checkbox'>
155-
<input
156-
title={i18n.get('panel.checkbox.case')}
157-
label={i18n.get('panel.checkbox.case')}
158-
className='search-control-case-sensitive'
159-
onChange={this.caseSensitive}
160-
type='checkbox'/>
161-
<input title={i18n.get('panel.checkbox.word')}
162-
label={i18n.get('panel.checkbox.word')}
163-
className='search-control-word'
164-
onChange={this.word}
165-
type='checkbox'
166-
disabled={state.searching.isPattern}/>
167-
<input title={i18n.get('panel.checkbox.pattern')}
168-
label={i18n.get('panel.checkbox.pattern')}
169-
className='search-control-pattern'
170-
onChange={this.pattern}
171-
type='checkbox'/>
172-
</div> */}
164+
<div className='search-checkbox'>
165+
<span title={i18n.get('panel.checkbox.case')}
166+
onClick={() => this.caseSensitive(caseSensitive)}
167+
className={caseSensitive ? 'active' : ''}>{'Aa'}</span>
168+
<span title={i18n.get('panel.checkbox.word')}
169+
onClick={() => this.word(word)}
170+
className={word ? 'active' : ''}>{'Al'}</span>
171+
<span title={i18n.get('panel.checkbox.pattern')}
172+
onClick={() => this.pattern(isPattern)}
173+
className={isPattern ? 'active' : ''}>{'.*'}</span>
174+
</div>
173175
</div>
174176
{this.renderResult()}
175177
</div>
176178
)
177179
}
178180

179-
caseSensitive = e => {
180-
state.searching.caseSensitive = e.target.checked;
181+
caseSensitive = caseSensitive => {
182+
state.searching.set('caseSensitive', !caseSensitive)
181183
}
182184

183-
word = e => {
184-
state.searching.word = e.target.checked;
185+
word = word => {
186+
state.searching.set('word', !word)
187+
if (!word) {
188+
state.searching.set('isPattern', false)
189+
}
185190
}
186191

187-
pattern = e => {
188-
state.searching.isPattern = e.target.checked;
192+
pattern = isPattern => {
193+
state.searching.set('isPattern', !isPattern)
194+
if (!isPattern) {
195+
state.searching.set('word', false)
196+
}
189197
}
190198

191199
}
192200

193-
export default SearchPanel;
201+
export default SearchPanel

app/i18n/en_US/panel.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"left": {
88
"project": "Project",
99
"working": "Working",
10-
"find": "Find"
10+
"find": "Search",
11+
"placeholder": "Enter keyword",
12+
"searching": "Searching..."
1113
},
1214
"right": {
1315
"plugin": "Plugin Development"
@@ -18,6 +20,7 @@
1820
"pattern": "Pattern Match"
1921
},
2022
"result": {
21-
"blank": "Search Result Is 0"
23+
"blank": "Search Result is 0",
24+
"tip": "Searched for {number} results, included in {files} files"
2225
}
2326
}

app/i18n/en_US/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"exit_zenmode": "Exit Zen Mode",
4545
"sysKeymap": "System Keybindings",
4646
"pluginKeymap": "Plugins Keybindings",
47-
"pluginSource": "Keybindings Source"
47+
"pluginSource": "Keybindings Source",
48+
"search": "Search All Files"
4849
},
4950
"appearance": {
5051
"main": "Appearance Setting",

app/i18n/zh_CN/panel.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"left": {
88
"project": "文件树",
99
"working": "工作文件",
10-
"find": "搜索"
10+
"find": "搜索",
11+
"placeholder": "输入关键词",
12+
"searching": "搜索中..."
1113
},
1214
"right": {
1315
"plugin": "插件开发"
@@ -18,6 +20,7 @@
1820
"pattern": "正则匹配"
1921
},
2022
"result": {
21-
"blank": "查询结果为 0 条"
23+
"blank": "查询结果为 0 条",
24+
"tip": "搜索到 {number} 个结果,包含于 {files} 个文件中"
2225
}
2326
}

app/i18n/zh_CN/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"exit_zenmode": "退出禅模式",
4444
"sysKeymap": "系统快捷键",
4545
"pluginKeymap": "插件快捷键",
46-
"pluginSource": "来源插件"
46+
"pluginSource": "来源插件",
47+
"search": "全文搜索"
4748
},
4849
"appearance": {
4950
"main": "样式",

app/styles/core-ui/Search.styl

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,42 @@
77
margin-bottom: 14px;
88
}
99
.search-panel-input {
10-
margin-bottom: 14px;
11-
background-color: #1e1e1e
12-
border: 1px solid #333
10+
margin-bottom: 10px;
1311
// display: flex
1412
.search-controls {
1513
border: none
1614
}
1715
.search-checkbox {
1816
margin-right: inherit;
19-
position inherit;
17+
position: inherit;
18+
top: 43px;
19+
display: inline-block;
20+
position: absolute;
21+
right: 15px;
22+
23+
.active {
24+
color: #337ab7;
25+
font-weight: bold;
26+
}
27+
28+
span {
29+
width: 22px;
30+
height: 22px;
31+
padding: 3px;
32+
display: inline-block;
33+
cursor: default;
34+
35+
36+
&:hover {
37+
color: #337ab7;
38+
font-weight: bold;
39+
}
40+
}
2041
}
2142
}
2243
.search-item {
2344
cursor: pointer;
45+
margin-top: 10px;
2446
white-space: nowrap;
2547
.search-item-path {
2648
line-height: 20px;
@@ -37,7 +59,8 @@
3759
width: 18px;
3860
text-align: center;
3961
display: inline-block;
40-
transform: translateY(1px)
62+
transform: translateY(1px);
63+
margin-right: 4px;
4164
}
4265
.search-item-path-path {
4366
opacity: .6;
@@ -57,14 +80,21 @@
5780
}
5881
}
5982
.search-item-line {
60-
padding-left: 12px;
83+
padding-left: 20px;
6184
line-height: 20px;
85+
margin-top: 10px;
6286
text-overflow: ellipsis;
6387
overflow: hidden;
6488
h {
6589
// font-weight: 700;
6690
background: #d2691e78;
6791
}
92+
93+
b {
94+
background: #337ab7;
95+
color: #fff;
96+
font-weight: normal;
97+
}
6898
}
6999
}
70100
}

0 commit comments

Comments
 (0)