mirror of
https://github.com/marktext/marktext.git
synced 2025-05-09 05:10:41 +08:00
Optimization search in folder
This commit is contained in:
parent
77b1b171c1
commit
a8bb4bd2f7
@ -60,7 +60,7 @@
|
|||||||
/*marktext*/
|
/*marktext*/
|
||||||
--sideBarColor: #9da5b4;
|
--sideBarColor: #9da5b4;
|
||||||
--sideBarIconColor: var(--iconColor);
|
--sideBarIconColor: var(--iconColor);
|
||||||
--sideBarTitleColor: #9da5b4;
|
--sideBarTitleColor: rgb(255, 255, 255);
|
||||||
--sideBarTextColor: #9da5b4;
|
--sideBarTextColor: #9da5b4;
|
||||||
--sideBarBgColor: #21252b;
|
--sideBarBgColor: #21252b;
|
||||||
--sideBarItemHoverBgColor: #3a3f4b;
|
--sideBarItemHoverBgColor: #3a3f4b;
|
||||||
|
@ -212,7 +212,7 @@ export default {
|
|||||||
width: 3px;
|
width: 3px;
|
||||||
cursor: col-resize;
|
cursor: col-resize;
|
||||||
&:hover {
|
&:hover {
|
||||||
border-right: 2px solid var(--highlightThemeColor);
|
border-right: 2px solid var(--iconColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -321,10 +321,10 @@ export default {
|
|||||||
}
|
}
|
||||||
.search-wrapper {
|
.search-wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: 35px 15px 10px 15px;
|
margin: 37px 15px 10px 15px;
|
||||||
padding: 0 6px;
|
padding: 0 6px;
|
||||||
border-radius: 15px;
|
border-radius: 14px;
|
||||||
height: 30px;
|
height: 28px;
|
||||||
border: 1px solid var(--floatBorderColor);
|
border: 1px solid var(--floatBorderColor);
|
||||||
background: var(--inputBgColor);
|
background: var(--inputBgColor);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
@click.stop="toggleSearchMatches()"
|
@click.stop="toggleSearchMatches()"
|
||||||
>
|
>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<span class="filename">{{ filename + extension }}</span>
|
<span class="filename">
|
||||||
|
<span class="name">{{ filename }}</span><span class="extension">{{extension}}</span>
|
||||||
|
</span>
|
||||||
<span class="match-count">{{ matchCount }}</span>
|
<span class="match-count">{{ matchCount }}</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="folder-path">
|
<!-- <div class="folder-path">
|
||||||
@ -31,6 +33,7 @@
|
|||||||
>
|
>
|
||||||
<ul>
|
<ul>
|
||||||
<li
|
<li
|
||||||
|
class="text-overflow"
|
||||||
v-for="(searchMatch, index) of getMatches"
|
v-for="(searchMatch, index) of getMatches"
|
||||||
:key="index"
|
:key="index"
|
||||||
:searchMatch="searchMatch"
|
:searchMatch="searchMatch"
|
||||||
@ -38,8 +41,8 @@
|
|||||||
@click="handleSearchResultClick(searchMatch)"
|
@click="handleSearchResultClick(searchMatch)"
|
||||||
>
|
>
|
||||||
<!-- <span class="line-number">{{ searchMatch.range[0][0] }}</span> -->
|
<!-- <span class="line-number">{{ searchMatch.range[0][0] }}</span> -->
|
||||||
<span>{{ searchMatch.lineText.substring(0, searchMatch.range[0][1]) }}</span>
|
<span>{{ ellipsisText(searchMatch.lineText.substring(0, searchMatch.range[0][1])) }}</span>
|
||||||
<span class="ag-highlight">{{ searchMatch.lineText.substring(searchMatch.range[0][1], searchMatch.range[1][1]) }}</span>
|
<span class="highlight">{{ searchMatch.lineText.substring(searchMatch.range[0][1], searchMatch.range[1][1]) }}</span>
|
||||||
<span>{{ searchMatch.lineText.substring(searchMatch.range[1][1]) }}</span>
|
<span>{{ searchMatch.lineText.substring(searchMatch.range[1][1]) }}</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -83,8 +86,7 @@ export default {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
getMatches () {
|
getMatches () {
|
||||||
if (this.searchResult.matches.length === 0 ||
|
if (this.searchResult.matches.length === 0 || this.allMatchesShown) {
|
||||||
this.allMatchesShown) {
|
|
||||||
return this.searchResult.matches
|
return this.searchResult.matches
|
||||||
}
|
}
|
||||||
return this.searchResult.matches.slice(0, this.shownMatches)
|
return this.searchResult.matches.slice(0, this.shownMatches)
|
||||||
@ -113,12 +115,19 @@ export default {
|
|||||||
toggleSearchMatches () {
|
toggleSearchMatches () {
|
||||||
this.showSearchMatches = !this.showSearchMatches
|
this.showSearchMatches = !this.showSearchMatches
|
||||||
},
|
},
|
||||||
|
|
||||||
handleShowMoreMatches (event) {
|
handleShowMoreMatches (event) {
|
||||||
this.shownMatches += 15
|
this.shownMatches += 15
|
||||||
if (event.ctrlKey || event.metaKey ||
|
if (event.ctrlKey || event.metaKey ||
|
||||||
this.shownMatches >= this.searchResult.matches.length) {
|
this.shownMatches >= this.searchResult.matches.length) {
|
||||||
this.allMatchesShown = true
|
this.allMatchesShown = true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
ellipsisText (text) {
|
||||||
|
const len = text.length
|
||||||
|
const MAX_PRETEXT_LEN = 6
|
||||||
|
return len > MAX_PRETEXT_LEN ? `...${text.substring(len - MAX_PRETEXT_LEN)}` : text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,16 +166,19 @@ export default {
|
|||||||
display: block;
|
display: block;
|
||||||
padding: 2px 16px;
|
padding: 2px 16px;
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow: hidden;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
/* Hide space between inline spans */
|
/* Hide space between inline spans */
|
||||||
font-size: 0;
|
font-size: 0;
|
||||||
|
& .highlight {
|
||||||
|
background: var(--highlightColor);
|
||||||
|
line-height: 16px;
|
||||||
|
height: 16px;
|
||||||
|
display: inline-block;
|
||||||
|
color: var(--sideBarTitleColor);
|
||||||
|
border-radius: 1px;
|
||||||
|
}
|
||||||
&:hover {
|
&:hover {
|
||||||
background: var(--sideBarItemHoverBgColor);
|
background: var(--sideBarItemHoverBgColor);
|
||||||
},
|
|
||||||
& span:first-child {
|
|
||||||
margin-right: 3px;
|
|
||||||
}
|
}
|
||||||
& span {
|
& span {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
@ -195,6 +207,10 @@ export default {
|
|||||||
color: var(--sideBarTitleColor);
|
color: var(--sideBarTitleColor);
|
||||||
& .filename {
|
& .filename {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
& .extension {
|
||||||
|
color: var(--sideBarTextColor);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
& .match-count {
|
& .match-count {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@ -206,12 +222,14 @@ export default {
|
|||||||
border-radius: 9px;
|
border-radius: 9px;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
background: var(--itemBgColor);
|
background: var(--itemBgColor);
|
||||||
color: var(--sideBarTextColor);
|
color: var(--sideBarTitleColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.folder-path {
|
.folder-path {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.folder-path > span,
|
.folder-path > span,
|
||||||
.matches {
|
.matches {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@ -59,7 +59,7 @@ function processUnicodeMatch (match) {
|
|||||||
function convertPosition (position) {
|
function convertPosition (position) {
|
||||||
const currentBuffer = remainingBuffer.slice(0, position - previousPosition)
|
const currentBuffer = remainingBuffer.slice(0, position - previousPosition)
|
||||||
currentLength = currentBuffer.toString().length + currentLength
|
currentLength = currentBuffer.toString().length + currentLength
|
||||||
remainingBuffer = remainingBuffer.slice(position)
|
remainingBuffer = remainingBuffer.slice(position - previousPosition)
|
||||||
|
|
||||||
previousPosition = position
|
previousPosition = position
|
||||||
|
|
||||||
@ -270,7 +270,6 @@ class RipgrepDirectorySearcher {
|
|||||||
buffer = lines.pop()
|
buffer = lines.pop()
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
const message = JSON.parse(line)
|
const message = JSON.parse(line)
|
||||||
|
|
||||||
if (message.type === 'begin') {
|
if (message.type === 'begin') {
|
||||||
pendingEvent = {
|
pendingEvent = {
|
||||||
filePath: getText(message.data.path),
|
filePath: getText(message.data.path),
|
||||||
@ -281,9 +280,7 @@ class RipgrepDirectorySearcher {
|
|||||||
} else if (message.type === 'match') {
|
} else if (message.type === 'match') {
|
||||||
const trailingContextLines = []
|
const trailingContextLines = []
|
||||||
pendingTrailingContexts.add(trailingContextLines)
|
pendingTrailingContexts.add(trailingContextLines)
|
||||||
|
|
||||||
processUnicodeMatch(message.data)
|
processUnicodeMatch(message.data)
|
||||||
|
|
||||||
for (const submatch of message.data.submatches) {
|
for (const submatch of message.data.submatches) {
|
||||||
const { lineText, range } = processSubmatch(
|
const { lineText, range } = processSubmatch(
|
||||||
submatch,
|
submatch,
|
||||||
|
Loading…
Reference in New Issue
Block a user