Skip to content

Commit a8bb4bd

Browse files
author
罗冉
committed
Optimization search in folder
1 parent 77b1b17 commit a8bb4bd

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

src/renderer/assets/themes/one-dark.theme.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
/*marktext*/
6161
--sideBarColor: #9da5b4;
6262
--sideBarIconColor: var(--iconColor);
63-
--sideBarTitleColor: #9da5b4;
63+
--sideBarTitleColor: rgb(255, 255, 255);
6464
--sideBarTextColor: #9da5b4;
6565
--sideBarBgColor: #21252b;
6666
--sideBarItemHoverBgColor: #3a3f4b;

src/renderer/components/sideBar/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export default {
212212
width: 3px;
213213
cursor: col-resize;
214214
&:hover {
215-
border-right: 2px solid var(--highlightThemeColor);
215+
border-right: 2px solid var(--iconColor);
216216
}
217217
}
218218
</style>

src/renderer/components/sideBar/search.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ export default {
321321
}
322322
.search-wrapper {
323323
display: flex;
324-
margin: 35px 15px 10px 15px;
324+
margin: 37px 15px 10px 15px;
325325
padding: 0 6px;
326-
border-radius: 15px;
327-
height: 30px;
326+
border-radius: 14px;
327+
height: 28px;
328328
border: 1px solid var(--floatBorderColor);
329329
background: var(--inputBgColor);
330330
box-sizing: border-box;

src/renderer/components/sideBar/searchResultItem.vue

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
@click.stop="toggleSearchMatches()"
1818
>
1919
<div class="title">
20-
<span class="filename">{{ filename + extension }}</span>
20+
<span class="filename">
21+
<span class="name">{{ filename }}</span><span class="extension">{{extension}}</span>
22+
</span>
2123
<span class="match-count">{{ matchCount }}</span>
2224
</div>
2325
<!-- <div class="folder-path">
@@ -31,15 +33,16 @@
3133
>
3234
<ul>
3335
<li
36+
class="text-overflow"
3437
v-for="(searchMatch, index) of getMatches"
3538
:key="index"
3639
:searchMatch="searchMatch"
3740
:title="searchMatch.lineText"
3841
@click="handleSearchResultClick(searchMatch)"
3942
>
4043
<!-- <span class="line-number">{{ searchMatch.range[0][0] }}</span> -->
41-
<span>{{ searchMatch.lineText.substring(0, searchMatch.range[0][1]) }}</span>
42-
<span class="ag-highlight">{{ searchMatch.lineText.substring(searchMatch.range[0][1], searchMatch.range[1][1]) }}</span>
44+
<span>{{ ellipsisText(searchMatch.lineText.substring(0, searchMatch.range[0][1])) }}</span>
45+
<span class="highlight">{{ searchMatch.lineText.substring(searchMatch.range[0][1], searchMatch.range[1][1]) }}</span>
4346
<span>{{ searchMatch.lineText.substring(searchMatch.range[1][1]) }}</span>
4447
</li>
4548
</ul>
@@ -83,8 +86,7 @@ export default {
8386
}),
8487
8588
getMatches () {
86-
if (this.searchResult.matches.length === 0 ||
87-
this.allMatchesShown) {
89+
if (this.searchResult.matches.length === 0 || this.allMatchesShown) {
8890
return this.searchResult.matches
8991
}
9092
return this.searchResult.matches.slice(0, this.shownMatches)
@@ -113,12 +115,19 @@ export default {
113115
toggleSearchMatches () {
114116
this.showSearchMatches = !this.showSearchMatches
115117
},
118+
116119
handleShowMoreMatches (event) {
117120
this.shownMatches += 15
118121
if (event.ctrlKey || event.metaKey ||
119122
this.shownMatches >= this.searchResult.matches.length) {
120123
this.allMatchesShown = true
121124
}
125+
},
126+
127+
ellipsisText (text) {
128+
const len = text.length
129+
const MAX_PRETEXT_LEN = 6
130+
return len > MAX_PRETEXT_LEN ? `...${text.substring(len - MAX_PRETEXT_LEN)}` : text
122131
}
123132
}
124133
}
@@ -157,16 +166,19 @@ export default {
157166
display: block;
158167
padding: 2px 16px;
159168
padding-right: 0;
160-
text-overflow: ellipsis;
161-
overflow: hidden;
162169
cursor: pointer;
163170
/* Hide space between inline spans */
164171
font-size: 0;
172+
& .highlight {
173+
background: var(--highlightColor);
174+
line-height: 16px;
175+
height: 16px;
176+
display: inline-block;
177+
color: var(--sideBarTitleColor);
178+
border-radius: 1px;
179+
}
165180
&:hover {
166181
background: var(--sideBarItemHoverBgColor);
167-
},
168-
& span:first-child {
169-
margin-right: 3px;
170182
}
171183
& span {
172184
font-size: 13px;
@@ -195,6 +207,10 @@ export default {
195207
color: var(--sideBarTitleColor);
196208
& .filename {
197209
flex: 1;
210+
& .extension {
211+
color: var(--sideBarTextColor);
212+
font-size: 12px;
213+
}
198214
}
199215
& .match-count {
200216
display: inline-block;
@@ -206,12 +222,14 @@ export default {
206222
border-radius: 9px;
207223
flex-shrink: 0;
208224
background: var(--itemBgColor);
209-
color: var(--sideBarTextColor);
225+
color: var(--sideBarTitleColor);
210226
}
211227
}
228+
212229
.folder-path {
213230
font-size: 12px;
214231
}
232+
215233
.folder-path > span,
216234
.matches {
217235
width: 100%;

src/renderer/node/ripgrepSearcher.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function processUnicodeMatch (match) {
5959
function convertPosition (position) {
6060
const currentBuffer = remainingBuffer.slice(0, position - previousPosition)
6161
currentLength = currentBuffer.toString().length + currentLength
62-
remainingBuffer = remainingBuffer.slice(position)
62+
remainingBuffer = remainingBuffer.slice(position - previousPosition)
6363

6464
previousPosition = position
6565

@@ -270,7 +270,6 @@ class RipgrepDirectorySearcher {
270270
buffer = lines.pop()
271271
for (const line of lines) {
272272
const message = JSON.parse(line)
273-
274273
if (message.type === 'begin') {
275274
pendingEvent = {
276275
filePath: getText(message.data.path),
@@ -281,9 +280,7 @@ class RipgrepDirectorySearcher {
281280
} else if (message.type === 'match') {
282281
const trailingContextLines = []
283282
pendingTrailingContexts.add(trailingContextLines)
284-
285283
processUnicodeMatch(message.data)
286-
287284
for (const submatch of message.data.submatches) {
288285
const { lineText, range } = processSubmatch(
289286
submatch,

0 commit comments

Comments
 (0)