mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-06 19:26:55 +08:00
fix(search): search perf and fix css issues
This commit is contained in:
parent
3d3748a86e
commit
571a464f7e
6 changed files with 26 additions and 5 deletions
|
@ -193,9 +193,13 @@ class MessageList extends React.Component
|
||||||
"messages-wrap": true
|
"messages-wrap": true
|
||||||
"ready": not @state.loading
|
"ready": not @state.loading
|
||||||
|
|
||||||
|
messageListClass = classNames
|
||||||
|
"message-list": true
|
||||||
|
"height-fix": SearchableComponentStore.searchTerm isnt null
|
||||||
|
|
||||||
<KeyCommandsRegion globalHandlers={@_globalKeymapHandlers()}>
|
<KeyCommandsRegion globalHandlers={@_globalKeymapHandlers()}>
|
||||||
<FindInThread ref="findInThread" />
|
<FindInThread ref="findInThread" />
|
||||||
<div className="message-list" id="message-list">
|
<div className={messageListClass} id="message-list">
|
||||||
<ScrollRegion tabIndex="-1"
|
<ScrollRegion tabIndex="-1"
|
||||||
className={wrapClass}
|
className={wrapClass}
|
||||||
scrollbarTickProvider={SearchableComponentStore}
|
scrollbarTickProvider={SearchableComponentStore}
|
||||||
|
|
|
@ -7,16 +7,17 @@ body.platform-win32 {
|
||||||
|
|
||||||
.find-in-thread {
|
.find-in-thread {
|
||||||
background: @background-secondary;
|
background: @background-secondary;
|
||||||
border-bottom: 1px solid @border-secondary-bg;
|
|
||||||
text-align: right;
|
text-align: right;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
height: 0;
|
height: 0;
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
transition: all 125ms ease-in-out;
|
transition: all 125ms ease-in-out;
|
||||||
|
border-bottom: 0;
|
||||||
&.enabled {
|
&.enabled {
|
||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
height: 35px;
|
height: 35px;
|
||||||
|
border-bottom: 1px solid @border-secondary-bg;
|
||||||
}
|
}
|
||||||
|
|
||||||
.controls-wrap {
|
.controls-wrap {
|
||||||
|
|
|
@ -112,12 +112,18 @@ body.platform-win32 {
|
||||||
img { background: @text-color-subtle; }
|
img { background: @text-color-subtle; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#message-list.height-fix {
|
||||||
|
height: calc(~"100% - 35px");
|
||||||
|
min-height: calc(~"100% - 35px");
|
||||||
|
}
|
||||||
|
|
||||||
#message-list {
|
#message-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
position: relative;
|
position: relative;
|
||||||
background: @background-secondary;
|
background: @background-secondary;
|
||||||
|
|
||||||
|
transition: all 125ms ease-in-out;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
|
|
|
@ -2,6 +2,7 @@ import _ from 'underscore'
|
||||||
import DOMUtils from '../../dom-utils'
|
import DOMUtils from '../../dom-utils'
|
||||||
import NylasStore from 'nylas-store'
|
import NylasStore from 'nylas-store'
|
||||||
import Actions from '../actions'
|
import Actions from '../actions'
|
||||||
|
import {MAX_MATCHES, CHAR_THRESHOLD} from '../../searchable-components/search-constants'
|
||||||
|
|
||||||
class SearchableComponentStore extends NylasStore {
|
class SearchableComponentStore extends NylasStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -74,8 +75,11 @@ class SearchableComponentStore extends NylasStore {
|
||||||
// root document.
|
// root document.
|
||||||
const searchNodes = []
|
const searchNodes = []
|
||||||
|
|
||||||
if (this.searchTerm && this.searchTerm.length > 0) {
|
if (this.searchTerm && this.searchTerm.length >= CHAR_THRESHOLD) {
|
||||||
_.each(this.searchRegions, (node) => {
|
_.each(this.searchRegions, (node) => {
|
||||||
|
if (this.matches.length >= MAX_MATCHES) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let refNode;
|
let refNode;
|
||||||
let topOffset = 0;
|
let topOffset = 0;
|
||||||
let leftOffset = 0;
|
let leftOffset = 0;
|
||||||
|
@ -104,6 +108,9 @@ class SearchableComponentStore extends NylasStore {
|
||||||
left: rect.left + leftOffset,
|
left: rect.left + leftOffset,
|
||||||
height: rect.height,
|
height: rect.height,
|
||||||
});
|
});
|
||||||
|
if (this.matches.length >= MAX_MATCHES) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.matches.sort((nodeA, nodeB) => {
|
this.matches.sort((nodeA, nodeB) => {
|
||||||
|
|
2
src/searchable-components/search-constants.es6
Normal file
2
src/searchable-components/search-constants.es6
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export const MAX_MATCHES = 999;
|
||||||
|
export const CHAR_THRESHOLD = 2;
|
|
@ -1,4 +1,5 @@
|
||||||
import {Utils} from 'nylas-exports'
|
import {Utils} from 'nylas-exports'
|
||||||
|
import {MAX_MATCHES, CHAR_THRESHOLD} from './search-constants'
|
||||||
|
|
||||||
export default class UnifiedDOMParser {
|
export default class UnifiedDOMParser {
|
||||||
constructor(regionId) {
|
constructor(regionId) {
|
||||||
|
@ -7,7 +8,7 @@ export default class UnifiedDOMParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
matchesSearch(dom, searchTerm) {
|
matchesSearch(dom, searchTerm) {
|
||||||
if ((searchTerm || "").trim().length === 0) { return false; }
|
if ((searchTerm || "").trim().length < CHAR_THRESHOLD) { return false; }
|
||||||
const fullStrings = this.buildNormalizedText(dom)
|
const fullStrings = this.buildNormalizedText(dom)
|
||||||
// For each match, we return an array of new elements.
|
// For each match, we return an array of new elements.
|
||||||
for (const fullString of fullStrings) {
|
for (const fullString of fullStrings) {
|
||||||
|
@ -59,7 +60,7 @@ export default class UnifiedDOMParser {
|
||||||
const matches = []
|
const matches = []
|
||||||
let matchCount = 0;
|
let matchCount = 0;
|
||||||
let match = re.exec(rawString);
|
let match = re.exec(rawString);
|
||||||
while (match && matchCount < 1000) {
|
while (match && matchCount <= MAX_MATCHES) {
|
||||||
const matchStart = match.index;
|
const matchStart = match.index;
|
||||||
const matchEnd = match.index + match[0].length;
|
const matchEnd = match.index + match[0].length;
|
||||||
matches.push([matchStart, matchEnd])
|
matches.push([matchStart, matchEnd])
|
||||||
|
|
Loading…
Add table
Reference in a new issue